Results 1 to 6 of 6

Thread: [RESOLVED] Help with loop!!!

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    38

    Resolved [RESOLVED] Help with loop!!!

    Hi

    I have written a loop-code but I get this message "Loop without Do". Now I have checked the code and i cant find whats wrong with it. Theres only one loop in the code so I cant see why the program doesnt recognise the first "Do" statement.

    This is the code (somewhat shortened though)

    VB Code:
    1. For i = 1 To iEnd
    2.    
    3.         bordervalue = 0.001
    4.        
    5.         bX1temp = ws.Cells(i, "a").Value
    6.         bX2temp = ws.Cells(i, "d").Value
    7.         bY1temp = ws.Cells(i, "b").Value
    8.         bY2temp = ws.Cells(i, "e").Value
    9.  
    10.         Do
    11.    
    12.             bEnough = True
    13.            
    14.             bXMtemp = (bX1temp + bX2temp) / 2
    15.             bYMtemp = (bY1temp + bY2temp) / 2
    16.            
    17.  
    18.             If bXMtemp < dXMin Then
    19.                 If 0 > Me.txtP1X.Value > bXMtemp Then
    20.                     bP1xxM = dP1 * (bXMtemp - Me.txtP1X.Value)
    21.                 End If
    22.                 If 0 > Me.txtP2X.Value > bXMtemp Then
    23.                     bP2xxM = dP2 * (bXMtemp - Me.txtP2X.Value)
    24.                 End If
    25.                 If 0 > Me.txtP3X.Value > bXMtemp Then
    26.                     bP3xxM = dP3 * (bXMtemp - Me.txtP3X.Value)
    27.                 End If
    28.                 If 0 > Me.txtP4X.Value > bXMtemp Then
    29.                     bP4xxM = dP4 * (bXMtemp - Me.txtP4X.Value)
    30.                 End If
    31.                 If 0 > Me.txtP5X.Value > bXMtemp Then
    32.                     bP5xxM = dP5 * (bXMtemp - Me.txtP5X.Value)
    33.                 End If
    34.                 If 0 > Me.txtP6X.Value > bXMtemp Then
    35.                     bP6xxM = dP6 * (bXMtemp - Me.txtP6X.Value)
    36.                 End If
    37.             End If
    38.                        
    39.          [B] [CUT OUT CODE]....[/B]        
    40.            
    41.             bPxxSum = bP1xxM + bP2xxM + bP3xxM + bP4xxM + bP5xxM + bP6xxM
    42.            
    43.             dY = 1 / dH * (dRa * bXMtemp - bPxxSum) + dYStrt
    44.             dX = bXMtemp
    45.            
    46.             If Not bYMtemp - dY < bordervalue Then
    47.                 bEnough = False
    48.                 If dY < bYMtemp Then
    49.                     bX2temp = bXMtemp
    50.                     bY2temp = bYMtemp
    51.                 End If
    52.                 If dY > bYMtemp Then
    53.                     bX1temp = bXMtemp
    54.                     bY1temp = bYMtemp
    55.                 End If
    56.             End If
    57.            
    58.         Loop While Not bEnough
    59.            
    60.         ws.Cells(i, "G").Value = dX
    61.         ws.Cells(i, "H").Value = dY
    62.        
    63.     Next i

    Does anyone have any idea to whats wrong?

    Could it be that the loopcode is to long? are there any restrictions to that?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help with loop!!!

    the error message does not mean what it say exactly, i can't see the error in the code you posted, but it may be in the section you cut

    it can be caused by and with without endwith, for without next, if without end if or do without loop, and even probaly some other code error

    pete

  3. #3
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Help with loop!!!

    I would suggest that you carefully check your code for missing End If/End With/End Select, etc.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    38

    Re: Help with loop!!!

    Thanks guys, You were right.

    There was a "End If" missing, didn't see that first though I checked the whole code, there was so much code so I missed that and besides I didnt think that message would come up with a "End if" missing...

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    38

    Re: [RESOLVED] Help with loop!!!

    one more question though...

    I fixed the loop, but now I wonder about the If statements above... does this
    VB Code:
    1. If 0 > Me.txtP4X.Value > bXMtemp Then
    mean the same thing as
    VB Code:
    1. If 0 > Me.txtP4X.Value And Me.txtP4X.Value  > bXMtemp Then

    ???

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] Help with loop!!!

    not the same

    pete

    edit: add code sample
    VB Code:
    1. Dim o As Integer, i As Integer, j As Integer
    2.    
    3.     o = 20
    4.     i = 6
    5.     j = 8
    6.     If o > j And j > i Then Stop
    7.     If o > j > i Then Stop
    8.     Stop

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