adam
adam

Reputation: 371

Can you 'mix and match' between buttons in a VBScript MsgBox?

I'm learning to code in VBScript and I was making a message box when an idea struck me: Can I 'mix and match' the buttons in a MsgBox, as in, instead of having vbYesNo, can you have vbYesCancelRetry or something?

Upvotes: 2

Views: 103

Answers (1)

Tomalak
Tomalak

Reputation: 338326

Can I 'mix and match' the buttons in a MsgBox, as in, instead of having vbYesNo, can you have vbYesCancelRetry or something?

This is easily answered by simply trying it out (hint: the answer is No).

The values MsgBox expects are predefined constants:

Constant            Value    Binary
vbOKOnly            0        0000
vbOKCancel          1        0001
vbAbortRetryIgnore  2        0010
vbYesNoCancel       3        0011
vbYesNo             4        0100
vbRetryCancel       5        0101

Since the numbers are not all strict powers of two(*), their binary representation overlaps. For example: vbAbortRetryIgnore shares a bit with vbYesNoCancel, but paints entirely different buttons.

The implication is: You can't switch on or off individual buttons, buttons only come in predefined sets. The constants are used to select one of the sets.


(*) If they were, they would each address an individual bit, resulting in such a pattern:

ButtonA    0    0000
ButtonB    1    0001
ButtonC    2    0010
ButtonD    4    0100
ButtonE    8    1000

Under such circumstances you could mix and match. Alas, that's not the way the MessageBox API function is implemented in Windows. VBScript's MsgBox() is just a thin wrapper around that system function call.

Upvotes: 3

Related Questions