?
Solved

VBScript program using WshShl.Run "Calc" works in windows 2000 but not in winXP

Posted on 2006-04-06
6
Medium Priority
?
1,462 Views
Last Modified: 2008-01-09
Following is a math game my scripting/programming class is entering. The caluculaor buttons show that they are pressed in win2000 but in winXP you only see the reults in the display. Can anyone tell me what I need to do different for calc in XP?

Hint: You need to enter the wrong answer to get the calc, so for once in your math life, make a mistake.

'*************************************************************************
'Script Name: Mathgame.vbs
'
'Description: This script prompts the user to solve a mathematical
'expression and demonstrates how to solve it in the event that the user
'cannot
'*************************************************************************

'Initialization Section

Option Explicit

Dim WshShl, QuestionOne, Proveit

'Define the title bar message to be displayed in the script's
'pop-up 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
QuestionOne = InputBox("What is the sum of 1 + 5 * 9 / 3 ?", cTitlebarMsg)

'See if the player provided an answer
If Len(QuestionOne) = 0 Then
  MsgBox "Sorry. You must enter a number to play this game."
  WScript.Quit
End If

'Make sure that the player typed a number
If IsNumeric(QuestionOne) <> 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 answer this question you must follow the " & _
      "correct order of precedence when performing your calculations."

    WScript.Sleep 2000
    WshShl.SendKeys "~~"
    WshShl.SendKeys "1st, working from left to right multiply 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 question my math..... watch this!"
    WScript.Sleep 2000
    WshShl.SendKeys "%{F4}"
    WshShl.SendKeys "%{N}"

    'Start the Calculator application
    WshShl.Run "Calc"

    'Use the Calculator application 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
    WshShl.SendKeys "{+}" & 1
    WScript.Sleep 2000
    WshShl.SendKeys "~"
    WScript.Sleep 2000
    WshShl.SendKeys "%{F4}"
  End If
End If
0
Comment
Question by:rivercity
6 Comments
 
LVL 15

Expert Comment

by:sr75
ID: 16403745
I ran your script to see what you were talking about,  You want to get the calculator buttons to be shown as being pushed like they usually are in Windows 2000?

Well, XP's calc doesn't push the buttons when you use the keyboard to enter in the numbers.  So I don't think it is programically possible using the sendkeys method or any other method with vbscript.  Its the calc program itself that is the issue, not the script you are using.
0
 
LVL 4

Expert Comment

by:dasmcse
ID: 16406724
Rivercity,
I have XP Sp2 and your script works perfectly from wcscript and cscript. You may want to check your XP installation make sure it's up to date.
0
 
LVL 41

Expert Comment

by:graye
ID: 16407382
.... so just copy the calc.exe from Win2k and copy it somewhere on the WinXP box (don't overwrite the original).   Then modify the script to use the path to the older version of calc.exe
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:mackenga
ID: 16439913
graye: I'm unsure if that will work; I'm under the impression that calc.exe is the same in both cases anyway.  The difference is the way Windows shows the buttons.

I can't try it since I'm in the stone age and haven't got an XP box on my network, but I suggest trying swiching themes in XP - maybe you'll see the buttons move if you're in the Windows Classic style.  I can't test it, but if copying over calc doesn't work this must be worth a try.

Hope this helps.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 16439947
If you that badly want to make the buttons appear to be moving how you want ( and you have a programming enviroment of some description ( Even vb 2005 ) or something like that. why not make your own calculator with buttons that move ?
0
 
LVL 41

Accepted Solution

by:
graye earned 2000 total points
ID: 16441191
Yep, it works... I just copied the CALC.EXE from Win2k to WinXP, and when I press a number key on the keyboard, it flashes on the calculator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question