if statement....
-
--> 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
-
--> 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
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
-
--> 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
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 SubUse 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
-
--> 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
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.
-
--> 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
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
-
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
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 )
-
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
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