• 0

VBS help


Question

'***************************************************

'Script name: Mathgame.vbs

'Author: Chris Kelly

'Class:7th Period B & E

'Created: 10/29/04

'Description: This script promts the user to solve a mathematical

'expression and demosntrates how to solve it in the event that the user

'cannot.

'***************************************************

'Initialization Section

Option Explicit

Dim WshShl, QuestionOne, Proveit

'Define the titlebar message to be displayed in the script's popup dialog

Const cTitlebarMsg = "The Math Game"

'Instantiate an instance of the WshShell object

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

'Present the player with the equation

QuestonOne = InputBox("What is the sum of 1 + 5 * 9 / 3 ?", cTitlebarMsg)

'See if the platyer provided an answer

If Len(QuestonOne) = 0 Then

MsgBox "Sorry. You must enter a number to play this game."

WScript.Quit

End If

'Make sure that the playe typed a number

If IsNumeric(QuestonOne) <> True Then

MsgBox "Sorry. You must enter a number to play this game."

WScript.Quit

End If

'Check to see if the player provided the correct answer

If QuestionOne = 16 Then

MsgBox "Correct! You obviously know your math!"

Else

ProveIt = MsgBox("Incorrect. Do you want to see me solve the " & _

"equation?", 36, cTitlebarMsg)

If ProveIt = 6 Then 'Player wants to see the solution

'Start the WordPad application

WshShl.Run "WordPad"

'Pause script execution to give Windows enough time to load WordPad.

Wscript.Sleep 2000

'Use Wordpad to show the player how to solve the equation

WshShl.SendKeys "To correctly answer this queston to must keep in " & _

"that you must follow the correct order of precedence when performing " & _

"numeric calculation."

WScript.Sleep 2000

WshShl.SendKeys "~~"

WshlShl.SendKeys "1st, working from left to right multiple 5 * 9."

WScript.Sleep 2000

WshShl.SendKeys "~~"

WshShl.SendKeys "2nd, divide the result by 3."

WScript.Sleep 2000

WshShl.SendKeys "~~"

WshShl.SendKeys "3rd, add 1."

Wscript.Sleep 2000

WshShl.SendKeys "~~"

WshShl.SendKeys "The final answer is 16."

WScript.Sleep 2000

WshShl.SendKeys "~~"

WshShl.SendKeys "~~"

WshShl.SendKeys "In case you queston my math..... watch this!"

WScript.Sleep 2000

WshShl.SendKeys "%{F4}"

WshShl.SendKeys "%{N}"

'Start the Calculator applictation

WshShl.Run "Calc"

'Use the Calculator applictation to solve the equation

Wscript.Sleep 2000

WshShl.SendKeys 5 & "{*}"

WScript.Sleep 2000

WshShl.SendKeys 9

WScript.Sleep 2000

WshShl.SendKeys "~~"

WScript.Sleep 2000

WshShl.SendKeys "{/}" & 3

WScript.Sleep 2000

WshShl.SendKeys "~"

WScript.Sleep 2000

End If

Im not sure how to end it... We ran outa time in class before the teacher could explain what we where doing and how to end it..

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.