|
-
Jan 23rd, 2007, 04:07 PM
#1
Thread Starter
Member
[RESOLVED] If statement not catching - Different
VB Code:
If InStr(comFinder, "!roll") = 1 Then
If Len(comFinder) = 7 Or 8 Then
numFinder = InStr(comFinder, " ")
'Error here.
fstNum = Right(comFinder, Len(comFinder) - numFinder)
sendToIRC (sendMsgText & " PRIVMSG #shadowfall :" & charName & " rolled " & CStr(fstNum) & " dice: " & diceRoller(fstNum, 0))
ElseIf Len(comFinder) = 9 Or 10 Or 11 Then
numFinder = InStr(comFinder, " ")
numFinder2 = InStr(numFinder + 1, comFinder, " ")
fstNum = Mid(comFinder, numFinder + 1, numFinder2 - 1)
sndNum = Mid(comFinder, numFinder2 + 1, Len(comFinder) - (numFinder2 + 1))
sendToIRC (sendMsgText & " PRIVMSG #shadowfall :" & charName & " rolled " & CStr(fstNum) & " dice: " & diceRoller(fstNum, sndNum))
End If
End If
If it is sent "!roll 3" or "!roll 12" it works perfectly.
If it is sent "!roll 3 2", "!roll 10 2", or "!roll 10 10" it fails. It catches on the marked line of code. It shouldn't even be touching that code at this point. It shouldn't be meeting the requirements and should therefore be skipping over that lil' section to the "ElseIf".
What's going on?
Thank you all in advance for your time.
Last edited by CyberInfantry; Jan 23rd, 2007 at 04:57 PM.
Reason: No longer resolved
-
Jan 23rd, 2007, 04:26 PM
#2
Re: If statement not catching
 Originally Posted by CyberInfantry
VB Code:
If Len(comFinder) = 7 Or 8 Then
Change this to:
VB Code:
If Len(comFinder) = 7 Or Len(comFinder) = 8 Then
-
Jan 23rd, 2007, 04:44 PM
#3
Thread Starter
Member
Re: If statement not catching
Ah, perfect! I feel so dumb some times. :P
-
Jan 23rd, 2007, 04:58 PM
#4
Thread Starter
Member
Re: If statement not catching - Different
I changed it to a Select Case.
VB Code:
Select Case Len(comFinder)
Case 7, 8
numFinder = InStr(comFinder, " ")
fstNum = Right(comFinder, Len(comFinder) - numFinder)
sendToIRC (sendMsgText & " PRIVMSG #shadowfall :" & charName & " rolled " & CStr(fstNum) & " dice:" & diceRoller(fstNum, 0))
Case 9, 10, 11
numFinder = InStr(comFinder, " ")
numFinder2 = InStr(numFinder + 1, comFinder, " ")
'Error here
fstNum = Mid(comFinder, numFinder + 1, (numFinder2 - numFinder))
sndNum = Mid(comFinder, numFinder2 + 1, Len(comFinder) - (numFinder2 + 1))
sendToIRC (sendMsgText & " PRIVMSG #shadowfall :" & charName & " rolled " & CStr(fstNum) & " dice:" & diceRoller(fstNum, sndNum))
End Select
Now it is catch at the new marked spot. -sigh-
-
Jan 23rd, 2007, 05:21 PM
#5
Re: If statement not catching - Different
OK, I took a closer look, and I think I know what you are trying to do. Here is a different approach, using the Split function:
VB Code:
Dim Substrings() As String
' ...
Substrings = Split(comFinder) ' Default splits on space character and returns all strings
If Substrings(0) = "!roll" Then
If UBound(Substrings) > 0 Then ' If there is at least 1 substring after "!roll"
fstNum = Substrings(1) ' Get the first substring
If UBound(Substrings) > 1 Then ' If there are at least 2 substrings after "!roll"
sndNum = Substrings(2) ' Get the second substring
Else
sndNum = "0"
End If
Else
fstNum = "0"
sndNum = "0"
End If
' ...
End If
-
Jan 23rd, 2007, 05:24 PM
#6
Thread Starter
Member
-
Jan 23rd, 2007, 05:38 PM
#7
Re: If statement not catching - Different
Assuming that all other variables have been declared, you only need to add a declaration for the dynamic Substrings array.
It has occurred to me that fstNum and sndNum are Integers, not Strings, so my code above would need to modified to assign appropriate values to those variables.
-
Jan 23rd, 2007, 05:41 PM
#8
Thread Starter
Member
Re: If statement not catching - Different
 Originally Posted by Logophobic
Assuming that all other variables have been declared, you only need to add a declaration for the dynamic Substrings array.
It has occurred to me that fstNum and sndNum are Integers, not Strings, so my code above would need to modified to assign appropriate values to those variables.
Modified as in...:
fstNum = Int(Substrings(1))
?
-
Jan 23rd, 2007, 06:16 PM
#9
Re: If statement not catching - Different
fstNum = Val(Substrings(1))
This should do well enough. Int() and CInt() will cause an error if the string contains non-numeric characters, or if the string is zero-length.
-
Jan 23rd, 2007, 07:06 PM
#10
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|