If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Compile Error: Block IF without END IF

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 02-01-13, 01:20
Rahul Bardia Rahul Bardia is offline
Registered User
 
Join Date: Feb 2013
Posts: 1
Red face Same error even i am getting for the following program. Pls help me out.

Function salary(quantity)

If quantity <= 25 Then
salary = 5000 + quantity * 0.25
Else
If quantity <= 50 Then
salary = 10000 + quantity * 0.3
Else
salary = 15000 + total_quantity * 0.4

End If
End Function

I am getting the error as "COMPILE ERROR - BLOCKIF WITHOUT ENDIF"
PLS solve this prob, as i need to complete my project in 2 days.
Reply With Quote
  #17 (permalink)  
Old 02-01-13, 08:12
mcwsky09 mcwsky09 is offline
Registered User
 
Join Date: Aug 2011
Posts: 3
Missing an End If

Code:
Function salary(quantity)

If quantity <= 25 Then
    salary = 5000 + quantity * 0.25
    Else
        If quantity <= 50 Then
            salary = 10000 + quantity * 0.3
            Else
                salary = 15000 + total_quantity * 0.4
        End If
End If

End Function
Reply With Quote
  #18 (permalink)  
Old 02-20-13, 15:32
Cbc-database Cbc-database is offline
Registered User
 
Join Date: Feb 2013
Posts: 2
missing an 'end if' but can't seem to find it

I have a similar problem. I'm receiving a compile error but can't seem to find the missing 'end if'. Could anyone help me find the error in this code. Sorry for the length.

Sub add_app()
'Renaming for coding purposes
Dim historyWks As Worksheet
Dim inputWks As Worksheet

Dim nextrow As Long
Dim oCol As Long
Dim transaction_info As Range
Dim lRsp As Long
Dim mycopy As Range
Dim IRsp2 As Long
Dim mytest As Range

Set inputWks = Worksheets("sheet1")
Set historyWks = Worksheets("all-rdr")
oCol = 1 'order info is pasted on data sheet, starting in this column

'check for duplicate when sending and receiving match
If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then
lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo, "Duplicate ID")
If lRsp = vbYes Then
UpdateLogRecord
Else
MsgBox "Please change APN number"
End If
'check for duplicate sending
If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = False Then
lRsp = MsgBox("You are about to update existing sending site data. Would you like to continue?", vbQuestion + vbYesNo, "Duplicate ID")
If lRsp = vbYes Then
IRsp2 = MsgBox("Will this utilize all remaining rights from the sending site?", vbQuestion + vbYesNo)
If IRsp2 = vbYes Then
UpdateLogRecord
Else
add_app
End If

Else

'cells to copy from Input sheet - some contain formulas
Set mycopy = inputWks.Range("transaction_info")

With historyWks
nextrow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With

With inputWks
'mandatory fields are tested in hidden column
Set mytest = mycopy.Offset(0, 1)

If Application.Count(mytest) > 0 Then
MsgBox "Please fill in all the cells!"
Exit Sub
End If
End With

With historyWks
'enter date and time stamp in record
With .Cells(nextrow, "Q")
.Value = Now
.NumberFormat = "mm/dd/yyyy, hh:mm"
End With
'enter user name in column B
.Cells(nextrow, "R").Value = Application.UserName

'copy the order data and paste onto data sheet
transaction_info.Copy
.Cells(nextrow, "A").PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.CutCopyMode = False
End With

'clear input cells that contain constants
ClearDataEntry
End If

End Sub
Reply With Quote
  #19 (permalink)  
Old 02-20-13, 15:43
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 10,496
can you repost the code inside [ c o d e ] & [ / c o d e ] blocks (without the spaces)
can you make certain the code is indented, especially if / then statements, with/end withg and so on

eg:-
Code:
'check for duplicate when sending and receiving match
If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then
  lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo,   "Duplicate ID")
endif
If lRsp = vbYes Then
  UpdateLogRecord
Else
  MsgBox "Please change APN number"
End If
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #20 (permalink)  
Old 02-20-13, 15:48
Cbc-database Cbc-database is offline
Registered User
 
Join Date: Feb 2013
Posts: 2
sure can. I'm a first time board user so I hope this posts right...

Code:
Sub add_app()
'Renaming for coding purposes
    Dim historyWks As Worksheet
    Dim inputWks As Worksheet

    Dim nextrow As Long
    Dim oCol As Long
    Dim transaction_info As Range
    Dim lRsp As Long
    Dim mycopy As Range
    Dim IRsp2 As Long
    Dim mytest As Range

    Set inputWks = Worksheets("sheet1")
    Set historyWks = Worksheets("all-rdr")
    oCol = 1 'order info is pasted on data sheet, starting in this column
    
    'check for duplicate when sending and receiving match
    If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then
      lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo, "Duplicate ID")
      If lRsp = vbYes Then
        UpdateLogRecord
      Else
        MsgBox "Please change APN number"
      End If
       'check for duplicate sending
    If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = False Then
      lRsp = MsgBox("You are about to update existing sending site data. Would you like to continue?", vbQuestion + vbYesNo, "Duplicate ID")
      If lRsp = vbYes Then
      IRsp2 = MsgBox("Will this utilize all remaining rights from the sending site?", vbQuestion + vbYesNo)
      If IRsp2 = vbYes Then
        UpdateLogRecord
      Else
       add_app
      End If
      
    Else

      'cells to copy from Input sheet - some contain formulas
      Set mycopy = inputWks.Range("transaction_info")
      
      With historyWks
          nextrow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
      End With
   
   With inputWks
          'mandatory fields are tested in hidden column
          Set mytest = mycopy.Offset(0, 1)
  
          If Application.Count(mytest) > 0 Then
              MsgBox "Please fill in all the cells!"
              Exit Sub
          End If
      End With
      
      With historyWks
          'enter date and time stamp in record
          With .Cells(nextrow, "Q")
              .Value = Now
              .NumberFormat = "mm/dd/yyyy, hh:mm"
          End With
          'enter user name in column B
          .Cells(nextrow, "R").Value = Application.UserName
          
          'copy the order data and paste onto data sheet
            transaction_info.Copy
          .Cells(nextrow, "A").PasteSpecial Paste:=xlPasteValues, Transpose:=True
          Application.CutCopyMode = False
      End With
      
      'clear input cells that contain constants
      ClearDataEntry
    End If
  
End Sub
Reply With Quote
  #21 (permalink)  
Old 02-20-13, 17:32
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 10,496
so having indented the code are there any obvious if then blocks that aren't terminated by an endif?

bear in mind that VB does allow
Code:
if (condition) then statement
as a valid statement without an endif. but I'd strongly reccommned that you never EVER use that style as it can make tracing erros liek this harder


if you are still struggling then a technique that I have seen work is to comment the endif or else statements

eg
Code:
    If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then
      lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo, "Duplicate ID")
      If lRsp = vbYes Then
        UpdateLogRecord
      Else 'lRsp wasn't so tell the t(*&)(*t to change the APn number
        MsgBox "Please change APN number"
      End If 'finished checking the user response
    [red]End if[/red]
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #22 (permalink)  
Old 02-23-13, 16:00
mcwsky09 mcwsky09 is offline
Registered User
 
Join Date: Aug 2011
Posts: 3
not sure if you got your question answered but..

Quote:
Originally Posted by Cbc-database View Post
I have a similar problem. I'm receiving a compile error but can't seem to find the missing 'end if'. Could anyone help me find the error in this code. Sorry for the length.
Looks to me as if you are missing two END IF statements - generally when building an IF Then Else End IF structure I will enter all those lines first then go put the code in between - it also helps to indent code so that you can see how things are nested. Comments can also be helpful.

in the snippet below you may have to scroll over to the right to see where I added tags for each If and End IF statement.
Code:
Sub add_app()
'Renaming for coding purposes
    Dim historyWks As Worksheet
    Dim inputWks As Worksheet

    Dim nextrow As Long
    Dim oCol As Long
    Dim transaction_info As Range
    Dim lRsp As Long
    Dim mycopy As Range
    Dim IRsp2 As Long
    Dim mytest As Range

    Set inputWks = Worksheets("sheet1")
    Set historyWks = Worksheets("all-rdr")
    oCol = 1 'order info is pasted on data sheet, starting in this column
    
    'check for duplicate when sending and receiving match
    If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then                               ' IF A
      lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo, "Duplicate ID")
      If lRsp = vbYes Then                                                                                                                                              ' IF B
        UpdateLogRecord
      Else
        MsgBox "Please change APN number"
      End If                                                                                                                                                                     ' END IF B
       'check for duplicate sending
    
    
    ' should END IF A be here? or at the very end ?
    
    
    If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = False Then                                 ' IF C
      lRsp = MsgBox("You are about to update existing sending site data. Would you like to continue?", vbQuestion + vbYesNo, "Duplicate ID")
      If lRsp = vbYes Then                                                                                                                                       ' IF D
      IRsp2 = MsgBox("Will this utilize all remaining rights from the sending site?", vbQuestion + vbYesNo)
        If IRsp2 = vbYes Then                                                                                                                                         ' IF E
          UpdateLogRecord
        Else
         add_app
        End If                                                                                                                                                                  ' END IF E
      
    Else

      'cells to copy from Input sheet - some contain formulas
      Set mycopy = inputWks.Range("transaction_info")
      
      With historyWks
          nextrow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
      End With
  
  
  ' should END IF C or END IF D be here?
  
  
   With inputWks
          'mandatory fields are tested in hidden column
          Set mytest = mycopy.Offset(0, 1)
  
          If Application.Count(mytest) > 0 Then                                                                                                             ' IF F
              MsgBox "Please fill in all the cells!"
              Exit Sub
          End If                                                                                                                                                                ' END IF F
      End With
      
      With historyWks
          'enter date and time stamp in record
          With .Cells(nextrow, "Q")
              .Value = Now
              .NumberFormat = "mm/dd/yyyy, hh:mm"
          End With
          'enter user name in column B
          .Cells(nextrow, "R").Value = Application.UserName
          
          'copy the order data and paste onto data sheet
            transaction_info.Copy
          .Cells(nextrow, "A").PasteSpecial Paste:=xlPasteValues, Transpose:=True
          Application.CutCopyMode = False
      End With
      
      'clear input cells that contain constants
      ClearDataEntry
    End If                                                                                                                                                                  ' END IF ??? A ???
  
End Sub
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On