Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
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  
Old June 12th, 2004, 12:43 AM
michelle_ho michelle_ho is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 6 michelle_ho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old June 12th, 2004, 10:47 AM
michelle_ho michelle_ho is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 6 michelle_ho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I know what's the problem la.... I keep increaseing the column even this is not a number.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > How to separate words in a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway