MajorGeeks Support Forums

Go Back   MajorGeeks Support Forums > ----------= PC, Desktop and Laptop Support =---------- > Software
Register FAQ Members List Calendar Mark Forums Read

Software Software such as operating systems like Windows XP, Windows Vista, Windows 7 etc., or specific programs.

Closed Thread
Thread Tools Display Modes
Old 04-23-12, 16:22
SelfAwareChimp SelfAwareChimp is offline
Private E-2
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Your Favorite Error - Syntax

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("")
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.
Sponsored links
Old 04-23-12, 16:57
GermanOne's Avatar
GermanOne GermanOne is offline
Major Geek's Coding Genius Extraordinaire
Join Date: Feb 2009
Location: Thuringia / Germany
Posts: 361
Thanks: 6
Thanked 89 Times in 83 Posts
Default Re: Your Favorite Error - Syntax

The debugger tells you exactly what's going wrong and where.
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"
  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:
If <condition> Then
  <code for true result>
  <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.

Closed Thread

error, explain, syntax, vbs

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Error PamLeah Software 2 10-27-08 00:14
VBScript syntax error Kniht Software 2 04-20-06 15:48
A syntax error installing xp pro SpAzZqNK Software 3 05-22-05 10:36
Invalid syntax error in IE CDank3 Software 9 05-03-05 12:34
Syntax Error Dolly Software 1 04-17-05 13:35

All times are GMT -5. The time now is 00:05.

MajorGeeks.Com Menu

MajorGeeks.Com \ 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 \ NEW! PC Games \ System Tools \ Macintosh \ Demonews.Com \ Top Downloads

MajorGeeks.Com \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

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

All content Copyright source code Powered by vBulletin® Version 3.8.4
Copyright © 2009 vBulletin Solutions, Inc. All rights reserved.
Ad Management by RedTyger