annoying one

1. Gaz
Senior Member
Join Date
Dec 1969
Posts
173

## annoying one

Hi<BR><BR>i am trying to test to see whether or not a value in my array is either a character or the number 0 like this<BR><BR>If (Not IsNumeric(productQuantity(y)) or productQuantity(y) = 0) Then<BR><BR>if the value is &#039;0&#039; then it&#039;s fine however should the value be &#039;aaa&#039; the I get the error:-<BR><BR>Type mismatch: &#039;productQuantity(...)&#039;<BR><BR>any ideas?<BR><BR>cheers

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## VBS can't do short cut operators

You get the error because *both* of the tests in the OR condition are *ALWAYS* executed. So, of course, <BR> "aaa" = 0<BR>gives a mismatch because "aaa" can&#039;t be converted to a number.<BR><BR>Best way around this particular case:<BR><BR>&#060;%<BR>...<BR>py = productQuantity(y) &#039; so you don&#039;t have to get array element twice<BR><BR>If IsNumeric(py) Then<BR> If py &#060;&#062; 0 Then<BR> ... handle the non-zero number case ...<BR> Else<BR> py = "NO"<BR> End If<BR>End If<BR>If Not IsNumeric(py) Then<BR> ... zero or non-numeric ...<BR>End If<BR>...<BR>%&#062;<BR>*****************<BR><BR>T hat used the temp py variable as its own flag. You could use a separate flag:<BR><BR>&#060;%<BR>nogood = true;<BR>py = productQuantity(y)<BR>If IsNumeric(py) Then If py &#060;&#062; 0 Then nogood = false;<BR><BR>If nogood Then<BR> ...<BR>End If<BR>%&#062;<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•