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

using Join and MakeArray to format a number 1

Status
Not open for further replies.

ascheper

Technical User
Nov 29, 2001
45
CA
There may be an easier way to do this, but I'm pretty new to Crystal reports. I'm trying to format a string of numbers with the following (input is 1234567890, output is (123) 456-7890):

Join (MakeArray ("(",ToText (Left ({FaxCover_View.Fax},3))," ", ToText (Mid ({FaxCover_View.Fax},4,3)),"-", ToText (Right ({FaxCover_View.Fax},4))))


From what I wave seen in other reports we have, this shouild work, but I keep getting an error saying that the formula should result in a number. What am I doing wrong?
 
Does it say that it should RESULT in a number or that the argument must be a number? It looks (upon cursory examination) as if you may be mixing types:
ToText(Left({your var}, 3)) -- In order for the LEFT to work, the var has to already be a string, in which case the TOTEXT won't work.
 
Syntactically, the formula is okay, (except that you look like you're missing another ) in your second set of " "), as long as the 1234567890 field is really a string field.

If it isn't, you need to swap your Left and ToText around.
 
Thank you both, I tried switching the left and totext (which I think was a problem too), but still get the same message. Yes, it does say it should RESULT in a number. This is now what I have:

Join (MakeArray ("(",left (totext ({FaxCover_View.Fax}),3)," ", mid (totext ({FaxCover_View.Fax}),4,3),"-", right (totext ({FaxCover_View.Fax}),4)))
 
You are getting this error becaus MakeArray() can only take number as input, while you are using text. See the CR help files on this function.

If you know there's an easier way to do this, why are oyu doing it this way? Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
Actually dgillz, I do not know of a different way, that is why I am doing it this way. I just assume there may be an easier way, like I said, I'm new to Crystal (thrown to the wolves is a better description). I have used the MakeArray with text strings before and it worked fine. Is there another way? I tried to concatenate (looked in CR help for the syntax) and that did not work either. I'm at a loss as to what is supposed to work.
 
Thank you everyone for your help, I figured it out by playing around with the concatenate syntax.
 
Dgillz, I don't think MakeArray has numerical limitations.
 
Naith,
My fault, I misread the CR help files.

ascheper, hree is how I would write a formula for this:

Picture({string},"(xxx) xxx-xxxx")

or if it is a number:

Picture(totext({string},0,""),"(xxx) xxx-xxxx")



Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
Naith,
My fault, I misread the CR help files.

ascheper, here is how I would write a formula for this:

Picture({string},"(xxx) xxx-xxxx")

or if it is a number:

Picture(totext({Number},0,""),"(xxx) xxx-xxxx")



Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
Simple'n'sexy.

Picture is one of those functions that tends to get forgotten about by people like me, because I'm too often thinking the solution is much more difficult than it needs to be.

Naith

When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong. -- R. Buckminster Fuller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top