Results 1 to 8 of 8

Thread: [RESOLVED] Syntax or Logic error?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Location
    Riverton, WY
    Posts
    36

    Resolved [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:
    1. Select Case True
    2.             'Does input meet requirements for Case
    3.             Case InStr(sockBuff, "!roll") <> 0:
    4.                 'Digging out the "!roll" command
    5.                 charLocNum = InStr(2, sockBuff, ":")
    6.                 comFinder = Right(sockBuff, Len(sockBuff) - charLocNum)
    7.  
    8.                 'Digging out name of inputter
    9.                 'Can use a Mid() command below, but didn't know that at the time
    10.                 charName = Left(sockBuff, InStr(1, sockBuff, "!") - 1)
    11.                 charName = Right(charName, Len(charName) - 1)
    12.  
    13.                 'Making sure "!roll" is at start of input
    14.                 If InStr(comFinder, "!roll") = 1 Then
    15.  
    16.                     'If it's single/double digit dice with NO threshold...
    17.                     If Len(comFinder) = 7 Or 8 Then
    18.                         'Digging out number of dice
    19.                         numFinder = InStr(comFinder, " ")
    20.                         fstNum = Right(comFinder, Len(comFinder) - numFinder)
    21.                         'The below line of code contains the error.  i know the first part of it is correct (It runs great lower in the code)
    22.                         sendToIRC (sendMsgText + " PRIVMSG #shadowfall :" + charName + " rolled " + fstNum + " dice: " + diceRoller(fstNum, 0))
    23.                     'else if Len(CommandFinder) = 9 or 10 or 11
    24.                     '    Find first " "
    25.                     '    Find 2nd " "
    26.                     '    Grab 1st number
    27.                     '    Grab 2nd number
    28.                     '    Call roll program - send First num as dice, Second num as Threshold (Target #)
    29.                     End If
    30.                     If InStr(1, comFinder, "!roll") = 1 Then
    31.                         charName = Left(sockBuff, InStr(1, sockBuff, "!") - 1)
    32.                         charName = Right(charName, Len(charName) - 1)
    33.                         'The below line of code works perfect
    34.                         sendToIRC (sendMsgText + " PRIVMSG #shadowfall :" + charName)
    35.                     End If
    36.                 End If
    37.         End Select


    The function it's calling is:

    VB Code:
    1. Function diceRoller(ByVal fstNum As Long, ByVal sndNum As Long) As String
    2.     'Haven't yet programmed in the random number calculations yet
    3.     diceRoller = "A GODLY DICE ROLL!"
    4. 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.

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Location
    Riverton, WY
    Posts
    36

    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.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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)

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2007
    Location
    Riverton, WY
    Posts
    36

    Lightbulb Re: Syntax or Logic error?

    I take it Cstr() Converts to a number to a string?

  6. #6

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2007
    Location
    Riverton, WY
    Posts
    36

    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?

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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
  •  



Click Here to Expand Forum to Full Width