|
Thread: If?
-
Jan 29th, 2003, 01:02 PM
#1
Thread Starter
Hyperactive Member
If?
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
-
Jan 29th, 2003, 01:20 PM
#2
Sleep mode
VB 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
try this
-
Jan 29th, 2003, 01:22 PM
#3
Thread Starter
Hyperactive Member
well...
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"
-
Jan 29th, 2003, 01:35 PM
#4
Registered User
You can always create a function for it.....
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
then call with something like this....
Code:
If Not TestMonth(TextBox1.Text) Then
MsgBox("Heyy, not a month there!")
End If
-
Jan 29th, 2003, 01:58 PM
#5
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
-
Jan 29th, 2003, 08:31 PM
#6
Addicted Member
you could try the or?
i don't know if this is what you want but.
Code:
If cbxFiscal.Text = "January" or "Febuary" or "etc" Then Return
Just another option
-
Jan 29th, 2003, 10:40 PM
#7
Originally posted by pirate
VB 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
try this
that doesnt work, ahem (I think )
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 29th, 2003, 11:35 PM
#8
Sleep mode
-
Jan 29th, 2003, 11:53 PM
#9
Originally posted by pirate
Sure ?? . no no you're kidding . Did the msgbox show anyways ?
well, If in4 <> in1 Or in2 Or in3 Then
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
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
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
|