Valhalla Legends Forums Archive | Visual Basic Programming | Uh.... WTF

AuthorMessageTime
BreW
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
[/quote]
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.....
June 27, 2007, 2:07 AM
l2k-Shadow
[quote author=brew link=topic=16825.msg170486#msg170486 date=1182910059]
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
[/quote]
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.....
[/quote]

Try to avoid using GoTo at any cost possible.

[code]
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
[/code]
June 27, 2007, 2:13 AM
BreW
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
June 27, 2007, 2:17 AM
l2k-Shadow
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.
June 27, 2007, 2:52 AM
Myndfyr
[quote author=brew link=topic=16825.msg170488#msg170488 date=1182910643]
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
[/quote]
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.
June 27, 2007, 4:43 AM

Search