I am trying to calculate something in Excel VBA using a class definion. The main goal is to calculate in an class within the sub Calc1 a simple ratio. When executing the module I receive the following error:
function or variable expected
in the line of the module
MsgBox myCalc1.Calc1
The code is below
Class is defined as the following:
' These are properties
Public dat_date1 As Date
Public dat_date2 As Date
Public str_Option As String
Dim ratio As Double
Dim nominator As Double
Dim denominator As Double
' These are methods
Sub Calc1()
' Code for day count conventions
If str_Option= "o1" Then
nominator = (dat_date2-dat_date1)
denominator = 2
ElseIf str_Option = "o2" Then
nominator = (dat_date2-dat_date1)
denominator = 3
Else
MsgBox "No function defined"
End If
ratio = nominator / denominator
End Sub
My module is defined as the following:
Sub ModuleCalc()
Dim myCalc1 As clsCalc
Set myCalc1 = New clsCalc
With myCalc1
.dat_date1 = "01/02/2015"
.dat_date2 = "28/02/2015"
.str_Option= "o1"
End With
MsgBox myCalc1.Calc1
End Sub
Calc1returns nothing to theMsgBoxcall is not valid.