Your Favorite Error - Syntax

Discussion in 'Software' started by SelfAwareChimp, Apr 23, 2012.

  1. SelfAwareChimp

    SelfAwareChimp Private E-2

    VBS
    Hey guys,
    This will probably be regarded as a silly question, but it's all good. Now, I know for a fact that what I've written has both numerous syntax and Parenthesis+Sub errors.
    Dim x
    Dim y
    set oShell = createobject("wscript.shell")
    x = MsgBox("Fatal error has occured, must play a game to continue.", 4+16, "Fatal Error")
    if x = "7" then
    MsgBox("Error, cannot decline challenge.", 0, "Fatal Error")
    end if
    y = InputBox("Guess the number from 1 to 100", "Fatal Error")
    if y = "77" then
    MsgBox("It's your lucky day!", 0, "Fatal Error")
    end if
    else if
    MsgBox("You lose!", 0, "Fatal Error")
    end if

    While I would appreciate someone fixing it for me, what I'd really want is someone to explain the rules to me, since I'm pretty new to this scripting game.
     
  2. GermanOne

    GermanOne Guest

    The debugger tells you exactly what's going wrong and where.
    Code:
    Dim x
    Dim y
    
    x = MsgBox("Fatal error has occured, must play a game to continue.", 4+16, "Fatal Error")
    if x = 7 then
      MsgBox "Error, cannot decline challenge.", 0, "Fatal Error"
    end if
    
    y = InputBox("Guess the number from 1 to 100", "Fatal Error")
    if y = "77" then
      MsgBox "It's your lucky day!", 0, "Fatal Error"
    else
      MsgBox "You lose!", 0, "Fatal Error"
    end if
    
    First of all you don't need the WScript.Shell object. Even if it is not an error you don't use it.

    If you use the MsgBox Function to assign a variable then you have to enclose the parameters into parentheses. If you don't assign a variable or you don't use the returned value inline the parentheses would cause an error.

    The syntax for if is:
    Code:
    If <condition> Then
      <code for true result>
    Else
      <code for false result>
    End If
    You have to distinguish numeric values which are not enclosed in quotation marks and strings which you have to enclose in quotation marks. While the MsgBox returns an integer value the InputBox function returns a string.

    Regards
    GermanOne
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds