Discussion:
VB6 IF OR THEN
(too old to reply)
g***@gmail.com
2014-12-27 17:03:30 UTC
Permalink
Hi All,

I am trying use operator OR but does not work. The coding below;

'---------------------------------
If Text1.Text <> "12" Or "53" Or "32" Or "63" Or "65" Then
MsgBox "Incorrect", vbCritical
Else
MsgBox "Correct", vbInformation
End If
'---------------------------------

Anyone can solve my issue. Thanks in advance

Regards,
Andre
Mayayana
2014-12-27 17:46:36 UTC
Permalink
| I am trying use operator OR but does not work. The coding below;
|
| '---------------------------------
| If Text1.Text <> "12" Or "53" Or "32" Or "63" Or "65" Then
| MsgBox "Incorrect", vbCritical
| Else
| MsgBox "Correct", vbInformation
| End If
| '---------------------------------
|
| Anyone can solve my issue. Thanks in advance
|

You have to spell it out:

If Text1.text = "12" or Text1.text = "53"....

A simpler way with so many tests is Select Case:

Select Case Text1.Text
Case "12", "32", "53", "63", "65"
Msgbox "Correct, 64
Case Else
MsgBox "Incorrect", 16
End Select

You can use as many Case elements as you like.
g***@gmail.com
2014-12-27 18:55:15 UTC
Permalink
Hi Mayayana,

whats mean 64 and 16?

Thanks
Post by Mayayana
| I am trying use operator OR but does not work. The coding below;
|
| '---------------------------------
| If Text1.Text <> "12" Or "53" Or "32" Or "63" Or "65" Then
| MsgBox "Incorrect", vbCritical
| Else
| MsgBox "Correct", vbInformation
| End If
| '---------------------------------
|
| Anyone can solve my issue. Thanks in advance
|
If Text1.text = "12" or Text1.text = "53"....
Select Case Text1.Text
Case "12", "32", "53", "63", "65"
Msgbox "Correct, 64
Case Else
MsgBox "Incorrect", 16
End Select
You can use as many Case elements as you like.
Mayayana
2014-12-27 22:00:04 UTC
Permalink
| whats mean 64 and 16?
|

I'm just in the habit of using the numbers for
msgbox. The constants you used represent
numbers. Do you know about constants? They're
basically unchangeable variables used for
convenience. People can usually remember
something like vbInformation more easily than
they remember the number 64. I started out with
VBScript, which didn't used to have preset
constants, so I learned the MsgBox constants as
numbers. You can do it either way, as long as you
either declare any constant you want to use, or
use a preset VB constant.
Deanna Earley
2015-01-02 10:03:34 UTC
Permalink
Post by g***@gmail.com
Hi All,
I am trying use operator OR but does not work. The coding below;
'---------------------------------
If Text1.Text <> "12" Or "53" Or "32" Or "63" Or "65" Then
As mentioned, each side of the Or needs to be a full valid expression,
but even if you expanded that statement, it wouldn't work as expected.

If Text1.Text <> "12" Or Text1.Text <> "53" Or Text1.Text <> "32" Or
Text1.Text <> "63" Or Text1.Text <> "65" Then

If you pass in 32, the expression will be:

If True Or True Or False Or True Or True Then

Which still evaluates to True.
You would need to invert the check to:

If Text1.Text <> "12" And Text1.Text <> "53" And Text1.Text <> "32" And
Text1.Text <> "63" And Text1.Text <> "65" Then

Or:

If Not (Text1.Text = "12" Or Text1.Text = "53" Or Text1.Text = "32" Or
Text1.Text = "63" Or Text1.Text = "65") Then

(Or remove the Not and swap the contents of the conditional blocks)

For further details, look up boolean algabra.
--
Deanna Earley (***@earlsoft.co.uk, ***@doesnotcompute.co.uk)

(Replies direct to my email address will be printed, shredded then fed
to the rats. Please reply to the group.)
Loading...