Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: help on a simple formula gone bad Post Reply Post New Topic
Author Message
TheFrank
Newbie
Newbie
Avatar

Joined: 31 Aug 2012
Location: United States
Online Status: Offline
Posts: 3
Quote TheFrank Replybullet Topic: help on a simple formula gone bad
     Posted: 31 Aug 2012 at 4:31am
I have a text field.  It has 'units' (either a single unit such as 1 or double like 12).  I am just trying to extract the digits which i've accomplished BUT is there is a '.', text, and then a digit the formula dbl posts the digit.     EX: . g 2 results in 22, .gggg4 results in 44.  If it is .6 nu then the result is 6 so it is only when text is inbetween the period and the digit. Tried numerictext, tried replace.  Why is this happening?
The replace:
 
local stringvar string := (replace({JOURNAL.SUBJECT}, ".", "p",1, -1, 1));
local stringvar str:= string;
local stringvar num;
local stringvar stringsave;
local numbervar strlen := len(str);
local numbervar i;
local numbervar x;

for i := 1 to strlen do
(
    replace(str,".","p",i);  // throw this in just to go one by one an change
if val(mid(str,i,strlen)) > 0 then
    num :=(mid(str,i,strlen));
       stringsave := stringsave & num;
          x := val(stringsave);
  
);
x
 
the numeric text
 
local stringvar str := {JOURNAL.SUBJECT};
local stringvar num;
local stringvar stringsave;
local numbervar strlen := len(str);
local numbervar i;
local numbervar x;

for i := 1 to strlen do
(
if numerictext(mid(str,i,strlen)) then
    num :=(mid(str,i,strlen));
       stringsave := stringsave & num;
          x := val(stringsave);
  
);
x
IP IP Logged
comatt1
Senior Member
Senior Member
Avatar

Joined: 19 May 2011
Online Status: Offline
Posts: 337
Quote comatt1 Replybullet Posted: 31 Aug 2012 at 5:53am
could you just round the number
IP IP Logged
TheFrank
Newbie
Newbie
Avatar

Joined: 31 Aug 2012
Location: United States
Online Status: Offline
Posts: 3
Quote TheFrank Replybullet Posted: 31 Aug 2012 at 5:59am
possible but more example may shed light on this issue:
. id 6 results in 66
.4 results in 4 < which is correct
6.bnb results in 6< correct
.d 2. 5... results in 252,555 < ?????????
Any text between, the period and the digit throws off the formula.
 
Easiest way would be to take the text field, eliminate everything that isn't a number(s) but THAT simple process is eluding me as well...
IP IP Logged
comatt1
Senior Member
Senior Member
Avatar

Joined: 19 May 2011
Online Status: Offline
Posts: 337
Quote comatt1 Replybullet Posted: 31 Aug 2012 at 8:24am
replace function, just remove all commas


replace(cast({field} as varchar (10)),',','')
IP IP Logged
TheFrank
Newbie
Newbie
Avatar

Joined: 31 Aug 2012
Location: United States
Online Status: Offline
Posts: 3
Quote TheFrank Replybullet Posted: 05 Sep 2012 at 3:11am
another formula that doesn't work right and it's so simple
So anyone know what is wrong with this (result is all zeroes)
 
local stringvar array legalchar := ["1","2","3","4","5","6","7","8","9"];
local stringvar str := {JOURNAL.SUBJECT};
//local stringvar num;
local stringvar stringsave := "";       
local numbervar strlen := len(str);
local numbervar i;
local numbervar x;
for i := 1 to strlen do
(
if str in legalchar then
       stringsave := stringsave & str;
         x = val(stringsave);
);
x;
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 05 Sep 2012 at 5:25am
Assignment statement is a := not a =.

x := val(stringsave) not x = val(stringsave)
IP IP Logged
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