Results 1 to 6 of 6

Thread: newbie need help with files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    64

    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.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    64
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    64
    does anyone have any ideas? im at a dead end.

    regards

    Dan
    Newie so thanks for your patience.

  4. #4
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    Is something like this what you are looking for?

    To delete original file:

    VB Code:
    1. Kill filenameforplayers


    To rename temporary file:

    VB Code:
    1. Name filenameforplayers2 As filenameforplayers

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    64
    @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.

  6. #6
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    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
  •  



Click Here to Expand Forum to Full Width