• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

A string is required here

Hi Guys,

How do I correct the below formula? I keep getting  an error message "A string is required here"

if {@sum_condition_value} <= 0 then "" 
else ToText({@bailing_text})
a-string-is-required-here.bmp
0
mcse2007
Asked:
mcse2007
  • 7
  • 5
  • 2
  • +1
3 Solutions
 
sjklein42Commented:
How is sum_condition_value declared?  We need a little more context.
0
 
mcse2007Author Commented:
It is declared like the below. Is it incorrect?

CStr(sum ({Sheet1_.Condition value}, {Sheet1_.Bill#Doc#}),2,'')
0
 
zephyr_hex (Megan)DeveloperCommented:
@sum_condition_value is cstr
you are comparing it to a number when you have <= 0

sum_condition_value either needs to return a number, or the value you're comparing it to needs to be a character (such as "0")
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
mlmccCommented:
Since it is a string you have to compare it to a string.
if {@sum_condition_value} <= "0" then
   ""
else
    ToText({@bailing_text})

It might be better to compare to the numeric value since I am not sure if the string   "-123"   is less than the string "0"
 
if Val( {@sum_condition_value} ) <= 0 then
    "" 
else
    ToText({@bailing_text})

mlmcc

0
 
sjklein42Commented:
CStr makes a string.  You can use ToNumber to make it back into a number.

Since you made a string, this means that you need to test against a string, perhaps with  "0".

But that is not advisable.

You can do this:

if ToNumber({@sum_condition_value}) <= 0 then ""

Open in new window

Of you could make sum_condition_value be a number by calling ToNumber when it is declared, but that may break some other part of your code.

ToNumber(CStr(sum ({Sheet1_.Condition value}, {Sheet1_.Bill#Doc#}),2,'') )

Open in new window


Either way, you must match number to number, or string to string.
0
 
mcse2007Author Commented:
It is always iinspiring getting help from you guys.

Before, I close this post, one last question.

mlmcc, your second formula works perfect but if I rework it and i declared it like the below which also works, any disadvantages doing it this way?

if Val( {@sum_condition_value} ) <= 0 then
    ""
else
    ToText({@bailing_text})

Note: This {@sum_condition_value} simply equals to the the below,

CStr(sum ({Sheet1_.Condition value}, {Sheet1_.Bill#Doc#}),2,'')
0
 
mcse2007Author Commented:
my mistakes, it should be like this.

if Val( {@sum_condition_value} ) <= 0 then
    ""
else
    ToText({@sum_condition_value})
0
 
mlmccCommented:
Since ({@sum_condition_value}) is already a string you don't need the ToText

ALso that will be slower since the formula is called twice.

One that might be fatser is
Local StringVar outstring := {@sum_condition_value};
If Left(outstring ,1) = '-' then
    ""
Else
   outstring


mlmcc
0
 
mcse2007Author Commented:
I now comprehend all the formulas except your last one...what does it mean?
0
 
mlmccCommented:
Since it is a string II am testing for the - sign on the number.  If it is < 0 then it must have a leading - sign

mlmcc
0
 
mcse2007Author Commented:
thanks mlmcc....

finally, how do I get 10% (VAT or GST tax) of the value of the below

if Val( {@sum_condition_value} ) <= 0 then
    ""
else
   
Local StringVar outstring := {@sum_condition_value};
If Left(outstring ,1) = '-' then
    ""
Else
   outstring
0
 
mcse2007Author Commented:
brilliant...you are worth more than these points i've assigned.
0
 
mlmccCommented:
Local StringVar outstring := {@sum_condition_value};
If Left(outstring ,1) = '-' then
    ""
Else
   CStr(Val(outstring ) * .1, 2)

mlmcc
0
 
mcse2007Author Commented:
cheers mlmcc.........dam u r 2 good. I wish I can allocate more points to you. but as said, you are worth more than all the points you earned here. thanks chief!!!
0
 
mlmccCommented:
Your kind words are more than enough

mlmcc
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 7
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now