Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: Messagebox Returning Values 2

Status
Not open for further replies.

Stevehewitt

IS-IT--Management
Jun 7, 2001
2,075
GB
Hi,

I'm a VBA / Access Developer and have no experience in .net whatso ever, so please bare with me whilst I post stupid questions!

I am trying to create a Message box where the user can select Yes or No. If they click Yes the app closes, No will restore back to the main screen.
The VBA code for this is:

Code:
Private Sub btnExitApp_Click()
Dim Msg, Style, Title, Response, MyString
Msg = "Are you sure you wish to exit?"    ' Define message.
Style = vbYesNo + vbExclamation    ' Define buttons.
Title = "Sales Database"    ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then    ' User chose Yes
DoCmd.Exit                  ' Close App
Else                        ' User chose No
    DoCmd.Restore    ' Returns user back to main menu
End If
End Sub

How can I do this in VB .net?

I can create message boxes without any problems, but I just don't know how to act on the results of the input. (E.G. What's the code to close the app when the users click 'Yes'?)

Sorry for the simple question, and I have hunted around the net / FAQ for it but as it's so simple it's not on the web.

Thanks in advance,


Steve.
 
Code:
Private Sub btnExitApp_Click(byval sender as object, byval e as eventargs) handles btnexitapp.click
Dim response as integer
dim Title, Msg, MyString as string
Msg = "Are you sure you wish to exit?"    ' Define message.
Title = "Sales Database"    ' Define title.
Response = Messagebox.show(Msg, Title,MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If Response = 6 Then    ' User chose Yes
  me.close                  ' Close App
End If
End Sub

Christiaan Baes
Belgium

What a wonderfull world - Louis armstrong
 
This is a little neater ...

Code:
Dim Title, Msg, MyString As String
Msg = "Are you sure you wish to exit?"    ' Define message.
Title = "Sales Database"    ' Define title.
If MessageBox.Show(Msg, Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then   ' User chose Yes
  Me.Close()                ' Close App
End If

Becca

Somtimes, the easy answer is the hardest to find. :)

Still under construction ...
 
ah women!
always trying to be neat and tidy. :)

Christiaan Baes
Belgium

What a wonderfull world - Louis armstrong
 
Hey Guys,

Thanks for your help and your prompt reply. Much appreciated. It works a treat. One of those things where books only cover a response with another messagebox - not a action and it's not anywhere on the net as everyone already knows it! :)

Cheers - works great!


Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top