Evaluating a String

  • Thread starter Thread starter tobesurveyor via AccessMonster.com
  • Start date Start date
T

tobesurveyor via AccessMonster.com

Good Morning All,
I would like to begin by thanking all the MVPs that I have helped me with the
questions I have posted. They have really kept me going in the right
direction with the applications I write.

Being a novice, this may be a simple answer...

In code, I have a string variable pulled in from another source which is a
combination of numbers and letters. This string can be varying lengths
depending on the situation.
Example: 001914LT
FA193A

What I want to do is evaluate each digit of the string and assign a value to
it. For example:
In the "001914LT" I would have:
0 = 10
1 = 20
4 = 50
L = 500
T = 1000

What is the proper way to pull each digit out of the string?

Thanks again in advance,
Chris
 
It sounds as if you want a function to do this. Use MID and a loop. Also,
do you want to return the individual values in a string, one of the values,
a sum of the values? Is the set of characters limited?

Rough code follows.

Public Function EvaluateString(strIn as String)
Dim iCounter as Integer
Dim vReturn as Variant\

For iCounter = 1 to Len(strIn)
Select Case Mid(strIn,ICounter,1)
Case "0" 'zero
vReturn = vReturn & "10;" 'Returns a string with all the
values
'vReturn = vReturn + 10 'Return a sum of the values
Case "L"
vReturn = vReturn & "50;"
'vReturn = vReturn + 50 'Return a sum of the values
Case ...
End Select

Next iCounter

EvaluateString = vReturn
End Function

You might consider using a table to store the equivalents (two columns -Char
and CharValue) and then use that to populate a static array and then check
in the array for the character. The above is the simplest code I can think
of
 
Back
Top