Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. if statement....

if statement....

Scheduled Pinned Locked Moved Visual Basic
questionhelp
7 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jamal Abdul Nasir
    wrote on last edited by
    #1

    --> i am having a problem with this code...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If Not Me.TextBox1.Text = "a" Or Not Me.TextBox1.Text = "b" Then
    MsgBox("1")
    Else
    MsgBox("2")
    End If
    End Sub

    --> this code always prints "1" in da message box.. --> what is the problem?

    J A Nasir K

    M D A T 4 Replies Last reply
    0
    • J Jamal Abdul Nasir

      --> i am having a problem with this code...

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      If Not Me.TextBox1.Text = "a" Or Not Me.TextBox1.Text = "b" Then
      MsgBox("1")
      Else
      MsgBox("2")
      End If
      End Sub

      --> this code always prints "1" in da message box.. --> what is the problem?

      J A Nasir K

      M Offline
      M Offline
      MidwestLimey
      wrote on last edited by
      #2

      If TextBox1.Text is "a" then it is not "b", thus the first condition is fulfilled. The same for TextBox1.Text being "b". Any other value will also fulfill this condition. You probably want to exclude both "a" AND "b".

      10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011

      1 Reply Last reply
      0
      • J Jamal Abdul Nasir

        --> i am having a problem with this code...

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not Me.TextBox1.Text = "a" Or Not Me.TextBox1.Text = "b" Then
        MsgBox("1")
        Else
        MsgBox("2")
        End If
        End Sub

        --> this code always prints "1" in da message box.. --> what is the problem?

        J A Nasir K

        D Offline
        D Offline
        Dalek Dave
        wrote on last edited by
        #3

        Jamal Abdul Nasir wrote:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not Me.TextBox1.Text = "a" And Not Me.TextBox1.Text = "b" Then MsgBox("1") Else MsgBox("2") End If End Sub

        Use And not Or If it is not A and Not B then do something, else do something else.

        ------------------------------------ "Children today are tyrants. They contradict their parents, gobble their food and tyrannize their teachers. I despair for the future." Socrates 400BC

        1 Reply Last reply
        0
        • J Jamal Abdul Nasir

          --> i am having a problem with this code...

          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          If Not Me.TextBox1.Text = "a" Or Not Me.TextBox1.Text = "b" Then
          MsgBox("1")
          Else
          MsgBox("2")
          End If
          End Sub

          --> this code always prints "1" in da message box.. --> what is the problem?

          J A Nasir K

          A Offline
          A Offline
          Andy Missico
          wrote on last edited by
          #4

          Try to avoid "Not Logic". It is hard to read thus it can cause logic errors. Write you logic without the NOT operator and you will find it is much easier.

          1 Reply Last reply
          0
          • J Jamal Abdul Nasir

            --> i am having a problem with this code...

            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Not Me.TextBox1.Text = "a" Or Not Me.TextBox1.Text = "b" Then
            MsgBox("1")
            Else
            MsgBox("2")
            End If
            End Sub

            --> this code always prints "1" in da message box.. --> what is the problem?

            J A Nasir K

            T Offline
            T Offline
            Tiyani Miyambo
            wrote on last edited by
            #5

            Try this condition if me.textbox1.text = "a" or me.textbox1.text = "A" or me.textbox1.text = "b" or me.textbox1.text = "B" Then MsgBox("2") else MsgBox("1") end sub

            C D 2 Replies Last reply
            0
            • T Tiyani Miyambo

              Try this condition if me.textbox1.text = "a" or me.textbox1.text = "A" or me.textbox1.text = "b" or me.textbox1.text = "B" Then MsgBox("2") else MsgBox("1") end sub

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              This problem was solved hours ago. It's great you want to help people, but perhaps help people who still need help ?

              Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

              1 Reply Last reply
              0
              • T Tiyani Miyambo

                Try this condition if me.textbox1.text = "a" or me.textbox1.text = "A" or me.textbox1.text = "b" or me.textbox1.text = "B" Then MsgBox("2") else MsgBox("1") end sub

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                On top of what Christian said, there are better ways of doing this than to make 4 conditions to check for 2 characters, while ignoring case.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups