Results 1 to 7 of 7

Thread: Input from textfile

  1. #1

    Thread Starter
    Member Mythrandil's Avatar
    Join Date
    Mar 2006
    Posts
    55

    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

  2. #2

  3. #3

    Thread Starter
    Member Mythrandil's Avatar
    Join Date
    Mar 2006
    Posts
    55

    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

  4. #4
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526

    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 #.

  5. #5

    Thread Starter
    Member Mythrandil's Avatar
    Join Date
    Mar 2006
    Posts
    55

    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

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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:
    1. Dim sText As String, sLine() As String
    2. Open "C:\text.txt" For Input As #1
    3.     sText = Input(LOF(1), #1)
    4. Close #1
    5. sLine = Split(sText, " ")
    6.  
    7. For N = LBound(sLine) To UBound(sLine)
    8.     Debug.Print sLine(N)
    9. Next N

  7. #7
    Addicted Member Piller's Avatar
    Join Date
    Oct 2004
    Location
    california
    Posts
    177

    Re: Input from textfile

    Quote 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:
    1. Private Sub Form_Load()
    2. Open "C:\test.txt" For Input As #1
    3.     While Not EOF(1)
    4.         Line Input #1, i
    5.         If Len(Text1.Text) = 0 Then
    6.             Text1.Text = Mid(i, Len(i) - 6, Len(i))
    7.         Else
    8.             Text1.Text = Text1.Text & vbNewLine & Mid(i, Len(i) - 6, Len(i))
    9.         End If
    10.     Wend
    11. Close #1
    12. 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
  •  



Click Here to Expand Forum to Full Width