Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #2209 > unrolled thread

VB6 IF OR THEN

Started bygeomodelers@gmail.com
First post2014-12-27 09:03 -0800
Last post2015-01-02 10:03 +0000
Articles 5 — 3 participants

Back to article view | Back to comp.lang.basic.visual.misc


Contents

  VB6 IF OR THEN geomodelers@gmail.com - 2014-12-27 09:03 -0800
    Re: VB6 IF OR THEN "Mayayana" <mayayana@invalid.nospam> - 2014-12-27 12:46 -0500
      Re: VB6 IF OR THEN geomodelers@gmail.com - 2014-12-27 10:55 -0800
        Re: VB6 IF OR THEN "Mayayana" <mayayana@invalid.nospam> - 2014-12-27 17:00 -0500
    Re: VB6 IF OR THEN Deanna Earley <dee@earlsoft.co.uk> - 2015-01-02 10:03 +0000

#2209 — VB6 IF OR THEN

Fromgeomodelers@gmail.com
Date2014-12-27 09:03 -0800
SubjectVB6 IF OR THEN
Message-ID<01a069ac-0e7d-4808-adb8-a548c348c89a@googlegroups.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
  MsgBox "Incorrect", vbCritical
Else
  MsgBox "Correct", vbInformation
End If
'---------------------------------

Anyone can solve my issue. Thanks in advance

Regards,
Andre

[toc] | [next] | [standalone]


#2210

From"Mayayana" <mayayana@invalid.nospam>
Date2014-12-27 12:46 -0500
Message-ID<m7mr8q$9ki$1@dont-email.me>
In reply to#2209
| 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. 

[toc] | [prev] | [next] | [standalone]


#2211

Fromgeomodelers@gmail.com
Date2014-12-27 10:55 -0800
Message-ID<cb101b69-5c7b-4057-ae50-e4520917ae01@googlegroups.com>
In reply to#2210
Hi Mayayana,

whats mean 64 and 16?

Thanks


On Sunday, December 28, 2014 12:46:28 AM UTC+7, Mayayana wrote:
> | 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.

[toc] | [prev] | [next] | [standalone]


#2213

From"Mayayana" <mayayana@invalid.nospam>
Date2014-12-27 17:00 -0500
Message-ID<m7na41$1bc$1@dont-email.me>
In reply to#2211
| 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.

[toc] | [prev] | [next] | [standalone]


#2218

FromDeanna Earley <dee@earlsoft.co.uk>
Date2015-01-02 10:03 +0000
Message-ID<m85qh3$ckd$1@speranza.aioe.org>
In reply to#2209
On 27/12/2014 17:03, geomodelers@gmail.com wrote:
> 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 (dee@earlsoft.co.uk, dee@doesnotcompute.co.uk)

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.basic.visual.misc


csiph-web