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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ToText Conversion Issue

Status
Not open for further replies.

glthornton

Programmer
Oct 19, 2005
108
US
Hi,

I'm using CR XI with and SQL ODBC connection. I'm having problem trying to get a properly formatted date string when using the ToText command. Here is my formula:

Code:
// Clear Variables
NumberVar Mon1 :=0;
NumberVar Day1 :=0;
NumberVar Yr1 :=0;
StringVar Mon2 := "";
StringVar Day2 := "";
StringVar Yr2 := "";
StringVar FinDT:= "";

//Set DT variable to today's date in text format
shared NumberVar IndID:=IndID+1;
StringVar StrIndID:=ToText(IndID,0);

//Set Month, Day, Year Variables
NumberVar Mon1:=DatePart ("m",CurrentDate);
NumberVar Day1:=DatePart ("d",CurrentDate);
NumberVar Yr1:=DatePart ("yyyy",CurrentDate);

//Convert Month, Day, Year Variables to Text
StringVar Mon2:=ToText(Mon1);
StringVar Day2:=ToText(Day1);
StringVar Yr2:=ToText(Yr1);

//Set Final Date (FinDT) to today + Incremented counter variable
StringVar FinDT:=Mon2+Day2+Yr2+"-"+StrIndID;

What I am currently getting for an end result looks like this: "5.007.002007.00-1" and "5.007.002007.00-2", etc. What I'd really like the string value to look like is "05072007-1". But I'd even be happy without the leading zeros like this: "572007-1". Does anyone know how I can do this? Or can someone show me how to prevent the decimals from being converted to text?

Thank you,
glthornton
 
Hi,
Try:

StringVar Mon2:=ToText(Mon1,#);
StringVar Day2:=ToText(Day1,#);
StringVar Yr2:=ToText(Yr1,#);



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Hey Turk,

I did try it and I got the following error when I tryed to validate the syntax: "The matching # for date time literal is missing".

I did check the Crystal Help section and it confirms exactly what you are instructing. Have any other possibilites? I wish this area had a debugging tool that we could use to test our formulas?

Thanks,
glthornton
 
Hey Turk,

I changed the the syntax to:

Code:
StringVar Mon2:=ToText(Mon1,0);
StringVar Day2:=ToText(Day1,0);
StringVar Yr2:=ToText(Yr1,0);

And now I get "572,007-1" for an end value. Does anyone know how to remove the comma formatting for this formula? This is what my formula looks like now:

Code:
// Clear Variables
NumberVar Mon1 :=0;
NumberVar Day1 :=0;
NumberVar Yr1 :=0;
StringVar Mon2 := "";
StringVar Day2 := "";
StringVar Yr2 := "";
StringVar FinDT:= "";

//Set DT variable to today's date in text format
shared NumberVar IndID:=IndID+1;
StringVar StrIndID:=ToText(IndID,0);

//Set Month, Day, Year Variables
NumberVar Mon1:=DatePart ("m",CurrentDate);
NumberVar Day1:=DatePart ("d",CurrentDate);
NumberVar Yr1:=DatePart ("yyyy",CurrentDate);

//Convert Month, Day, Year Variables to Text
StringVar Mon2:=ToText(Mon1,0);
StringVar Day2:=ToText(Day1,0);
StringVar Yr2:=ToText(Yr1,0);

//Set Final Date (FinDT) to today + Incremented counter variable
StringVar FinDT:=Mon2+Day2+Yr2+"-"+StrIndID;

Thank you,
glthornton
 
Change this part:

StringVar Mon2:=ToText(Mon1,0,"");
StringVar Day2:=ToText(Day1,0,"");
StringVar Yr2:=ToText(Yr1,0,"");

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top