silentwraith
New Member
Hi all, I am new to programming and I am trying to implement a simple calculator using VBA. The idea behind this function is to return a string. For example, the input string is [2,+,3,+,4,+,5] the output would be 14. I am not sure how can I implement this using the following recursive function. Please find below the code where I tried implementing the function. However, I am getting an error in "CalcTotal = CLng(Memory(Pos + 1)) & CalcTotal(Pos + 2)" saying that it is a type mismatch. ANy new suggestions are also welcomed.
Also, I have attached a link to my entire program below.
Please find the entire code for reference.
Also, I have attached a link to my entire program below.
Code:
Function CalcTotal(ByVal Pos As Integer) As Long
If Pos > CurrentPos Then ' Case 1: Nothing left to read
CalcTotal = 0
'return 0 as the result because there is nothing to do...
ElseIf Pos = CurrentPos Then ' Case 2: There is only a number left
CalcTotal = CLng(Memory(Pos))
'return the number in the current position...
Else ' Case 3: Read the next two slots of the array and combine with the rest of the array
CalcTotal = CLng(Memory(Pos + 1)) & CalcTotal(Pos + 2)
End If
End Function
Please find the entire code for reference.