Results 1 to 3 of 3

Thread: [RESOLVED] While Loop Problem

  1. #1

    Thread Starter
    Member Mythrandil's Avatar
    Join Date
    Mar 2006
    Posts
    55

    Resolved [RESOLVED] While Loop Problem

    I have a pretty simple while loop:

    VB Code:
    1. While (UBound(LUpper) > 1) And (Cross_product(LUpper(UBound(LUpper) - 2), LUpper(UBound(LUpper) - 1), LUpper(UBound(LUpper))) >= 0)
    2.      Delete_Element LUpper, UBound(LUpper) - 1
    3. Wend

    Problem is if a situation arises where Ubound(LUpper) = 1. Rather than moving on as the first paramater of the while loop fails, vb still tries to evaluate the parameters of cross_product function, and in the case of Ubound(LUpper) = 1 the first parameter is subscript out of range.

    Is there a way to stop vb evaluating parameters despite the fact their state isn't relevant, or is there another way around forming a while loop to acheive my goal?

    Im quite stressed atm so sorry if the solution is obvious, not thinking str8

    thanks in advance!

  2. #2
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Lightbulb Re: While Loop Problem

    Since there's no short-circut evaluation in VB, you might just have to have two exit points from the loop. Something like:
    VB Code:
    1. Do While (UBound(LUpper) > 1)
    2.   If (Cross_product(LUpper(UBound(LUpper) - 2), LUpper(UBound(LUpper) - 1), LUpper(UBound(LUpper))) >= 0) Then
    3.     Exit Do
    4.   End If
    5.  
    6.    Delete_Element LUpper, UBound(LUpper) - 1
    7. Loop

  3. #3

    Thread Starter
    Member Mythrandil's Avatar
    Join Date
    Mar 2006
    Posts
    55

    Re: While Loop Problem

    Ah thats a alternative solution, many thanks!

Posting Permissions

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



Click Here to Expand Forum to Full Width