Results 1 to 7 of 7

Thread: It seems i'm stuck here somewhat (fileaccess)

  1. #1

    Thread Starter
    Addicted Member Icheb's Avatar
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    232

    It seems i'm stuck here somewhat (fileaccess)

    I need to read the last line of a .dat file (txt based).
    But only the last line, it must be in a sub.
    I currently have this :

    code:

    Do
    starten:
    Open plaats For Input As #1
    Input #1, klantnummer, Text, foto, video

    If klantnummer = "Leeg" Then GoTo starten
    If klantnummer = "leeg" Then GoTo starten


    Do
    Open "c:\erdatmp.dat" For Input As #2
    Input #2, klantnrtemp
    Close #2
    Loop Until EOF(2)

    Loop Until Not klantnrtemp = klantnummer
    Close #1

    Open "c:\erdatmp.dat" For Append As #2
    Write #2, klantnummer
    Close #2
    -------
    My intention :

    It's all about a datafile downloaded from the internet, but the file is variable.
    So that is the problem, i can't include it in the program.
    If its downloaded, it must open the first 'record' (in on other perfectly working rountine at the time).
    But when the user hits an other command button it needs to load the data of the second line and change the variables so the user sees the second line in the program.

    And, no, i haven't used access database files because 0 or 1 things are url's where or a small movie or a picture needs to be downloaded.

    So what i tried now :
    From every read there is from the datafile, the first varaiable will be saved in another file, and the next time the user hits the command button it reads both files and should continue at the right position, but that doesn't happen.
    What happens is the first thing (other sub routine in the prog) works good, and the second line (first time this routine) works good too, but the third time he gives exactly the same data of the first.

    So, if anyone can help me with this routine, i really suck at these routines...
    I've been trying different approaches for over 3 months now... and the friend i'm writing it for really wants it... (he's been bugging me for 4 weeks about when its done)
    So please help.

    thanks in advance,
    Sebastian

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845


    Is this what you want to do:

    Read the last line of plaats
    check that klantnummer isn't already listed in "c:\erdatmp.dat"
    and then add klantnummer to the end of the file.
    Mark
    -------------------

  3. #3

    Thread Starter
    Addicted Member Icheb's Avatar
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    232
    Originally posted by Mark Sreeves


    Is this what you want to do:

    Read the last line of plaats
    check that klantnummer isn't already listed in "c:\erdatmp.dat"
    and then add klantnummer to the end of the file.
    about right, but instead of only copying plaats it needs to copy the entire record.
    but for the rest you are right
    The main VB routine in Windows XP (The don't admit it, they wrote it in VB)

    [vbcode]
    Public Sub Windows_Load()
    a = 1
    b = 2
    if not a + b = 2 then
    goto crash
    end if

    goto crash

    End Sub
    [/vbcode]

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Have a play with this then:


    Code:
    Private Sub Command2_Click()
    Dim klantnummer As String
    Dim Text As String
    Dim foto As String
    Dim video As String
    Dim klantnrtemp As String
    Dim fNum As Byte
    Dim fNum2 As Byte
    
    
    fNum = FreeFile
    Open plaats For Input As fNum
    
    fNum2 = FreeFile
    Open "c:\erdatmp.dat" For Input As fNum2
    
    Do While Not EOF(fNum)
      Input #fNum, klantnummer, Text, foto, video
      
        If UCase(klantnummer) <> "LEEG" Then
          Line Input #fNum2, klantnrtemp
          If klantnrtemp <> klantnummer Then
            Exit Do
          End If
        End If
    Loop
    
    Close fNum
    Close fNum2
    
    fNum = FreeFile
    Open "c:\erdatmp.dat" For Append As fNum
      Write #fNum, klantnummer
    Close fNum
    
    End Sub
    Mark
    -------------------

  5. #5

    Thread Starter
    Addicted Member Icheb's Avatar
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    232
    Finally a approach that works.
    needed to change one line though.
    I'll give you the outcome and the new code :

    Code:
    fNum = FreeFile
    Open plaats For Input As fNum
    
    fNum2 = FreeFile
    Open "c:\erdatmp.dat" For Input As fNum2
    
    Do While Not EOF(fNum)
      Input #fNum, klantnummer, Text, foto, video
      
        If UCase(klantnummer) <> "LEEG" Then
          Input #fNum2, klantnrtemp
          If klantnrtemp <> klantnummer Then
            Exit Do
          End If
        End If
    Loop
    
    Close fNum
    Close fNum2
    
    fNum = FreeFile
    Open "c:\erdatmp.dat" For Append As fNum
      Write #fNum, klantnummer
    Close fNum
    I don't think you can see it fast.
    I changed one Line Input to Input to compensate for the ""

    Furthermore, i'll give you the output of it.

    after 3 klantnummer's the erdatmp.dat file looks like :
    Code:
    "39"
    "38"
    "40"
    the databasefile (plaats) works good, only 1 little thing, if klantnummer = "LEEG" everything quits... (it continues then, but it starts produceing some strange answers)
    but your approach is much faster, and it accually works, then what i tried to do !!


    now only that LEEG... (leeg = empty in dutch, its a dutch program... it's the new value of klantnummer when the record is deleted because i dont know how to whipe it completely out...
    (i'm quite bad at VB, i think)
    The main VB routine in Windows XP (The don't admit it, they wrote it in VB)

    [vbcode]
    Public Sub Windows_Load()
    a = 1
    b = 2
    if not a + b = 2 then
    goto crash
    end if

    goto crash

    End Sub
    [/vbcode]

  6. #6
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I don't think there is an easy way to wipe out just one line from a plain text file

    this will remove them for you though....

    Code:
    Private Sub Command2_Click()
    
    Dim strTemp As String
    Dim fNum As Byte
    Dim fNum2 As Byte
    
    
    fNum = FreeFile
    Open plaats For Input As fNum
    
    fNum2 = FreeFile
    Open plaats & ".temp" For Output As fNum2
    
    Do While Not EOF(fNum)
      Line Input #fNum, strTemp
      
        If UCase(Left(klantnummer, 4)) <> "LEEG" Then
          Print #fNum2, strTemp
        End If
    Loop
    
    Close fNum
    Close fNum2
    
    FileCopy plaats & ".temp", plaats
    Kill plaats & ".temp"
    
    End Sub
    Mark
    -------------------

  7. #7

    Thread Starter
    Addicted Member Icheb's Avatar
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    232
    ok,
    i'll try it, when i have it i'll post the result here...

    tnx,

    Sebastian
    The main VB routine in Windows XP (The don't admit it, they wrote it in VB)

    [vbcode]
    Public Sub Windows_Load()
    a = 1
    b = 2
    if not a + b = 2 then
    goto crash
    end if

    goto crash

    End Sub
    [/vbcode]

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