|
-
September 18th, 2003, 09:18 AM
#1
Senior Member
Needs help in VB6
Hi all, can anyone tell me how to use msgbox in vb 6
I mean, let say
msgbox "Do you want to continue?", vbYesNo, "My Program"
- How to use VbYesNo? How to write a program for this?
- what is the value will returned by Yes or No
help me.... or give me simple example......
-
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
-
September 18th, 2003, 11:42 AM
#3
Member
sometimes i use msgbox just for debugging
you can use this in a very simplistic form:
msgbox "any text here"
or
msgbox any_variable_here
=====
but for your question, this might work:
if msgbox("Do you want to continue?", vbYesNo, "My Program") = vbYes then
msgbox "you chose YES" 'put the code for 'yes'
else
msgbox "you chose NO" 'put the code for 'no'
endif
When you have eliminated the impossible, whatever remains, however improbable, must be the truth. - Sherlock Holmes
i am NOT a hacker :Þ
-
September 18th, 2003, 11:53 AM
#4
On a side note, dont forget Debug.* is there for debug purposes as well, saves time/memory/effort in comparison to MsgBox, and doesnt affect the actual program.
For x = 0 to lstResults.listcount - 1
Debug.Print "x = " & x
Debug.Print "Corresponds to the following item on lstResults: " & lstResults.List(x)
Next x
etc etc. It puts the .Print'ed text into the tiny debug screen at the bottom when you run the program through VB.
-
September 18th, 2003, 05:38 PM
#5
go to www.planetsourcecode.com
You will get tonnes of examples to faf arround with.
-
September 18th, 2003, 06:23 PM
#6
 Mad Beaver
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
|
|