• Welcome to Valhalla Legends Archive.
 

Reload file after edit...

Started by R.a.B.B.i.T, October 31, 2004, 03:10 PM

Previous topic - Next topic

R.a.B.B.i.T

This is for a bot I am making, but is not really bot related at all.

Okay, so basically I got this idea from iago, who said that the database is reloaded after any changes by checking the edit times.  Okay.  Well, I decided to go the easy way in VB and just check to see if the size is the same.  My problem is that even if the size is different, nothing happens!  I can't figure this out, and I've been trying for a while now.

This is what I get:
124     'check size
124     'initial size
<file edited here>
185     'size after edit
124     'inital size
database updated 'changed, so the database is reloaded

My problem is that it doesn't work.  It will return true and SAY the database was reloaded, but it doesn't reload, and it isn't cleared either.  Code below..

'Called at run-time to set the database check
Public Sub SetLastEdit()
    Dim dbHandle As Long
    Dim lnData As Long
    Dim OF As OFSTRUCT
On Error GoTo SetLastEdit_Error

    dbHandle = OpenFile(App.Path & "\database.txt", OF, &H0)
    LastEdit = GetFileSize(dbHandle, lnData)

On Error GoTo 0
Exit Sub

SetLastEdit_Error:
    AddC ERRORMSG, " -- Error " & Err.Number & vbNewLine & _
    " (" & Err.Description & ") " & vbNewLine & _
    "in procedure SetLastEdit of modDatabase"
End Sub



'called whenever someone speaks or whispers the bot
Public Function GetLastEdit() As Boolean
    Dim dbHandle As Long
    Dim lnData As Long
    Dim check As Currency
    Dim OF As OFSTRUCT
On Error GoTo GetLastEdit_Error

    dbHandle = OpenFile(App.Path & "\database.txt", OF, &H0)
    check = GetFileSize(dbHandle, lnData)
    Debug.Print check
    Debug.Print LastEdit
    If check <> LastEdit Then
        LastEdit = check
        ReDim UserList(0)
        LoadDatabase
        DoEvents
        GetLastEdit = True
        Exit Function
    End If
    GetLastEdit = False

On Error GoTo 0
Exit Function

GetLastEdit_Error:
    AddC ERRORMSG, " -- Error " & Err.Number & vbNewLine & _
    " (" & Err.Description & ") " & vbNewLine & _
    "in procedure GetLastEdit of modDatabase"
End Function


Adron

You mean that lastedit doesn't change? I suggest you breakpoint on the line that updates lastedit and make sure you get there. If lastedit changes, perhaps there's a problem in your LoadDatabase function?

R.a.B.B.i.T

LastEdit changes (because it has a different value upon the next check), and LoadDatabase() works just fine because I call it on startup and after userlist changes, and it works just fine.  If you want to take a look at it I will post it.

Adron

I might want to take a look at it eventually. I'd like to see if you can solve it yourself first though, given the best debugging suggestions this forum can come up with.

How about a breakpoint on LoadDatabase, and stepping through it to see that it actually does what it's supposed to? Maybe you have an "on error" handler in it that catches an error and skips the whole thing?

UserLoser.

Shouldn't you be closing the file?  See: CloseHandle()

R.a.B.B.i.T

Hah.....I completely forgot about that.  Bad me.  Thanks UL, that solved it.
I was thinking that it might be reloading the database before the command parser was called, and thus I didn't have access yet, but it was a simple CloseFile() call I forgot.  Thank you, again.