Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Writing a formula in Crystal Reports

Posted on 2014-03-16
7
Medium Priority
?
770 Views
Last Modified: 2014-04-02
I am a bit out of practice in the use of Crystal and could use a jump start.  Been a long time since I wrote crystal formulas and could use help in correcting the code I have attached.

I need to pull the first three values in a string, determine if the first three values is all numeric and if so is it less then a 100 using a Crystal Formula.   If not a string or less than a 100 use the first concant of values, if greater then 100 then use the second.
Quick-Code.txt
0
Comment
Question by:gilnari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 23

Expert Comment

by:Ido Millet
ID: 39934049
stringVar sTest := "023abc";
IF Len(sTest) < 3 Then "Too Short" Else
(
    sTest := LEFT(sTest, 3);

    IF NumericText(sTest) Then
    (
        IF val(sTest) < 100 Then " " & sTest[1] & " " & sTest[2] & " " & sTest[3]
        eLSE
        sTest[1] & " " & sTest[2] & " " & sTest[3];
    )
    Else "Not Numric";
);
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39934188
What does this part of your question mean?

>>If not a string or less than a 100 use the first concant of values, if greater then 100 then use the second

The final Else in the formula above should be

ELSE
        sTest[1] & " " & sTest[2] & " " & sTest[3];

mlmcc
0
 

Author Comment

by:gilnari
ID: 39934828
I have a string as example 110 deg F or could be 70 deg F.  
What I need to know if the first three characters is something like  (110, or 70<space>)
Then see if the value (which is numeric) is less than 100 (100 deg F) I want to add a space to a set of values I am concanting together at the beginning if less than 100.   Its a pretty lineup thing I am trying to accomplish.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 23

Expert Comment

by:Ido Millet
ID: 39934839
The text sample you provided indicates you want spaces inserted, but your latest message indicates otherwise.  Tough to follow, so please provide a couple of examples of input versus desired output.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39935010
Try something like

Local StringVar  TestString;
TestString := Left({YourFIeld},3);

If NumberText(YourString) then
    If Val(YourString) < 100 then
         " " & TestString
    Else
      TestString
Else
    TestString

mlmcc
0
 
LVL 35

Accepted Solution

by:
James0628 earned 2000 total points
ID: 39935180
Some of the other suggestions may give you what you need, but FWIW ...

 I see 3 basic problems with the formula attached to your first post.

 You don't have a ";" at the end of each statement.
 You had a typo in the declaration for the string variable and called it sTest, instead of sText (the name you used in the other lines).
 You used "=" when you tried to set nTemp, instead of ":=".

 You also mentioned checking to see if the first 3 characters are numeric, and you didn't do that in your formula.  If those characters could really be non-numeric (not just something like "72 ", but things like "abc" or "1b3"), then you need to test for that, because ToNumber will give you an error on strings like that.

 This is your formula with the corrections I mentioned, and a couple of NumericText checks added:

WhilePrintingRecords;
Global numberVar nTemp;
Global stringVar sText;
sText:= LEFT({RESULT.ATTRIBUTE_1}, 3);
if NumericText (sText) then
  nTemp := ToNumber(sText);
IF NOT ISNULL ({RESULT.ATTRIBUTE_3}) THEN 
    IF NumericText (sText) and nTemp < 100 THEN
    " " & ({RESULT.ATTRIBUTE_1} & " " & {RESULT.ATTRIBUTE_2} & " " & {RESULT.ATTRIBUTE_3})
    ELSE
     ({RESULT.ATTRIBUTE_1} & " " & {RESULT.ATTRIBUTE_2} & " " & {RESULT.ATTRIBUTE_3})

Open in new window


 If you want the formula to produce a specific result (not just an empty string) when RESULT.ATTRIBUTE_3 is null, then you also need to add an Else at the end for that.

 James
0

Featured Post

The Ideal Solution for Multi-Display Applications

Check out ATEN’s VS1912 12-Port DP Video Wall Media Player at InfoComm 2017. Kerri describes how easy it is to design creative video walls in asymmetric layouts and schedule detailed playlists ahead of time with its advanced scheduling feature.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Invest in your employees with these five simple steps to improve employee engagement and retention.
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question