Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: adding a string of numbers Post Reply Post New Topic
Author Message
SusanW
Newbie
Newbie
Avatar

Joined: 27 May 2009
Location: United States
Online Status: Offline
Posts: 4
Quote SusanW Replybullet Topic: adding a string of numbers
    Posted: 27 May 2009 at 12:28pm
I have 2 fields I want to compare and need to add all the numbers in the field.  Field 1 is a character field and I want to add all 9 characters together to get a total.  although it is a character field, there are numbers in it.
 
Also, the second field is the same, character field with dashes "-" separating the numbers. (it is actually a SSN field).
 
What formula could I use to do this?
 
Thanks
Susan
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 28 May 2009 at 1:46am
Hi,
 
please can you post some sample data....
 
cheers
Rahul
 
IP IP Logged
SusanW
Newbie
Newbie
Avatar

Joined: 27 May 2009
Location: United States
Online Status: Offline
Posts: 4
Quote SusanW Replybullet Posted: 28 May 2009 at 5:39am
field A  is   123-45-6789  and field B  is  123-45-7877
 
how do I total the numbers in each field ?
 
Thanks!
Susan
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 28 May 2009 at 6:37am

val(replace({fieldA}, "-", "")) + val(replace({fieldB}, "-", ""))

should work...
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 28 May 2009 at 9:22am
For field A, are you asking how to total 1+2+3+4+5+6+7+8+9 ?

Edited by JohnT - 28 May 2009 at 9:22am
IP IP Logged
SusanW
Newbie
Newbie
Avatar

Joined: 27 May 2009
Location: United States
Online Status: Offline
Posts: 4
Quote SusanW Replybullet Posted: 28 May 2009 at 9:42am
yes, I needed to strip out the dashes, then add the numbers together.
Susan
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 28 May 2009 at 12:05pm

Try this.  I setup fielda to be 123-45-6789 and it seems to work.

 
NumberVar total =0;
NumberVar StringIndex;
replace({@fielda},"-","");
For StringIndex := 1 to Len({@fielda}) Do
(
  total := total + val(mid({@fielda},StringIndex,1))
);
total
IP IP Logged
SusanW
Newbie
Newbie
Avatar

Joined: 27 May 2009
Location: United States
Online Status: Offline
Posts: 4
Quote SusanW Replybullet Posted: 28 May 2009 at 12:10pm
Thanks!  I'll give it a try!
Susan
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 28 May 2009 at 2:28pm
Ahh...sorry misunderstood what you wanted.  I thought you wanted to add, say, 2 ssns together.  Why?  Idunno.
 
Yeah, JohnT solution would add all the numbers up.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.