|
-
Mar 10th, 2011, 11:48 AM
#1
Thread Starter
New Member
Can i have multiple IF statements in a single button?
Hi i am very very new to visual basic.. i have some experiance with SQL scripting that's it.
I am just starting to learn the visual basic language so i am trying to make a simple application where a user can put in it's first and last name or else the application exists.
I manage to do this fine untill i get to the point of ending one if statement and starting another in the same button.. I do not really know how to explain it but maybe someone can look and my code and guide me to what is wrong.
(in the form i have button1, button2, label1, label2. Button2 is only a "quit" button)
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim prompt1, prompt2, firstname, lastname, msg1, msg2 As String
Dim response As MsgBoxResult
Dim response2 As MsgBoxResult
prompt1 = "give me your first name"
prompt2 = "give me your last name"
msg1 = "acsess denied"
msg2 = "acsess denied"
'prompts you for firstname'
firstname = InputBox(prompt1)
MsgBox(firstname, vbYesNo, "input result")
If response = MsgBoxResult.Yes Then
'the firstname is supposed to be visible in the lable if you click yes'
Label1.Text = firstname
Else
'the application is supposed to close when you click no'
MsgBox(msg1, , )
Application.Exit()
End If
'prompts you for lastname'
lastname = InputBox(prompt2)
MsgBox(lastname, vbYesNo, "input result")
If response2 = MsgBoxResult.Yes Then
'the lastname is supposed to be visible in the lable if you click yes'
Label2.Text = lastname
Else
'the application is supposed to close when you click no'
MsgBox(msg2, , )
Application.Exit()
End If
End Sub
What happens when i run this is that i can put in the first name but then when i click yes the application closes.
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
|
Click Here to Expand Forum to Full Width
|