• Welcome to Valhalla Legends Archive.
 

Next without For

Started by Forged, September 09, 2005, 02:07 PM

Previous topic - Next topic

Forged

I keep getting the error next without for when this code runs and I have no clue why.  I do have a for loop


Private Sub CSB_ServerInfo(ByVal Message As String, SimulatedEvent As Boolean)

If LCase(Message) = LCase("Your friends are:") Then
'
End If
For i = 1 To 25 Step 1
If Left((LCase(Message)), 3) = (LCase(i & ": ")) Then
    ParseFriends Message
Next i
Else
AddC vbYellow, Message
End If

End Sub
QuoteI wish my grass was Goth so it would cut itself

dxoigmn


Private Sub CSB_ServerInfo(ByVal Message As String, SimulatedEvent As Boolean)

  If LCase(Message) = LCase("Your friends are:") Then
    '
  End If

  For i = 1 To 25 Step 1
    If Left((LCase(Message)), 3) = (LCase(i & ": ")) Then
      ParseFriends Message
      Next i
    Else
      AddC vbYellow, Message
    End If

End Sub


Tabbing reveals the problem...

Forged

except that will add the server info 25 times and I don't want to do that.
QuoteI wish my grass was Goth so it would cut itself

shout

Quote from: Forged on September 09, 2005, 02:30 PM
except that will add the server info 25 times and I don't want to do that.

If you did not notice is the exact same code except it has tabbing.

Blaze

Quote from: Forged on September 09, 2005, 02:30 PM
except that will add the server info 25 times and I don't want to do that.
Think then...

Private Sub CSB_ServerInfo(ByVal Message As String, SimulatedEvent As Boolean)

If LCase(Message) = LCase("Your friends are:") Then
'
End If

If Left((LCase(Message)), 3) = (LCase(i & ": ")) Then
    For i = 1 To 25 Step 1
        ParseFriends Message
    Next i
Else
AddC vbYellow, Message
End If

End Sub
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

Forged

For i = 1 to 25 needs to be above the if statement because I am using the value of i in the if statement.
QuoteI wish my grass was Goth so it would cut itself

Blaze

Hmm, how about we do this the easy way then..


Private Sub CSB_ServerInfo(ByVal Message As String, SimulatedEvent As Boolean)

     If LCase(Message) = LCase("Your friends are:") Then
          '
     End If

     For i = 1 To 25 Step 1
          If Left((LCase(Message)), 3) = (LCase(i & ": ")) Then
               ParseFriends Message
          Else
               AddC vbYellow, Message
               Exit For
          End If
     Next i
End Sub

Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

dxoigmn

Quote from: Forged on September 09, 2005, 03:17 PM
For i = 1 to 25 needs to be above the if statement because I am using the value of i in the if statement.

I'm guessing you want to do something like this:


Private Sub CSB_ServerInfo(ByVal Message As String, SimulatedEvent As Boolean)

  If LCase(Message) = LCase("Your friends are:") Then ' Why not lower-case the string yourself? *Lazy*
    '
  End If

  If Left(Message, 3) Like "#: " Then
    ParseFriends Message
  Else
    AddC vbYellow, Message
  End If

End Sub


Edit: This might only work for 1 digit. Making it work for 2 digits is trivial.

Forged

Thank you sir, that is exactlly what I needed.   I had never heard of the Like operator before, kind of nifty.
QuoteI wish my grass was Goth so it would cut itself

Joe[x86]

In my bot, just print server info to the screen, and update my friends list using 0x.. whatever the packet was. That way if they use /f l it will display correctly.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Eric

Quote from: Forged on September 09, 2005, 02:07 PM
I keep getting the error next without for when this code runs and I have no clue why.  I do have a for loop


Private Sub CSB_ServerInfo(ByVal Message As String, SimulatedEvent As Boolean)

If LCase(Message) = LCase("Your friends are:") Then
'
End If
For i = 1 To 25 Step 1
If Left((LCase(Message)), 3) = (LCase(i & ": ")) Then
    ParseFriends Message
Next i
Else
AddC vbYellow, Message
End If

End Sub


You're missing an End If.


Private Sub CSB_ServerInfo(ByVal Message As String, SimulatedEvent As Boolean)

If LCase(Message) = LCase("Your friends are:") Then
'
End If
For i = 1 To 25 Step 1
If Left((LCase(Message)), 3) = (LCase(i & ": ")) Then
    ParseFriends Message
End If
Next i
Else
AddC vbYellow, Message
End If

End Sub

Joe[x86]

If LCase(Message) = LCase("Your friends are:") Then
'
End If


I'd comment out the If and End If lines as well (for efficency) or just plain remove them, seeing as how its a compare to do even though it doesn't effect anything.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.