Public Group

# VB Function Question

This topic is 4967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is just a question I have for a game I'm making. Basically, I just wondered how you tell the program what to do if user clicks Cancel, Abort, Retry or Okay is response to a sudden MsgBox. Thanks in advance.

##### Share on other sites
Dim intResponse As IntegerintResponse = MsgBox("Whatever you want to ask", "Title", vbYesNoCancel)If (intResponse = vbYes) Then    ' Do whatever you want here for "Yes".ElseIf (intResponse = vbNo) Then    ' Do whatever you want here for "No".ElseIf (intResponse = vbCancel) Then    ' Do whatever you want here for "Cancel".End If

You can also use other constants to test the return value like vbAbort, vbRetry, etc... actually, if you declare "intResponse" as type vbResponse (or something like that), it will allow you to use the CodeAssist or whatever it's called, so you can see all the possible values.

There are also other options besides vbYesNoCancel (e.g. vbYesNo, vbOkOnly, vbOkCancel, etc) that you can provide to the function to determine which buttons to display.

##### Share on other sites
Thanks a lot Mattman!

Oh, and one other thing I was having problems with was pressing command to take me to another form.

Hypothetically say I wanted vbOK to take them to the next screen (form3 lets say) or VBCancel to go back to the original form where they can say ... fill out an application form for something again (form 1 lets say).

How would I do that?

I've tried experimenting with GOTO form3 and GOTO (form3) and everything else I've come accross in program that I thought could work, but it hasn't worked with VB. The book I'm learning from is quite bad and I expect the answer to this question would probably be somewhere in chapter 19 when I'm in Chapter 8 now, and left in the dark.

Again, help is appreaciated.

##### Share on other sites
Try this...

If intResponse=vbOk Tthen
form3.show
ElseIf intResponse=vbCancel Then
form1.show
End If

The GoTo statement simply goes to a different line, not a form. Like in this while loop...

While True

MsgBox "This is normally an infinite loop"
GoTo theLine

Wend

theLine: MsgBox "Nice line!"

If you executed that, the goto statement would exit the loop and go directly to the aptly named line "theLine", which displays a message box. It can also be used for a block of code like:

While True

MsgBox "This is normally an infinite loop"
GoTo theBlockOfCode

Wend

theBlockOfCode:

MsgBox "Inside the block..."
MsgBox "Still inside the block..."

If you executed that you would see those two messsage boxes. Also keep in mind that those are just examples, it is not a very good idea to use alot of goto statements in loops, it makes people go insane...

Hope that helps :)

##### Share on other sites
Thanks guys.

I've tried to do what I just learned, but there's a hitch somewhere. Here is what I put down.

Clarify = MsgBox(strman_fname & " " & strman_lname & "are you sure you want proceed managing with " & List1 & "?", =vbYesNo + vbQuestion, "Confirm Decision")
If (Clarify = vbYes) Then
form2.Show
ElseIf (Clarify = vbNo) Then
manprofile.Show
End If

Basically strman_fname and strman_lname are just the manager's firstname and last name that get entered on the form. List1 is the club they select to manage. manprofile is the name of the form and form2 is a form a created simply for the testing to see if this works - it has no use ... yet.

The according to the debugging my problem is somewhere in the =vbYesNO + vbQuestion section of the MsgBox() function. I have no idea what exactly it is though.

Any of you know?

Help appreaciated.

##### Share on other sites
Quote:
 Original post by ClottyClarify = MsgBox(strman_fname & " " & strman_lname & "are you sure you want proceed managing with " & List1 & "?", =vbYesNo + vbQuestion, "Confirm Decision")

Take out the '=' before vbYesNo so it reads:

Clarify = MsgBox(strman_fname & " " & strman_lname & "are you sure you want proceed managing with " & List1 & "?", vbYesNo & vbQuestion, "Confirm Decision")

Deg

##### Share on other sites
Quote:
 If intResponse=vbOk Tthen form3.show ElseIf intResponse=vbCancel Then form1.showEnd If

You can also write "form3.show 1". "1" is a parameter.
Writing in this way can keep form3 activated until a code ends it.

##### Share on other sites
So, I have a new problem for you then :)

Private Sub cmdproceed_Click()

Clarify = MsgBox(strman_fname & " " & strman_lname & "are you sure you want proceed managing with " & List1 & "?", vbYesNo + vbQuestion, "Confirm Decision")

If (Clarify = vbYes) Then

Form1.Show AND manprofile.Hide

ElseIf (Clarify = vbNo) Then

manprofile.Show

End If

End Sub

There is an error here and I know it's in this line

"Form1.Show AND manprofile.Hide"

I'm guessing it's because I've used the AND in an illegal context for VB6. How else can I do the same thing?

##### Share on other sites
Why do you need the AND? Just put it on the next line.

##### Share on other sites
That works, I just didn't think of trying it. I supppose as I use VB6 more things like this will just get natural for me.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634065
• Total Posts
3015313
×