Reducing Code

  • Thread starter Thread starter G
  • Start date Start date
G

G

I want to code an IF statement with efficient code, but don't know the syntax
for VB 6.5:

If Not (field) = [62, 56, 58, 38, 61, 60, 40, 66, 64, 53] Then Z

This doesn't work, can anyone give me the correct syntax? Thanks.

G
 
On Tue, 20 Jan 2009 05:38:01 -0800, G <[email protected]>
wrote:

Write a central function to handle this. Something like:
dim aryNotAllowed as Variant
aryNotAllowed = array(62, 56, 58, 38, 61, 60, 40, 66, 64, 53)
if not InArray(field, aryNotAllowed) then Msgbox "Good, you entered an
allowed number"

function InArray(byval intValue as Integer, ary as variant) as boolean
dim a as variant
dim blnFound as boolean
for each a in ary
if a = intValue then
blnFound = True
exit for
end if
next
InArray = blnFound
end function
 
hi Tom,
Write a central function to handle this. Something like:
dim aryNotAllowed as Variant
aryNotAllowed = array(62, 56, 58, 38, 61, 60, 40, 66, 64, 53)
if not InArray(field, aryNotAllowed) then Msgbox "Good, you entered an
allowed number"
I would consider using a ParamArray:

Public Function ValueInArray( _
AValue As Variant, _
ParamArray AArray() As Variant _
) As Boolean

On Local Error Resume Next

Dim Index As Long
Dim Result As Boolean

Result = False
For Index = 0 To UBound(AArray())
Result = (AValue = AArray(Index))
If Result Then
Exit For
End If
Next Index

ValueInArray = Result

End Function

And

If Not ValueInArray(field, 62, 56, 58, 38, 61, 60, 40) Then Msgbox


mfG
--> stefan <--
 
Back
Top