|
-
Feb 16th, 2002, 07:30 AM
#1
Thread Starter
Lively Member
newbie need help with files
hi all
I have a small random acces file, that is used to add information about different people, age name, etc
what i need to do is accomadate for deletion of players. I have read that this is a soloution:
copy all records except the one to delete to a new file, delete the old file and rename the new one to the same as the old one.
can someone help with the code to do this. many thanks
kind regards
Dan
Newie so thanks for your patience.
-
Feb 16th, 2002, 08:45 AM
#2
Thread Starter
Lively Member
ok this is what i guessin it would be something like
Private Sub cmdDeletePlayer_Click()
Dim onerecord
Dim copyrecord
Open FileNameForPlayers For Random As #1 Len = Len(onerecord)
While Not EOF(1)
Get #1, , onerecord
'if this record <> the deleted one then
Open FileNameForPlayers2 For Random As #2 Len = Len(onerecord)
Put #2, , copyrecord
Close #2
Loop
Close #1
'somehow delete FileNameForPlayers *******
'somehow rename FileNameForPlayers2 to what FileNameForPlayers was. ******
End Sub
i dont know how to do ************bits
pls help
Newie so thanks for your patience.
-
Feb 16th, 2002, 12:41 PM
#3
Thread Starter
Lively Member
does anyone have any ideas? im at a dead end.
regards
Dan
Newie so thanks for your patience.
-
Feb 16th, 2002, 01:38 PM
#4
Frenzied Member
Is something like this what you are looking for?
To delete original file:
To rename temporary file:
VB Code:
Name filenameforplayers2 As filenameforplayers
-
Feb 16th, 2002, 02:38 PM
#5
Thread Starter
Lively Member
@john
you star thats exactly what i needed. This code now works, is this common practice
Private Sub cmdDeletePlayer_Click()
Dim onerecord As PlayerType
Dim filenameforplayers2 As String
Dim numberofrecords2 As Integer
filenameforplayers2 = "C:\My Documents\playerdetails2.dat"
Open FileNameForPlayers For Random As #1 Len = Len(onerecord)
Do While Not EOF(1)
Get #1, , onerecord
'if this record <> the deleted one then
Open filenameforplayers2 For Random As #2 Len = Len(onerecord)
Put #2, numberofrecords2 + 1, onerecord
Close #2
numberofrecords2 = numberofrecords2 + 1
Loop
Close #1
Kill FileNameForPlayers 'somehow delete FileNameForPlayers
Name filenameforplayers2 As FileNameForPlayers '
End Sub
Thanks again, it would be much appreciated if this style is ok
regards
Dan
Newie so thanks for your patience.
-
Feb 16th, 2002, 02:53 PM
#6
Frenzied Member
Looks fine. Glad to be of help.
By the way, the tags for formatting your code in vb-style are vbcode and /vbcode in square brackets
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
|