|
-
September 18th, 2003, 09:51 AM
#2
Hey there.
Heres a quick easy example;
Dim a As Integer
'we will start with a simple msgbox that has two choices: yes and no
a = MsgBox("Do you like rice?", vbYesNo,"Rice")
'now we check what the user selected with an if statement. Although we could use numerical values, vb constants are much easier; vbyes, vbno, vbcancel etc. Press F2 to open the object browser in vb where you can find a full list.
If a = vbYes Then
'yes stuff
Else
'no stuff
End If
If you need further help, just specify what you need 
Edit -- Im bored, so i might add some stuff you'd find useful;
Heres exactly what the above does.
Firstly, we set aside some memory space for a variable called 'a' -- can be anything you want. vbYesNo and all its variants convert to whole numbers, so i am Dim'ing it as Integer.
Then comes the msgbox. In front of it i put a =, which will set the users choice (vbYes or vbNo in this case) to the variable we set in the previous step. The rest is self explanitory; MsgBox(text, buttons, title).
After the user has selected an option, we pass it through an If statement to determine what they selected. As i mentioned, you can use the proper numerical values (below), or you can just use the visual basic constant for 'yes'; vbYes.
Here is a list of constants/values associated with the MsgBox in Visual Basic.
Event -- Constant -- Numerical Value
User clicks 'yes' -- vbYes -- 6
User clicks 'no' -- vbNo -- 7
User clicks 'OK' -- vbOK -- 1
User clicks 'Cancel' -- vbCancel -- 2
User clicks 'Abort' -- vbAbort -- 3
User clicks 'retry' -- vbRetry -- 4
User clicks 'ignore' -- vbIgnore -- 5
To get these buttons to appear on your message box, use any of the following in the 'Buttons' field [ MsgBox(text, buttons, title) ]
Constant -- Buttons Displayed
vbYesNo -- Yes, No
vbYesNoCancel -- Yes, No, Cancel
vbRetryCancel -- Retry, Cancel
vbOkCancel -- OK, Cancel
vbOkOnly [default] -- OK
vbAbortRetryIgnore -- Abort, Retry, Ignore
If you want to be adventurous, try adding an icon to the messagebox. to do this, is the following format: MsgBox(text, icon + button, title). Example - MsgBox("**** off", vbCritical + vbAbortRetryIgnore, "hello")
Icon Constant -- Icon Displayed/Effects
vbCritical -- Windows critical icon, critical beep sounds
vbQuestion -- Windows question mark icon, question beep sounds
vbExclamation -- Exclamation mark, beep sounds
vbInformation -- 'i' Information icon, info beep sounds
well, that was fun. as i said above, any questions just ask
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|