Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If And Statement not working

Status
Not open for further replies.

SgtPepps

IS-IT--Management
May 1, 2002
109
GB
I have a very dull If And Statement that doesn't work, It Is:

If MyArray(1) = False And MyArray(2) = False And MyArray(3) = False And MyArray(4) = False And MyArray(5) = False And MyArray(6) = False And MyArray(7) = False And MyArray(8) = False And MyArray(9) = False And MyArray(10) = False And MyArray(11) = False And MyArray(12) = False And MyArray(13) = False And MyArray(14) = False And MyArray(15) = False And MyArray(16) = False And MyArray(17) = False And MyArray(18) = False And MyArray(19) = False And MyArray(20) = False And MyArray(21) = False And MyArray(22) = False And MyArray(23) = False And MyArray(24) = False And MyArray(25) = False And MyArray(26) = False And TArray(1) < 1 And TArray(2) < 1 And TArray(3) < 1 Then

I've gone through each of them 1 by 1 and they are all false or less than 1 but It still doesn't work, Is there a limit to how many If Ands you can have?? some help would be great!

Regards

SgtPepps
 
Hey Sarg,

Here's what i would suggest -- use a for..next loop. If Not True then bale out...
Code:
bFail = False
For i = 1 to UBound(MyArray, 1)
   If MyArray(i) Then
      bFail = True
      Exit For
   End If
   If i <= Ubound(TArray, 1) Then
      If TArray(i) >= 1 Then
         bFail = True
         Exit For
      End If
   End If
Next
If bFail Then

Else

End If
Hope this helps ;-) Skip,
 
Thanks for the help Skip but I don't really understand It, I tried to use It but I didn't get anywhere.

Regards

Sgtpepps
 
Sarg - it's just a loop thru the array, doing a check on each element. Set up the array and then have this after instead of your massive If statement. I don't know what limit there is on ands in if conditions but I'm sure there is one and I reckon you've probably gone past it. Skip's code should work
Rgds
Geoff
 
Hi Sgtpepps!

What App are you using and where does the information in the array come from. There may be easier solutions to what you are trying to do.

Jeff Bridgham
bridgham@purdue.edu
 
I ended up splitting the If And statement into 4 seperate If Ands, for each of them I had a boolean variable that was true If all of the If Ands were true, then I Queried those boolean variables In a much smaller statement. Cheers for the help though! I just had a problem getting my head around the logic of skips Loop.

Regards

Sgt Pepps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top