CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002
    Posts
    72

    Get current Line

    I'm trying to read both binary and text information from a text file. The following code shows what I am doing but I need to be able to keep moving through the text. When I open for Input a second time I am reset to the first line of the text file. What can I throw in there to keep it moving along properly through each line of the text file without repeating lines? Also, I'm not sure if I am getting the proper line when I open for binary read. What can I put after "Get #1," to ensure I am getting the proper line?

    Open SelectedFile For Input As #1
    Do Until EOF(1)
    If gettingPicture = True Then
    Close #1
    Dim mynewStrLine() As Byte
    Open SelectedFile For Binary Access Read As #1
    ReDim mynewStrLine(LOF(1))
    Get #1, , mynewStrLine
    gettingPicture = False
    Close #1
    Set picInsert(i) = LoadPicture(App.Path & "\myTempPic.txt")
    Open SelectedFile For Input As #1

    '(get onto proper line. How??)

    Else
    Line Input #1, strLine
    GetField
    If InStr(strLine, "End of Report:") > 0 Then
    'this was the last line
    Exit Do
    End If
    End If
    Loop

  2. #2
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    Re: Get current Line

    check out "Loc" and "Seek" in the help. perhaps you could do a loc before the first read, then when you reach your "getpicture" clause, close the file, re-open in binary, use seek to get to the previous loc, do your thing, record the new loc, close file, open for input, etc...

    also, you could probably get away with not closing and re-opening the file all the time - just open it using two handles - #1, and #2.
    Last edited by Zeb; October 7th, 2004 at 12:16 AM. Reason: change "although" to "also" in final paragraph

  3. #3
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Get current Line

    If I were doing this, I might store the length of the image data just before it, and once you read that line, you will know how much data to read. Another way might be to use a UDT, which could load various sorts of data all at once.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

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

Featured