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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error: Block If without End If 3

Status
Not open for further replies.

RP1America

Technical User
Aug 17, 2009
221
US
While using the Compile Project option, I ran into the error: "Compile Error: Block If without End If" with the "End Sub" highlighted.

Any ideas as to why this may be occuring? I cannot figure it out. All other debugging within this procedure has been accounted for.

Thanks!!


Code:
Private Sub beneinfcont_click()

    Dim strperiod As String
    If period = "1" Then strperiod = "One"
    If period = "2" Then strperiod = "Two"
    If period = "3" Then strperiod = "Three"
    If period = "4" Then strperiod = "Four"
    If period = "5" Then strperiod = "Five"
    If period = "6" Then strperiod = "Six"
    If period = "7" Then strperiod = "Seven"
    If period = "8" Then strperiod = "Eight"
    If period = "9" Then strperiod = "Nine"
    If period = "10" Then strperiod = "Ten"
    If period = "11" Then strperiod = "Eleven"
    If period = "12" Then strperiod = "Twelve"
    If period = "13" Then strperiod = "Thirteen"
    If period = "14" Then strperiod = "Fourteen"
    If period = "15" Then strperiod = "Fifteen"
    If period = "16" Then strperiod = "Sixteen"
    If period = "17" Then strperiod = "Seventeen"
    If period = "18" Then strperiod = "Eighteen"
    If period = "19" Then strperiod = "Nineteen"
    If period = "20" Then strperiod = "Twenty"
    If period = "21" Then strperiod = "Twenty-One"
    If period = "22" Then strperiod = "Twenty-Two"
    If period = "23" Then strperiod = "Twenty-Three"
    If period = "24" Then strperiod = "Twenty-Four"
    If period = "25" Then strperiod = "Twenty-Five"
    If period = "26" Then strperiod = "Twenty-Six"
    If period = "27" Then strperiod = "Twenty-Seven"
    If period = "28" Then strperiod = "Twenty-Eight"
    If period = "29" Then strperiod = "Twenty-Nine"
    If period = "30" Then strperiod = "Thirty"
    If period = "31" Then strperiod = "Thirty-One"
    If period = "32" Then strperiod = "Thirty-Two"
    If period = "33" Then strperiod = "Thirty-Three"
    If period = "34" Then strperiod = "Thirty-Four"
    If period = "35" Then strperiod = "Thirty-Five"
    If period = "36" Then strperiod = "Thirty-Six"
    If period = "37" Then strperiod = "Thirty-Seven"
    If period = "38" Then strperiod = "Thirty-Eight"
    If period = "39" Then strperiod = "Thirty-Nine"
    If period = "40" Then strperiod = "Fourty"
    If period = "41" Then strperiod = "Fourty-One"
    If period = "42" Then strperiod = "Fourty-Two"
    If period = "43" Then strperiod = "Fourty-Three"
    If period = "44" Then strperiod = "Fourty-Four"
    If period = "45" Then strperiod = "Fourty-Five"
    If period = "46" Then strperiod = "Fourty-Six"
    If period = "47" Then strperiod = "Fourty-Seven"
    If period = "48" Then strperiod = "Fourty-Eight"
    If period = "49" Then strperiod = "Fourty-Nine"
    If period = "50" Then strperiod = "Fifty"
    If period >= "50" Then strperiod = period
    
    Dim strperiodmys As String
    If annuityinfo.periodmonths = True Then strperiodmys = " months"
    If annuityinfo.periodyears = True Then strperiodmys = " years"
    
    Dim strsex2 As String
    If annuitantinfo.annuitantsal.Value = "Mr." Then strsex2 = "his"
    If annuitantinfo.annuitantsal.Value = "Mrs." Then strsex2 = "her"
    If annuitantinfo.annuitantsal.Value = "Ms." Then strsex2 = "her"
    
    Dim strnumbenes As String
    If Not bene1first.Value = "" And Not bene2first.Value = "" Then strnumbenes = "beneficiaries"
    If Not bene1first.Value = "" And bene2first.Value = "" Then strnumbenes = "beneficiary"
    
    Dim strisare As String
    If Not bene1first.Value = "" And Not bene2first.Value = "" Then strisare = "are"
    If Not bene1first.Value = "" And bene2first.Value = "" Then strisare = "is"
    
    Dim stryou2 As String
    If addresseeinfo.addresseefirst.Value = bene1first.Value And addresseeinfo.addresseelast.Value = bene1last.Value Then
    stryou2 = "you, "
    If addresseeinfo.addresseefirst.Value = Not bene1first.Value And addresseeinfo.addresseelast.Value = Not bene1last.Value Then
    stryou2 = ""
    
    Dim strbenenames As String
    If ssayes = True And Not bene1first.Value = "" And Not bene2first.Value = "" And Not bene3first.Value = "" _
    And Not bene4first.Value = "" And bene5first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value + ", " + bene2first.Value + " " + bene2last.Value _
    + ", " + bene3first.Value + " " + bene3last.Value + ", " + bene4first.Value + " " + bene4last.Value + ", and " + _
    bene5first.Value + " " + bene5last.Value + " to share equally"
    If ssayes = True And Not bene1first.Value = "" And Not bene2first.Value = "" And Not bene3first.Value = "" _
    And Not bene4first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value + ", " + bene2first.Value + " " + bene2last.Value + _
    ", " + bene3first.Value + " " + bene3last.Value + ", and " + bene4first.Value + " " + bene4last.Value + " to share equally"
    If ssayes = True And Not bene1first.Value = "" And Not bene2first.Value = "" And Not bene3first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value + ", " + bene2first.Value + " " + bene2last.Value + _
    ", and " + bene3first.Value + " " + bene3last.Value + " to share equally"
    If ssayes = True And Not bene1first.Value = "" And Not bene2first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value + ", and " + bene2first.Value + " " + bene2last.Value + _
    " to share equally"
    If ssayes = True And Not bene1first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value
    If ssano = True And Not bene1first.Value = "" And Not bene2first.Value = "" And Not bene3first.Value = "" _
    And Not bene4first.Value = "" And bene5first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value + " - " + bene1per.Value + ", " + bene2first.Value + _
    " " + bene2last.Value + " - " + bene2per.Value + ", " + bene3first.Value + " " + bene3last.Value + " - " + bene3per.Value + _
    ", " + bene4first.Value + " " + bene4last.Value + " - " + bene4per.Value + ", and " + bene5first.Value + " " + _
    bene5last.Value + " - " + bene5per.Value
    If ssano = True And Not bene1first.Value = "" And Not bene2first.Value = "" And Not bene3first.Value = "" _
    And Not bene4first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value + " - " + bene1per.Value + ", " + bene2first.Value + _
    " " + bene2last.Value + " - " + bene2per.Value + ", " + bene3first.Value + " " + bene3last.Value + " - " + bene3per.Value + _
    ", and " + bene4first.Value + " " + bene4last.Value + " - " + bene4per.Value
    If ssano = True And Not bene1first.Value = "" And Not bene2first.Value = "" And Not bene3first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value + " - " + bene1per.Value + ", " + bene2first.Value + _
    " " + bene2last.Value + " - " + bene2per.Value + ", and " + bene3first.Value + " " + bene3last.Value + " - " + bene3per.Value
    If ssano = True And Not bene1first.Value = "" And Not bene2first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value + " - " + bene1per.Value + ", and " + bene2first.Value + _
    " " + bene2last.Value + " - " + bene1per.Value
    If ssano = True And Not bene1first.Value = "" Then
    strbenenames = stryou2 + bene1first.Value + " " + bene1last.Value
    
    Dim strnumregpyts As String
    If annuityinfo.annoption = "Fixed Amount" And annuityinfo.benefityes = True Then
    strnumregpyts = (annuityinfo.numpytsduebene.Value - 1)
    If annuityinfo.annoption = "Installment Refund" And annuityinfo.benefityes = True Then
    strnumregpyts = (annuityinfo.numpytsduebene.Value - 1)
    
    Dim strjscalcpercent As String
    If annuityinfo.jspercent = "50%" Then strjscalcpercent = Format$(annuityinfo.gross * 0.5, "$#,##0.00")
    If annuityinfo.jspercent = "66%" Then strjscalcpercent = Format$(annuityinfo.gross * 0.666, "$#,##0.00")
    If annuityinfo.jspercent = "75%" Then strjscalcpercent = Format$(annuityinfo.gross * 0.75, "$#,##0.00")
    If annuityinfo.jspercent = "100%" Then strjscalcpercent = Format$(annuityinfo.gross * 1, "$#,##0.00")

    With ActiveDocument
    
'   Benefits Due (No Contingent Benefits Available Per Annuity Type)
        If annuityinfo.annoption.Value = "Fixed Period" And annuityinfo.benefityes = True Then
        .Bookmarks("annoptionspecs").Range.Text = LCase(strperiod) + strperiodmys + ".  There are " + _
        annuityinfo.numpytsduebene.Value + " payments left on this annuity to be paid to " + strsex2 + " " + strnumbenes + _
        ", who " + strisare + " " + strbenenames + "."
        ElseIf annuityinfo.annoption.Value = "Fixed Amount" And annuityinfo.benefityes = True Then
        .Bookmarks("annoptionspecs").Range.Text = annuityinfo.instrefnumpyts + " payments and a final payment of " + _
        annuityinfo.instreffinal + ".  There are " + strnumregpyts + " payments of " + annuityinfo.gross + _
        " and a final payment of " + annuityinfo.instreffinal + " left on this annuity to be paid to " + strsex2 + " " + _
        strnumbenes + ", who " + strisare + " " + strbenenames + "."
        ElseIf annuityinfo.annoption.Value = "Certain and Life" And annuityinfo.benefityes = True Then
        .Bookmarks("annoptionspecs").Range.Text = LCase(strperiod) + strperiodmys + " and life thereafter.  There are " + _
        annuityinfo.numpytsduebene.Value + " payments left on this annuity to be paid to " + strsex2 + " " + strnumbenes + _
        ", who " + strisare + " " + strbenenames + "."
        ElseIf annuityinfo.annoption.Value = "Installment Refund" And annuityinfo.benefityes = True Then
        .Bookmarks("annoptionspecs").Range.Text = annuityinfo.instrefnumpyts + " installments and a final payment of " + _
        annuityinfo.instreffinal + " and for life thereafter.  There are " + strnumregpyts + " installments of " + _
        annuityinfo.gross + " and a final payment of " + annuityinfo.instreffinal + " left on this annuity to be paid to " + _
        strsex2 + " " + strnumbenes + ", who " + strisare + " " + strbenenames + "."
        End If
        
'   Benefits Due (To Contingent)
        If annuityinfo.annoption = "Joint and Survivor" And contingentbeneyes = True Then
        .Bookmarks("annoptionspecs").Range.Text = strsex2 + " lifetime.  Upon " + strsex2 + " death, " + stryou2 + _
        annuityinfo.contingentfirst + " " + annuityinfo.contingentlast + " will receive " + annuityinfo.jspercent + " of what " + _
        annuitantinfo.annuitantsal.Value + " " + annuitantinfo.annuitantlast.Value + " was receiving, which will be " + _
        strjscalcpercent + " " + LCase(annuityinfo.freq) + " for your lifetime."
        ElseIf annuityinfo.annoption = "Joint and Survivor with Certain and Life" And contingentbeneyes = True Then
        .Bookmarks("annoptionspecs").Range.Text = LCase(strperiod) + strperiodmys + " and for life thereafter.  Upon " + _
        strsex2 + " death, " + stryou + annuityinfo.contingentfirst + " " + annuityinfo.contingentlast + " will receive " + _
        annuityinfo.jspercent + " of what " + annuitantinfo.annuitantsal.Value + " " + annuitantinfo.annuitantlast.Value + _
        " was receiving, which will be " + strjscalcpercent + " " + LCase(annuityinfo.freq) + " for your lifetime."
        ElseIf annuityinfo.annoption = "Joint and Contingent" And contingentbeneyes = True Then
        .Bookmarks("annoptionspecs").Range.Text = strsex2 + " lifetime.  Upon " + strsex2 + " death, " + stryou2 + _
        annuityinfo.contingentfirst + " " + annuityinfo.contingentlast + " will receive " + annuityinfo.jspercent + " of what " + _
        annuitantinfo.annuitantsal.Value + " " + annuitantinfo.annuitantlast.Value + " was receiving, which will be " + _
        strjscalcpercent + " " + LCase(annuityinfo.freq) + " for your lifetime."
        End If
        
'   Benefits Due (NOT To Contingent)
        If annuityinfo.annoption = "Joint and Survivor with Certain and Life" And contingentbeneno = True Then
        .Bookmarks("annoptionspecs").Range.Text = LCase(strperiod) + strperiodmys + _
        " and for life thereafter.  Since the contingent annuitant, " + annuityinfo.contingentfirst + " " + _
        annuityinfo.contingentlast + ", is also deceased, there are " + annuityinfo.numpytsduebene + _
        " payments left on this annuity to be paid to " + strsex2 + " " + strnumbenes + ", who " + strisare + " " + _
        strbenenames + "."
        End If

    End With

Me.Hide
Load additionalinfo
additionalinfo.Show

End Sub
 
Almost there.
:)

1) Yes, you got that right: the "Zero" is a mere placeholder.
2) The ordering is important. You must first initiate the "periods" array, i.e. give it values before you can access these values, hence the line "periods=array..." must be put before the IF block:

Code:
Dim strperiod As String, periods as Variant
periods=Array("Zero", "One", "Two", "Three", "Four", ...)
If period > "50" Then
   strperiod = period
Else
   strperiod = periods((CInt)period)
End If

Strongm's IIF version is nothing but a shortened If.. Then...Else block:

If you have a construct as simple as "If this is true then one statement else one other statement", then you can summarize these 5 lines of code into one by using "IIF"

=> strperiod = IIf(period > "50", period, periods(CInt(period)))

The syntax is: IIF ([your condition goes here], ["then" part], ["else" part])

So
Code:
strperiod = IIf(period > "50", period, periods(CInt(period)))
and
Code:
If period > "50" Then
   strperiod = period
Else
   strperiod = periods((CInt)period)
End If
Are exactly the same.

:)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
I have just spotted that the bracketing of CInt in the IF..Then..Else version is wrong:

CInt means "Convert to Integer" and converts the argument into an integer number.
So instead of...

periods((CInt)period)

...it must read...

periods(CInt(period))

...just as in Strongm's IIF version.
[blush]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
>Arrays begin at 0, i.e. the first entry would be array(0).

Not necessarily. That is indeed the default for VBA when no initialisation information is provided, but can be changed with

Option Base 1

which means that default arrays will start at 1.




Of course if we are initialising arrays ourselves we can have them start anywhere we like no matter what the Option Base:

Dim Example(11 to 17) as string

would create an array of strings starting at an index value of 11. We can even do 'silly' things like using negative numbers, e,g

Dim Example(-6 to -1) as string

(which, BTW, is why I'm not always a huge fan of the UBound method of determining whether an array is empty)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top