|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
How to separate words in a string
I am writing a program, to read a txt file, and display it in a spreadsheet.
The txt files contains these lines, and they are numbers: 0 400 9.42 0.00 4.4 2.20 0.61 420 54 790 8.84 2.38 9.3 1.69 1.06 880 144 1930 1.06 10.6 17.7 0.34 2.17 2220 I want to put each of the number in one cell. I have written the following code: Dim fileExits Dim i fileExits = Dir("data.dat") If fileExits <> "" Then Dim Filename As String Dim rowNumber As Integer rowNumber = 1 Filename = "data.dat" Dim strSplit Dim MyLine As Variant Open Filename For Input As #1 While Not EOF(1) Line Input #1, MyLine strSplit = Split(MyLine, " ") For i = 0 To UBound(strSplit) Spreadsheet3.ActiveSheet.Cells(rowNumber, 1 + i).Value = strSplit(i) Next rowNumber = rowNumber + 1 Wend Close #1End If However, it doesn't display what i want. The output now become: (I use "|" represent a cell) | | | 0| | 400|9.42| 0| | 4.4| 2.2| 0.61| |420| | | 54| | 790|8.84|2.38| | 9.3|1.69|1.06| |880| |186|1800|0.04| 17| 19|0.02|2.78 |2200| I want it display like: | 0| 400|9.42| 0| 4.4| 2.2| 0.61| 420| | 54| 790|8.84|2.38| 9.3|1.69|1.06| 880| |186|1800|0.04| 17| 19|0.02|2.78 |2200| I have try to add the following constraint. But no use. If strSplit(I) <> " " Then Spreadsheet3.ActiveSheet.Cells(rowNumber, 1 + i).Value = strSplit(i) end if What happend to my code? please help me! |
|
#2
|
|||
|
|||
|
I know what's the problem la.... I keep increaseing the column even this is not a number.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > How to separate words in a string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
![]() |
|