Benjamin Jones
Benjamin Jones

Reputation: 997

How to define button value in popup?

I've create a VBScript popup with OK and Cancel buttons. How do I value the OK button?

Basically I want :

If OK button = True Then
  ' statement
Else

End If 

I've tried to declare intbutton= 1, then

intbutton = objshell.popup"..."

but I get a syntax error.

Upvotes: 1

Views: 99

Answers (1)

Dai
Dai

Reputation: 155145

You're getting a syntax error because in VBScript (and VBA and VB6) all Function calls must use parenthesis when capturing return values (unlike Sub calls which must not use parenthesis unless you're using Call syntax - yes, I think VBScript's syntax is dumb).

You're also missing the other parameters to the function: nSecondsToWait, strTitle, and nType. Note that those additional parameters are optional, so leave nothing in the nSecondsToWait parameter space.

VBScript has built-in constants for the arguments you're wanting, they are:

vbOK
vbOKCancel
vbAbortRetryIgnore
vbYesNoCancel
vbYesNo
vbRetryCancel

You can use them like so:

Dim result
result = shell.Popup( "Mesage text goes here", , "Window title", vbOKCancel )
If result = vbOK Then
    ' something here
End If

Upvotes: 2

Related Questions