Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Button Constants with popup

Status
Not open for further replies.

Netman06

Technical User
Aug 15, 2006
70
US
Hello,

Can you look at this code, see why the button constants are not being picked up.

Const TIMEOUT = 10
Dim intClicked
Set objShell = WScript.CreateObject("WScript.Shell")

'objShell.Popup "Abort, Retry, Ignore. Retry Set as Default." ,TIMEOUT,,vbYesNo+vbDefaultButton1

objShell.Popup "Stop Icon / Abort, Retry and Ignore Buttons", _
TIMEOUT, "Popup Example", vbInformation + vbYesNo


If intClicked = 6 Then
objItem.StartService()
WScript.Echo "Button Constants 6"
End If

If intClicked = 7 Then
WScript.Echo "Button Constants 7"

End If

Thanks,

Mike
 
Original Script, I get this error message with it.

Error Message

Microsoft VBScript compilation error: Expected end of statement


'**********************************************************
'* Displaying Message-boxes.
'**********************************************************
'* Easiest, but least options (only [OK]-button)
WScript.Echo "This is my computer: " & strComputer & "."
'
'* Wscript.Shell Popup-method has many options
'* A timed message-box (5 sec.)
Const TIMEOUT = 5
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Popup "Disk Report Complete", TIMEOUT

'* Constants for Icons
'** Icon_______________Constant Name___Constant Value
'** STOP vbCritical 16
'** QUESTION MARK vbQuestion 32
'** EXCLAMATION MARK vbExclamation 48
'** INFORMATION vbInformation 64
Const vbCritical = 16

'* Constants for Button Sets
'** Button Set_____________Constant Name___Constant Value
'** OK vbOKOnly 0
'** OK and CANCEL vbOKCancel 1
'** ABORT, RETRY and IGNORE vbAbortRetryIgnore 2
'** YES, NO and CANCEL vbYesNoCancel 3
'** YES and NO vbYesNo 4
'** RETRY and CANCEL vbRetryCancel 5
Const vbYesNo = 4

'* Constants for Default Button Locations
'** Default Button_Constant Name_______Constant Value
'** LEFT vbDefaultButton1 0
'** MIDDLE vbDefaultButton2 256
'** RIGHT vbDefaultButton3 512
Const vbDefaultButton3 = 512

'* Display both an icon and a button set, timeout is 10 sec., default is
'* rightmost button (No).
TIMEOUT = 10
strPopupTitle = "Popup Example"
strPopupText = "Stop Icon / Abort, Retry and Ignore Buttons"
objShell.Popup strPopupText, TIMEOUT, strPopupTitle, vbCritical + vbYesNo + vbDefaultButton3

'* Retrieving User Input
'* Button Constants
'** Value__Constant____Button Clicked
'** 1 VbOK OK
'** 2 VbCancel Cancel
'** 3 VbAbort Abort
'** 4 VbRetry Retry
'** 5 VbIgnore Ignore
'** 6 VbYes Yes
'** 7 VbNo No
Const VbYes = 6
intClicked = objShell.Popup strPopupText, TIMEOUT, strPopupTitle, vbCritical + vbYesNo + vbDefaultButton3
'** This can be verified with either of the following lines:
If intClicked = 6
'** or
If intClicked = VbYes
'** or (more elaborate, but also more options):
Select Case intClicked
Case vbYes
WScript.Echo "Yes"
Wscript.Quit
Case vbNo
WScript.Echo "No"
Wscript.Quit
Case -1
WScript.Echo "Popup timed out."
Wscript.Quit
End Select
 
How can you edit your posts?

Microsoft VBScript compilation error: Expected end of statement

Line:

56.30

intClicked = objShell.Popup strPopupText, TIMEOUT, strPopupTitle, vbCritical + vbYesNo + vbDefaultButton3

Between these two

Popup strPopupText

Thanks,

Mike
 
You don't need to define the constants for the vbCritical, vbYes, vbNo, etc. You can simply use them.

This part
intClicked = objShell.Popup strPopupText, TIMEOUT, strPopupTitle, vbCritical + vbYesNo + vbDefaultButton3

Should be in parenthesis

intClicked = objShell.Popup(strPopupText, TIMEOUT, strPopupTitle, vbCritical + vbYesNo + vbDefaultButton3)

Your IF statements at the bottom are incomplete as well.

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
Thanks, dm4ever

That fixed it. And thanks for explaining the consts

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top