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
Printable View
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
Line Input #1, sLine
darn tht reads the whole file lol.
thats the file format,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
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
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 #.
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
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
You can use the mid function to detemine the last 7 charecters from each line even if the size of the line is random.Quote:
Originally Posted by Mythrandil
Add a textbox with multiline and it will add input the last 7 charecters with on each line.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