Results 1 to 9 of 9

Thread: If?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    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

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Dim in1 As Integer = 1
    2. Dim in2 As Integer = 2
    3. Dim in3 As Integer = 3
    4. Dim in4 As Integer = 4
    5.  
    6. If in4 <> in1 Or in2 Or in3 Then
    7. MsgBox("not equal")
    8. End If
    try this

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    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"

  4. #4
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    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

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It might be better in your case to use a select case:
    VB Code:
    1. Select Case cbxFiscal.Text
    2.    Case "January","February","March"
    3.       Msgbox("You picked J F or M")
    4.    Case "April","May"
    5.       Msgbox("You picked A or M")
    6.    Case Else
    7.       Msgbox("You picked something else")
    8. End Select

  6. #6
    Addicted Member Stick's Avatar
    Join Date
    Aug 1999
    Location
    Iowa
    Posts
    152

    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

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by pirate
    VB Code:
    1. Dim in1 As Integer = 1
    2. Dim in2 As Integer = 2
    3. Dim in3 As Integer = 3
    4. Dim in4 As Integer = 4
    5.  
    6. If in4 <> in1 Or in2 Or in3 Then
    7. MsgBox("not equal")
    8. 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!!

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by MrPolite
    that doesnt work, ahem (I think )
    Sure ?? . no no you're kidding . Did the msgbox show anyways ?

  9. #9
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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:
    1. If in4 <> in1 Or CBool(in2) Or CBool(in3) Then
    2.             MsgBox("not equal")
    3.         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
  •  



Click Here to Expand Forum to Full Width