|
-
Jul 30th, 2001, 05:36 AM
#1
Thread Starter
Addicted Member
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
-
Jul 30th, 2001, 06:26 AM
#2
-
Jul 30th, 2001, 06:38 AM
#3
Thread Starter
Addicted Member
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]
-
Jul 30th, 2001, 06:47 AM
#4
Frenzied Member
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
-
Jul 30th, 2001, 07:10 AM
#5
Thread Starter
Addicted Member
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 :
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]
-
Jul 30th, 2001, 07:39 AM
#6
Frenzied Member
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
-
Jul 30th, 2001, 07:54 AM
#7
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|