An "If" command for multiple conditions!
-
Hello! I have a form with 2 textboxes and one buttton. Now, suppose the button displays a messagebox, something like this : msgbox("Hello world")! So, what i want is, the button wouldn't show the msgbox until both the textboxes have something typed in it! i've tried the "IF" command, but as far as i see it, the if command only adds one condition! For example , "IF TEXTBOX1.TEXT="" then msgbox("please fill in the form") else msgbox("Hellow world")"" But as i just said i have 2 textboxes, so is there a way to put both the textboxes in one single IF command? Something like: "IF THEXTBOX1.TEXT="" AND TEXTBOX2.TEXT="" THEN MSGBOX("PLEASE FILL IN THE FORM") ELSE MSGBOX("HELLO WORLD")?? One more thing , i want the msgbox to to show "HELLO WORLD" only when both the textboxes have something , if any of them are remained empty then msgbox will say " PLEASE FILL IN THE FORM" So , how should i do it ?
-
Hello! I have a form with 2 textboxes and one buttton. Now, suppose the button displays a messagebox, something like this : msgbox("Hello world")! So, what i want is, the button wouldn't show the msgbox until both the textboxes have something typed in it! i've tried the "IF" command, but as far as i see it, the if command only adds one condition! For example , "IF TEXTBOX1.TEXT="" then msgbox("please fill in the form") else msgbox("Hellow world")"" But as i just said i have 2 textboxes, so is there a way to put both the textboxes in one single IF command? Something like: "IF THEXTBOX1.TEXT="" AND TEXTBOX2.TEXT="" THEN MSGBOX("PLEASE FILL IN THE FORM") ELSE MSGBOX("HELLO WORLD")?? One more thing , i want the msgbox to to show "HELLO WORLD" only when both the textboxes have something , if any of them are remained empty then msgbox will say " PLEASE FILL IN THE FORM" So , how should i do it ?
You do not share which language you use, but it appears to be Visual Basic so I'm going to assume that for this answer. Visual Basic has an
And
operator which does exactly what you want (in fact, it will look like it did in your question :)):If TextBox1.Text = "" And TextBox2.Text = "" Then
MsgBox("Please fill in the form")
Else
MsgBox("Hello World")
End If(As a side note, you can also use String.IsNullOrEmpty[^] or String.IsNullOrWhiteSpace[^] rather than
= ""
) About your final question: that change is very simple, all you have to do is replace yourAnd
operator byOr
:If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Please fill in the form")
Else
MsgBox("Hello World")
End IfThe quick brown ProgramFOX jumps right over the
Lazy<Dog>
. -
You do not share which language you use, but it appears to be Visual Basic so I'm going to assume that for this answer. Visual Basic has an
And
operator which does exactly what you want (in fact, it will look like it did in your question :)):If TextBox1.Text = "" And TextBox2.Text = "" Then
MsgBox("Please fill in the form")
Else
MsgBox("Hello World")
End If(As a side note, you can also use String.IsNullOrEmpty[^] or String.IsNullOrWhiteSpace[^] rather than
= ""
) About your final question: that change is very simple, all you have to do is replace yourAnd
operator byOr
:If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Please fill in the form")
Else
MsgBox("Hello World")
End IfThe quick brown ProgramFOX jumps right over the
Lazy<Dog>
.