Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: brew on June 26, 2007, 09:07 PM

Title: Uh.... WTF
Post by: brew on June 26, 2007, 09:07 PM
So i'm working on my bot and all of a sudden a function that worked absolutely FINE a few minutes ago is screwing up:
Quote
Public Function ScanUsers(User As String, strArray() As String) As Long
    Dim i As Long
    For i = 0 To UBound(strArray)
        If User = Left$(strArray(i), InStr(strArray(i), " ") - 1) Then
            ScanUsers = i
            AddChat vbWhite, "yay"
            GoTo Done
        End If
    Next i
    ScanUsers = -1
Done:
MsgBox "im here"
End Function
Uh... it enters the if statement, then addchats, but the value of i isn't set to ScanUsers. Then it goes to Done, messageboxes Im here, then (i set a breakpoint on Scanusers = -1) executes ScanUsers = -1, then goes back to Im Done. .....god help me.....
Title: Re: Uh.... WTF
Post by: l2k-Shadow on June 26, 2007, 09:13 PM
Quote from: brew on June 26, 2007, 09:07 PM
So i'm working on my bot and all of a sudden a function that worked absolutely FINE a few minutes ago is screwing up:
Quote
Public Function ScanUsers(User As String, strArray() As String) As Long
    Dim i As Long
    For i = 0 To UBound(strArray)
        If User = Left$(strArray(i), InStr(strArray(i), " ") - 1) Then
            ScanUsers = i
            AddChat vbWhite, "yay"
            GoTo Done
        End If
    Next i
    ScanUsers = -1
Done:
MsgBox "im here"
End Function
Uh... it enters the if statement, then addchats, but the value of i isn't set to ScanUsers. Then it goes to Done, messageboxes Im here, then (i set a breakpoint on Scanusers = -1) executes ScanUsers = -1, then goes back to Im Done. .....god help me.....

Try to avoid using GoTo at any cost possible.


Public Function ScanUsers(User As String, strArray() As String) As Long
    Dim i As Long
    ScanUsers = -1
    For i = 0 To UBound(strArray)
        If User = Left$(strArray(i), InStr(strArray(i), " ") - 1) Then
            ScanUsers = i
            AddChat vbWhite, "yay"
            Exit For
        End If
    Next i
End Function
Title: Re: Uh.... WTF
Post by: brew on June 26, 2007, 09:17 PM
I originally just had Exit function where i had goto, but i changed to demonstrate how (il) logical the vb6 compiler was. Executing a line, then going back up one, executing that one, then going back to the bottom one is perfectly logical. right? /me sighs
Title: Re: Uh.... WTF
Post by: l2k-Shadow on June 26, 2007, 09:52 PM
well it's simply a bug in the compilation of the asm, places a bad jmp or doesn't place one.. either way i just tested it with the latest service pack for vs6 and it worked ok, make sure you are using it.
Title: Re: Uh.... WTF
Post by: MyndFyre on June 26, 2007, 11:43 PM
Quote from: brew on June 26, 2007, 09:17 PM
I originally just had Exit function where i had goto, but i changed to demonstrate how (il) logical the vb6 compiler was. Executing a line, then going back up one, executing that one, then going back to the bottom one is perfectly logical. right? /me sighs
Incidentally this may be due to the fact that modern processors are able to execute instrutions so fast that they can actually execute some instructions in parallel.  It doesn't matter if ScanUsers is set to -1 when the message box that says "im here" is displayed, and so they can be executed out of order.  This is done as an optimization sometimes.  Maybe you should examine disassembly of this function.