Hi All,
I have been working on this assignment for my computer science class and cannot figure out how to fix my code when I get the error message: Variable not Defined in my User form. Here is the section of my code
Option Explicit
'************************************************* ************************************************** **********
'Melissa Nesbitt, CS 106, Fall 2011, Section 1
'Assignment 3
'************************************************* ************************************************** **********
'************************************************* ************************************************** **********
'Create an entry showing the name of Tree, Zone, Price and caluculate the Shipping and Handling
'************************************************* ************************************************** **********
Const REGULAR_SHIPPING As Double = 0.05
Const EXPRESS_SHIPPING As Double = 0.1
Const FERTILIZER As Double = 10
Const TRUNK_WRAP As Double = 4
Const PRE_PRUNING As Double = 8
'************************************************* ************************************************** **********
'Initialize values and labels when the form first loads
'************************************************* ************************************************** **********
Sub UserForm_Initialize()
Worksheets("sales").Activate
'*** initialize captions on option buttons and check boxes
optShared.Caption = "Shared " & Format(REGULAR_SHIPPING, "Percent")
optShared.Caption = "Shared " & Format(EXPRESS_SHIPPING, "Percent")
chkFertilizer.Caption = "Fertilizer" & Format(FERTILIZER, "Currency")
chkTrunkWrap .Caption = "Trunk Wrap" & Format(TRUNK_WRAP, "Currency")
chkPrePruning.Caption = "Pre-Pruning" & Format(PRE_PRUNING, "Currency")
'*** initialize list boxes since the RowSource property is not available on MAC
lstTree.List = Workshets("names").Range("Tree").Value
lstZone.List = Worksheets("names").Range("Zone").Value
End Sub
'************************************************* ************************************************** **********
'Get the data and fill out the columns
'************************************************* ************************************************** **********
Private Sub btnProcess_Click()
Dim Trees As String
Dim zone As String
Dim price As Double
Dim shippingandhandling, FERTILIZER, trunkWrap, prePruning As Double
'*** get tree name and enter in sheet
Tree = lstTree.Value
Cells(2, 1).Value = Tree
'*** get zone name and enter in sheet
zone = lstZone.Value
Cells(2, 2) = zone
'*** get price and enter in sheet
price = CDbl(txtPrice.Value)
Cells(2, 3) = Format(price, "Currency")
'*** compute shipping and handling according to type
If optSolo.Value = True Then
shippingandhandling = price * REGULAR_SHIPPING
ElseIf optShared.Value = True Then
shippingandhandling = price * EXPRESS_SHIPPING
Else 'error, no shipping chosen
MsgBox ("You must choose a shipping cost")
Exit Sub
End If
'***compute any add-ons
If chkFertilizer.Value = True Then
Total = price * shippingCost + FERTILIZER
Else
FERTILIZER = 0
ElseIf chkTrunkWrap.Value = True Then
Total = price * shippingCost + trunkWrap
Else
trunkWrap = 0
ElseIf chkPrePruning.Value = True Then
Total = price * shippingCost + prePruning
Else
prePruning = 0
End If
'*** finish up
Cells.Columns.AutoFit 'adjust column width to fit entries
End Sub
About a quarter of the way down, optShared.Caption is what is highlighted as not defined. Can anyone help?