Hello I am sure this is a simple question but here goes...
How do I use the If statement for multiple options?
Example:
If my text doesnt = January, Febuary, March, April... etc then
my code goes here...
??
Thanks,
Anjari
Printable View
Hello I am sure this is a simple question but here goes...
How do I use the If statement for multiple options?
Example:
If my text doesnt = January, Febuary, March, April... etc then
my code goes here...
??
Thanks,
Anjari
try thisVB Code:
Dim in1 As Integer = 1 Dim in2 As Integer = 2 Dim in3 As Integer = 3 Dim in4 As Integer = 4 If in4 <> in1 Or in2 Or in3 Then MsgBox("not equal") End If
Well..
Here is what I have... It works.. But I am sure there is an easier way...
If cbxFiscal.Text = "January" Then Return
If cbxFiscal.Text = "Febuary" Then Return
If cbxFiscal.Text = "March" Then Return
If cbxFiscal.Text = "April" Then Return
If cbxFiscal.Text = "May" Then Return
If cbxFiscal.Text = "June" Then Return
If cbxFiscal.Text = "July" Then Return
If cbxFiscal.Text = "August" Then Return
If cbxFiscal.Text = "September" Then Return
If cbxFiscal.Text = "October" Then Return
If cbxFiscal.Text = "November" Then Return
If cbxFiscal.Text = "December" Then Return
MessageBox.Show("The Fiscal value you entered is not acceptable for this field! It has been changed to 'January' to allow you to continue.", "Incorrect Value", MessageBoxButtons.OK, MessageBoxIcon.Error)
cbxFiscal.Text = "January"
You can always create a function for it.....
then call with something like this....Code:Function TestMonth(ByVal themonth As String) As Boolean
Dim i As Integer
For i = 1 To 12
If themonth = DateAndTime.MonthName(i) Then Return True
Next
Return False
End Function
Code:If Not TestMonth(TextBox1.Text) Then
MsgBox("Heyy, not a month there!")
End If
It might be better in your case to use a select case:
VB Code:
Select Case cbxFiscal.Text Case "January","February","March" Msgbox("You picked J F or M") Case "April","May" Msgbox("You picked A or M") Case Else Msgbox("You picked something else") End Select
i don't know if this is what you want but.
Just another optionCode:If cbxFiscal.Text = "January" or "Febuary" or "etc" Then Return
that doesnt work, ahem (I think:rolleyes: )Quote:
Originally posted by pirate
try thisVB Code:
Dim in1 As Integer = 1 Dim in2 As Integer = 2 Dim in3 As Integer = 3 Dim in4 As Integer = 4 If in4 <> in1 Or in2 Or in3 Then MsgBox("not equal") End If
Sure ??:eek: . no no you're kidding :D . Did the msgbox show anyways ?Quote:
Originally posted by MrPolite
that doesnt work, ahem (I think:rolleyes: )
well, If in4 <> in1 Or in2 Or in3 ThenQuote:
Originally posted by pirate
Sure ??:eek: . no no you're kidding :D . Did the msgbox show anyways ?
means:
if int4<>int1 or
in2 = true or
in3 = true
which is equal to this:
VB Code:
If in4 <> in1 Or CBool(in2) Or CBool(in3) Then MsgBox("not equal") End If