|
-
Apr 26th, 2006, 04:50 PM
#1
Thread Starter
Member
Input from textfile
Hey every1
I was wondering when using the input statement to read a line from file, is there a way for it to input a whole line and not just upto the first comma?
thanks in advance
-
Apr 26th, 2006, 05:00 PM
#2
-
Apr 26th, 2006, 05:25 PM
#3
Thread Starter
Member
Re: Input from textfile
darn tht reads the whole file lol.
Code:
31-Mar-06,6015.20,6019.20,5961.40,5964.60,1650124544,5964.60
30-Mar-06,5959.20,6036.00,5959.20,6015.20,1496758016,6015.20
29-Mar-06,5935.70,5979.70,5927.20,5959.20,1742429440,5959.20
thats the file format,
i need the last value on each line. My plan was to take the last 7 chars from each line.
Anyone got a sure fire way of getting that last value for each line?
thanks
-
Apr 26th, 2006, 05:37 PM
#4
Re: Input from textfile
If the Line Input statement reads in the whole file, then there may not be any line breaks in it. Are there always the same number of characters on e "line"? If so, you could use the Input(xxx,#1) wheren the xxx is the number of characters per line and the #1 is the file channel #.
-
Apr 26th, 2006, 05:41 PM
#5
Thread Starter
Member
Re: Input from textfile
no, due to the dates in the first column each line length varies slightly in size.
I think there is always the same amount of columns so i guess i cud use Input 7 times, where the 7th time has what i need :s
Seems abit flaky tho
-
Apr 26th, 2006, 05:51 PM
#6
Re: Input from textfile
what separates the columns? A space?
read the whole file at once, then split it on the delimiter to give you an array with the lines:
VB Code:
Dim sText As String, sLine() As String
Open "C:\text.txt" For Input As #1
sText = Input(LOF(1), #1)
Close #1
sLine = Split(sText, " ")
For N = LBound(sLine) To UBound(sLine)
Debug.Print sLine(N)
Next N
-
Apr 26th, 2006, 07:30 PM
#7
Addicted Member
Re: Input from textfile
 Originally Posted by Mythrandil
darn tht reads the whole file lol.
Code:
31-Mar-06,6015.20,6019.20,5961.40,5964.60,1650124544,5964.60
30-Mar-06,5959.20,6036.00,5959.20,6015.20,1496758016,6015.20
29-Mar-06,5935.70,5979.70,5927.20,5959.20,1742429440,5959.20
thats the file format,
i need the last value on each line. My plan was to take the last 7 chars from each line.
Anyone got a sure fire way of getting that last value for each line?
thanks
You can use the mid function to detemine the last 7 charecters from each line even if the size of the line is random.
VB Code:
Private Sub Form_Load()
Open "C:\test.txt" For Input As #1
While Not EOF(1)
Line Input #1, i
If Len(Text1.Text) = 0 Then
Text1.Text = Mid(i, Len(i) - 6, Len(i))
Else
Text1.Text = Text1.Text & vbNewLine & Mid(i, Len(i) - 6, Len(i))
End If
Wend
Close #1
End Sub
Add a textbox with multiline and it will add input the last 7 charecters with on each line.
Are we alive or just breathing?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|