Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[b]Converting string to number[/b]

Status
Not open for further replies.

madsstiig

Technical User
Jun 11, 2008
50
DK
Hi.
I found a formula in another thread about this:
stringvar x := {yourdbfield};
stringvar z;
numbervar y;
for y := 1 to len(x)
do
if isnumeric(x[y])
or x[y] = "." then
z := z + x[y]
else z;
tonumber(z)

HOWEVER when I use it it seems that my resulting numbers are multiplied all the way down through the report.
My string {VWDEPSTAT.DID} is actually a patient-ID (which in Denmark is always the same number for each patient no matter where in the system the patient is registered - always the same 8 digit social security number).
Using the above solution makes the first entry an 8 digit number equal to the social security number but the next patient's number is multiplied by 100 and so forth.
What's wrong?
Best regards Mads Stiig, Denmark
 
It sounds like the solution you are trying to use is inappropriate to your situation. What are you trying to do? Why do you want to convert the ID to a number? Please also show samples of the ID field.

-LB
 
The reason why I need to convert from string to number is that I need to anonymize some patients in a report and want to multiply the number by a constant (e.g. 0.4 to make the number smaller and immediately unrecognizable but still recognizable if needed).
A social security number in Denmark reflects birthdate as DDMMYY plus a 4 digit 'serial number'. So if you're born July 4th 1967 your social security number would start with 040767 and end with the 4 digit code looking something like 040767-0735.
Would this be possible to accomplish? Why does the formula above not work for me?
 
... the '-' doesn't count in the number by the way. In the system the number would be 0407670735 ...
 
You probably just need to reset the variables, as in:

stringvar x := {yourdbfield};
stringvar z [red]:= ""[/red];
numbervar y [red]:= 0[/red];
for y := 1 to len(x)
do
if isnumeric(x[y])
or x[y] = "." then
z := z + x[y]
else z;
tonumber(z)

But this is more complicated than you need. Try instead:

tonumber(replace({table.string},"-",""))

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top