|
-
Jan 23rd, 2007, 02:26 PM
#1
Thread Starter
Member
[RESOLVED] Syntax or Logic error?
I keep getting a Run-time Error 13: "Type Mismatch" on one of the below lines of code.
My input is:
":[email protected] PRIVMSG #shadowfall :!roll 1"
VB Code:
Select Case True
'Does input meet requirements for Case
Case InStr(sockBuff, "!roll") <> 0:
'Digging out the "!roll" command
charLocNum = InStr(2, sockBuff, ":")
comFinder = Right(sockBuff, Len(sockBuff) - charLocNum)
'Digging out name of inputter
'Can use a Mid() command below, but didn't know that at the time
charName = Left(sockBuff, InStr(1, sockBuff, "!") - 1)
charName = Right(charName, Len(charName) - 1)
'Making sure "!roll" is at start of input
If InStr(comFinder, "!roll") = 1 Then
'If it's single/double digit dice with NO threshold...
If Len(comFinder) = 7 Or 8 Then
'Digging out number of dice
numFinder = InStr(comFinder, " ")
fstNum = Right(comFinder, Len(comFinder) - numFinder)
'The below line of code contains the error. i know the first part of it is correct (It runs great lower in the code)
sendToIRC (sendMsgText + " PRIVMSG #shadowfall :" + charName + " rolled " + fstNum + " dice: " + diceRoller(fstNum, 0))
'else if Len(CommandFinder) = 9 or 10 or 11
' Find first " "
' Find 2nd " "
' Grab 1st number
' Grab 2nd number
' Call roll program - send First num as dice, Second num as Threshold (Target #)
End If
If InStr(1, comFinder, "!roll") = 1 Then
charName = Left(sockBuff, InStr(1, sockBuff, "!") - 1)
charName = Right(charName, Len(charName) - 1)
'The below line of code works perfect
sendToIRC (sendMsgText + " PRIVMSG #shadowfall :" + charName)
End If
End If
End Select
The function it's calling is:
VB Code:
Function diceRoller(ByVal fstNum As Long, ByVal sndNum As Long) As String
'Haven't yet programmed in the random number calculations yet
diceRoller = "A GODLY DICE ROLL!"
End Function
If anything needs explanation, please let me know. I cannot figure out what it is I'm doing wrong in the indicated line of code.
Thank you!
Last edited by CyberInfantry; Jan 23rd, 2007 at 02:29 PM.
-
Jan 23rd, 2007, 02:28 PM
#2
Re: Syntax or Logic error?
Remove the parenthesys. You should also use & instead of +.
-
Jan 23rd, 2007, 02:32 PM
#3
Thread Starter
Member
Re: Syntax or Logic error?
Sorry, last language I used in any quantity was Java. :P
Why do the +'s work lower for the same thing, but not up here?
Which set of ()'s are you saying I should get rid of?
Thank you for your help.
-
Jan 23rd, 2007, 02:32 PM
#4
Re: Syntax or Logic error?
In a way, it's both logic and syntax.
When joining strings you should use & instead of + , otherwise (as I presume is happening) it will try to add a string to a number, which can't be done. (eg: "1"+1 = 2 , but "si" + 1 doesnt make sense!)
Also, when working with different data types you should use the conversion functions (but VB will do this bit for you - often badly), eg: myString = "some text " & Cstr(myNumber)
-
Jan 23rd, 2007, 02:36 PM
#5
Thread Starter
Member
Re: Syntax or Logic error?
I take it Cstr() Converts to a number to a string?
-
Jan 23rd, 2007, 02:37 PM
#6
Re: Syntax or Logic error?
 Originally Posted by CyberInfantry
I take it Cstr() Converts to a number to a string?
Yes.
-
Jan 23rd, 2007, 02:40 PM
#7
Thread Starter
Member
Re: Syntax or Logic error?
Thank you! I pulled out the "+"s and put in "&"s. I also put fstNum into Cstr(). Works perfectly. 
I'm curious now, though; which set of ()'s were you saying I should remove?
-
Jan 23rd, 2007, 03:03 PM
#8
Re: Syntax or Logic error?
[QUOTE=CyberInfantry...I'm curious now, though; which set of ()'s were you saying I should remove?[/QUOTE]From your original code.
sendToIRC (sendMsgText + " PRIVMSG #shadowfall :" + charName + " rolled " + fstNum + " dice: " + diceRoller(fstNum, 0))
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
|