Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007
    Posts
    2

    Unanswered: End if without block if - the dreaded error!

    The code below when run gives the End If without Block If error for the very last End If. I cannot see why. All if statements are block ifs and all have end if statements associated with them. Any help will be appreciated. BTW I am relatively new to using Visual Basic.

    Code basically looks for the word PROCESSOR within a line in a file and then extracts the word after PROCESSOR.
    Regards. Martin.

    Code:
    Private Sub LoadFile(strFilename)
      Dim strInputLine As String
      Dim intREMpoint As Integer
      Dim intINCpoint As Integer
      Dim intTemp As Integer
      Dim intChar As Integer
      Dim blnINCfilefound As Boolean
      Dim strINC_filename As String
      Dim strTemp As String
      
      blnINCfilefound = False
     
      Open strFilename For Input As #1
      
      frmOutput_Window.Show
      
      Do Until (EOF(1) = True)
        Line Input #1, strInputLine
        
        'record where a REM occurs if at all
        intREMpoint = InStr(strInputLine, ";")
        
        'Find include file(s)
        intINCpoint = InStr(UCase(strInputLine), ".INC")
    
        If (intREMpoint > intINCpoint And intINCpoint <> 0) Or (intREMpoint = 0 And intINCpoint <> 0) Then
           blnINCfilefound = True
           strINC_filename = strInputLine
        End If
        
        'Find which processor is specified.
        If (InStr(UCase(strInputLine), "PROCESSOR") <> 0 And InStr(UCase(strInputLine), "PROCESSOR") < intREMpoint) Then
        
           intTemp = InStr(UCase(strInputLine), "PROCESSOR") + 10
           'strip spaces from left end of string after "PROCESSOR"
           strTemp = LTrim(Mid(strInputLine, intTemp))
           
            'Find 1st space in new row and strip characters and spaces after it
           intTemp = 0
           Do
              intTemp = intTemp + 1
              intChar = Asc(Mid(strTemp, intTemp))
           While (intChar < 48 Or intChar > 57) And (intChar < 65 Or intChar > 90) And (intChar < 97 Or intChar > 122)
           'should exit either on 1st non alpha numeric or CRLF
                
           If InStr(strTemp, " ") <> 0 Then
             intTemp = Len(strTemp) - InStr(strTemp, " ")
           Else
             If InStr(strTemp, Chr$(9) <> 0) Then
               intTemp = Len(strTemp) - InStr(strTemp, Chr$(9))
             Else
               intTemp = 0
             End If
           End If
           
           strTemp = Mid(strTemp, 1, intTemp)
    
        End If
    
      Loop
      frmOutput_Window.Print "Include path & file = ", strINC_filename
        
    End Sub

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    The problem lies in your DO loop.

    A do loop has two variants. The Do-While loop, where the while keyword is on the same line as the Do keyword, or the Do-Until, where the Until keyword lies on the same line as the Loop keyword.

    In other words, it should be EITHER

    Code:
    Do While [a condition]
      ' statements within the loop
    Loop
    
    'or
    
    Do
      ' statements within the loop
    Loop Until [a Condition]
    The two variants are similar, but the first approach tests at the start of the loop, whereas the second variant tests at the END of the loop. In the second instance, the code within the loop is guaranteed to run at least once.

    Ref a PDF output file from PrettyCode.Print, of your source...
    Attached Files Attached Files
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Nov 2007
    Posts
    2

    Smile

    Loquin,

    Thanks for your reply. It certainly put me onto the problem.

    BTW the text I am using suggests there are four or more do loop variants:

    Do while {condition}
    {code}
    Loop

    Do
    {code}
    Loop until {condition}

    Do
    {code}
    Loop while {condition}

    Do until {condition}
    {code}
    Loop

    but not as I had
    Do
    {code}
    Until {condition}

    Many thanks. My hair is beginning to grow back again.
    Martin

Posting Permissions

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