• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

VBScript Coding

Status
Not open for further replies.
Level 9
Joined
Apr 14, 2007
Messages
437
Okay, I am trying to make a simple test for my school as a project were working on. I'm making an 8th-Grade Social Studies test using VBScript, but something just doesn't work out. I want my 2 variables (Right, Wrong) to add 1 to the variable, depending if the person answers correctly or incorectly. Like say if they answered correct, "Right = 1" "Wrong = 0" and if they answered wrong on the next one, "Right = 1" "Wrong = 1", and if they answer wrong on the 3rd question, "Right = 1" "Wrong = 2" but I can't get it to do that, because the variable would equal the first thing it's set to, and not increase correctly. I'm sorry if you don't understand this well, but here's my coding, I hope you can tell me how to make variables increase numbers. It is also unfinished:


Dim WinShell, prompt, answer

Set WinShell = WScript.CreateObject("WScript.Shell")
MsgBox("This is a practice social studies test about the Revolutionary War. Try your best, this is not graded. If you do not know the answer, simply press the OK or Cancel buttons until you reach the end of the test. Made By: Brandon P.")
prompt = "What was the turning point in the war?" & vbCrLf &_
"" & vbCrLf &_
"(No cheating either or you fail. Also, you must capitalize and spell correctly or you fail the test.)"

answer = InputBox(prompt, "Practice SS Test")

If answer = "Saratoga" Then
MsgBox("Congragulations, you got it right! Here's the next question.")
Right = 1
Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Saratoga"
Wrong = 1
End If

prompt = "Who was offered 20,000 pounds to turn over West point?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "Benedict Arnold" Then
MsgBox("Congragulations, you got it right! Here's the next question.")
Right = Right + 1
Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Benedict Arnold"
Wrong = Wrong + 1
End If
prompt = "Who manned a cannon a gave water to soldiers during a battle?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "Molly Pitcher" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Molly Pitcher"

End If

prompt = "Who dressed as a man during the revolutionary war and fought in many battles?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "Deborah Sampson" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Deborah Sampson"

End If

prompt = "Who was the British Main General, and who lost to Washington at Yorktown?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "Lord Cornwallis" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Lord Cornwallis"

End If

prompt = "Who lost to General Horatio Gates at Saratoga?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "General Burgoyne" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"General Burgoyne"

End If

prompt = "What general decided to move his army to Philadelphia rather than New York because of his girlfriend?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "General Howe" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"General Howe"

End If

prompt = "Who was the offical scribe of the Continental Congress, Calligrapher, not writer?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "Timothy Matlack" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Timothy Matlack"

End If

prompt = "Who asked Patrick Henry for permission to defend Virginia's Western Frontier?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "George Rogers Clark" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"George Rogers Clark"

End If

prompt = "Who was a privateer who commanded the ship Bahomme Richard against the British ship Serapis and won?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "John Paul Jones" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"John Paul Jones"

End If

prompt = "What was the group's name of people who were German Mercenaries who were paid to fight for the British?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "Hessians" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Hessians"

End If

prompt = "What woman sued Massachusetts for her freedom after the war and won?"

answer = InputBox(prompt, "Practice SS Test")

If answer = "Elizabeth Freeman" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Elizabeth Freeman"

End If

prompt = ""

answer = InputBox(prompt, "Practice SS Test")

If answer = "" Then
MsgBox("Congragulations, you got it right! Here's the next question.")

Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
""

End If
















If IsNumeric(a) And IsNumeric(b) Then
TotalWrong = Wrong
TotalRight = Right
PercentCorrect = 37 / Right
Wscript.Echo "Total Wrong: " & c
Wscript.Echo "Total Right: " & d
Wscript.Echo "Percent Correct: " & e
Else
Wscript.Quit
End If
 
Level 15
Joined
Nov 1, 2004
Messages
1,058
Start by setting Right = 0 and Wrong = 0 at the very start of your program. Then always use Right = Right + 1 and Wrong = Wrong + 1 as people answer questions correctly or incorrectly.
 
Level 9
Joined
Apr 14, 2007
Messages
437
nevermind, I got it to work...sort of... It stopped erroing on me, and figures out the final score correctly, but it doesn't add to the variable, and one variable doesn't work at all. Here's the end of the coding, I changed the variables to sinlge-letters so it would work:

Dim WinShell, prompt, answer

REM 'Do not edit this coding

Set WinShell = WScript.CreateObject("WScript.Shell")

MsgBox("This is a practice social studies test about the Revolutionary War. Try your best, this is not graded. If you do not know the answer, simply press the OK or Cancel buttons until you reach the end of the test. Made By: Brandon P.")
prompt = "What was the turning point in the war?" & vbCrLf &_
"" & vbCrLf &_
"(No cheating either or you fail. Also, you must capitalize and spell correctly or you fail the test.)"

answer = InputBox(prompt, "Practice SS Test")
a = 0
b = 0
If answer = "Saratoga" Then
MsgBox("Congragulations, you got it right! Here's the next question.")
a = a + 1
Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Saratoga"
b = b + 1
End If
answer = InputBox(prompt, "Practice SS Test")
a = 0
b = 0
If answer = "Saratoga" Then
MsgBox("Congragulations, you got it right! Here's the next question.")
a = a + 1
Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Saratoga"
b = b + 1
End If
answer = InputBox(prompt, "Practice SS Test")
a = 0
b = 0
If answer = "Saratoga" Then
MsgBox("Congragulations, you got it right! Here's the next question.")
a = a + 1
Else
MsgBox("Answer is....................") & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Saratoga"
b = b + 1
End If
answer = InputBox(prompt, "Practice SS Test")
a = 0
b = 0
If answer = "Saratoga" Then



'Variables: a=total right, b= total wrong, c= total right to display, d= total wrong to display, e= Percent Correct

If IsNumeric(a) And IsNumeric(b) Then
c = b
d = a
e = a/5
Wscript.Echo "Total Right: " & d
Wscript.Echo "Total Wrong: " & c
Wscript.Echo "Percent Correct: " & e & " out of 1.00 (100%)"
Else
Wscript.Quit
End If
 
Level 15
Joined
Nov 1, 2004
Messages
1,058
Only set a = 0 and b = 0 at the very start of the program. Don't keep setting them to zero again.

And you could not use 'Right' as a variable name because that is the name of a built-in string manipulation function.
 
Status
Not open for further replies.
Top