can you please help me in my code

MsgBox "Are you sure you want to Logout?", vbYesNo, "Confirmation"

If vbYes Then
    Unload Me
    frmAuthentication.Show
    End If

how can i have 2 choices example i want vb no and just stay with my form help me..

Recommended Answers

All 20 Replies

Can you reword "how can i have 2 choices example i want vb no and just stay with my form help me.."

It is not clear what you need.

Thanks

ok sir for example

If vbYes Then
    Unload Me
    frmAuthentication.Show
ElseIf vbno then
    Unload Me
(EXAMPLE I JUST WANT TO STAY WITH THE FORM)

end if 

Like that sir but its not correct thanks :D

the msg box is this

but if i click yes it will log out and even i pick no it still log out :(

No need for an Else statement since that does nothing.

Dim reply As Integer = MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")

If reply = vbYes Then
    Unload Me
    frmAuthentication.Show
End If

Sorry I just realied you might want an Else Statement - put one in if you need one.

it errors on equal it says compile error

Show me your code?

Private Sub cmdLogout_Click()
Dim reply As Integer = MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")
If reply = vbYes Then
Unload Me
frmAuthentication.Show
End If
End Sub

Here sir! ty

Where is the actual compile error?

end of statement it says

Looks oks to me. Can you zip and send me the whole solution?

Message me for my email if you want to send it.

In vb6 you can't use declaration= dadada but you need to seperate these.

Private Sub cmdLogout_Click()
Dim reply As String
reply = MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")
If reply = vbYes Then
Unload Form1
frmAuthentication.Show
End Sub

This makes me always question is it vb6 or vb.net?

Right sorry I assume this was Vb.net! Didn't even notice which area I was in.

Sorry

Dim responce As Integer 
responce = MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")
If reply = vbYes Then
    Unload Me
    frmAuthentication.Show
else
    exit sub
End If

You need to use the same variable for the return value as well as the test. You used responce to save the result but your test uses reply. Another possibility would be

If MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation") = vbYes Then
    Unload Me
    frmAuthentication.Show
else
    exit sub
End If
commented: That is the version I use. +6

thanks reverend jim my mistake thanks for pointing out i use response in what ever code i write for myself so in the description they were using reply and i used description in a mistake

commented: Yeah. I've done that. +12
commented: Setting Option Explicit at the beginning of the file can help catch this kind of thing. +6

Another way of handling this is with a Select block:

Select Case MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")
Case vbYes
    frmAuthenticaion.Show
    Unload Me
Case vbNo
    Exit Sub
End Select

Using a Select block gives you more flexibility for when you are using an option that gives more than two answers, like vbYesNoCancel or vbAbortRetyIgnore.

If there is nothing after the Select or If-Then block, then you drop the Exit Sub if you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.