Your gathering place for information and ideas about Quality Assurance, Testing, and other topics of interest.
November 14, 2009
WinTask - ToDollarAndCent()
'
' ToDollarAndCent()
'
' Author: Joe Strazzere
'
' Removes all non-numerics from a string
' Returns two numbers
' - the dollars portion
' - the cents portion
'
Function ToDollarAndCent(test$,Dollars,Cents)
Local i
Local new$
Local work$
work$=""
Dollars=-1
Cents=0
i=1
While i<= len(test$)
Select Case Mid$(test$,i,1)
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
new$=Mid$(test$,i,1)
Case "."
new$=""
Dollars=Val(work$)
work$=""
Case Else
new$=""
EndSelect
work$=work$+new$
i=i+1
Wend
If Dollars=-1 Then
Dollars=Val(work$)
Else
Cents=Val(Left$(work$,2))
EndIf
EndFunction
ToDollarAndCent(" $123,456.789 ",D,C)
MsgBox(D)
MsgBox(C)
Labels:
WinTask