Public Function CharCount(RomanChar As String, Expression As String) As Long
Dim sTemp As String
sTemp = Replace(Expression, RomanChar, "")
CharCount = (Len(Expression) - Len(sTemp)) / Len(RomanChar)
End Function
Public Function RomanToDecimal(ByRef RomanNum As String) As Long
'note that I passed by reference so I can update the value of RomanNum in the called procedure
RomanToDecimal = -1
If SimpleCheck(RomanNum) <> ) Then error occured 'check for common errors and invalid letters
If ReplaceOnes(RomanNum) <> 0 Then error occured
If ReplaceTens(RomanNum) <> 0 Then error occured
If ReplaceHundreds(RomanNum) <> 0 Then error occured
If ReplaceThousands(RomanNum) <> 0 Then error occured
'you will need to correct the leading + sign in the final expression
If PlacesCheck(RomanNum) <> 0 Then error occured
'You will reuse ExpressionToArray() in placescheck() to
'get an array to check by iteration to ensure that
'the decimal values progress in order from thousands to ones
romanNum = EvaluateExpression(RomanNum) & ""
RomanToDecimal = 0 'completed successfully
End Function
'Pseudocode for ones place, do the same for the other places
' note validity checks during conversion
Public Function ReplaceOnes(ByRef Expression As String) As Long
Dim IVcount As Long
Dim IXcount As Long
ReplaceOnes = -1
IVcount = CharCount("IV", Expression)
IXcount = CharCount("IX", Expression)
If IVcount > 0 and IXcount > 0 Then
'error, IX and IV cannot exist at the same time
ElseIf IVcount > 1 Then
'error, only one IV in a number
ElseIf IXcount > 1
'error only one instance of IX is valid
ElseIf IVcount = 1
'notice no need to check IXcount = 0,
'it is implied cause first case already handles IVcount > 0 and IXcount > 0
Expression = Replace(Expression, "IV", "+4")
If CharCount("I", Expression) > 0 Or CharCount("V", Expression) > 0 Then
'error, I's or V exist when IV already used
End If
ElseIf IXcount = 1
'almost same format as IVcount = 1, test I's and X
ElseIf IVcount = 0 and IXcount = 0
If CharCount("V", Expression) > 1 Then
'error, only one V is valid
Else
Expression = Replace(Expression, "V", "+5")
End If
If CharCount("I", Expression) > 3 Then
'error, only up to 3 I's valid
Else
Expression = Replace(Expression, "I", "+1")
End If
End If
ReplaceOnes = 0 'completed with no errors
End Sub
Public Function EvaluateExporession()
Dim oSCRCNT As New ScriptControl
'sorry have to go... but this will have only about 3 to 5 lines
'anyone for the save??
End Function