Results 1 to 6 of 6

Thread: IF, then, Else Functions errors

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2013
    Posts
    23

    IF, then, Else Functions errors

    This may seem like a stupid question but I can't seem to get the IF function to work. I got it to work in an earlier section:
    Code:
     If txtSat1.Text = "" Then
                If txtSat2.Text = "" Then
                    If cbSat.CheckState = 0 Then
                        MessageBox.Show("Please Enter Hours for Saturday")
                    End If
                End If
            End If
    but with my current code here:
    Code:
    If txtSun1.Text <> Then
                cbSun.CheckState = 0
                Else If txtSun2.Text <> Then
                cbSun.CheckState = 0
            End If
    Both the "Then"s are underline blue and it says "expression expected." I have two textboxes and a checkbox. If the user types something into either one of the textboxes, then I want the checkbox to not be able to be clicked. Any help would be appreciated.

  2. #2
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: IF, then, Else Functions errors

    Quote Originally Posted by jhaag4 View Post
    This may seem like a stupid question but I can't seem to get the IF function to work. I got it to work in an earlier section:
    but with my current code here:
    Code:
    If txtSun1.Text <> Then
                cbSun.CheckState = 0
                Else If txtSun2.Text <> Then
                cbSun.CheckState = 0
            End If

    If txtSun1.Text <> (not equal to what?) Then

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2013
    Posts
    23

    Re: IF, then, Else Functions errors

    OH. I thought that <> meant that the textbox.Text has something written in it by the user. Like the opposite of ""

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: IF, then, Else Functions errors

    There is no opposite of ""!
    <> means literally 'either less than or greater than' and so 'does not equal'. In this case I imagine that what you want is

    If txtSun1.Text <> "" Then
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: IF, then, Else Functions errors

    The <> is just a nice way of saying both < or >. In other words, not equal to. C-style languages often have a != operator which may make a bit more sense if you know that the ! is the not operator (or at least one of them), so it reads as Not Equal. However, the <> convention is much more common as far as I can tell, as it seems to extend beyond programming.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2013
    Posts
    23

    Re: IF, then, Else Functions errors

    That was it! Thank you everyone!

Tags for this Thread

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