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

Multiple Variables (and types) in a Formula Returns Zero 2

Status
Not open for further replies.

AndersonCJA

Programmer
Jul 30, 2003
57
US
WHILEPRINTINGRECORDS;
//
// I am roughly following the example from
// // and using multiple variable assignments in one formula.
//
// I believe the problem is in the the way
// I have coded the very last line in the example
//
//
// I recieve the message "a string is required here"
// or it works and I get a zero result.
//
//
// I have included only a portion of my formula
// so that it will be easier to read.
//
// If I test the code in an "if then else print" formula
// I can see the result is true and being met.
//
// The problem is that when fields that
// fill the variable, "role" and the
// variable, "over18" are sometimes blank.
// When they (just the two fields out of four)
// are blank I get a blank result.
//
// perhaps I am not allowed to use multiple variable
// types in one formula.
//
// If I modify the last line, I can get it to run, but I get
// a zero result.
// Here is an Exmple of the formula


Numbervar Person;
Datevar Bday;
Stringvar Role;
Stringvar over18;


if
Stringvar Role <> "role1" AND
isnull({TABLE1.DATEBIRTH}) and
{TABLE2.DATEBIRTH} > datevar bday and
{TABLE2.DATEBIRTH} < {@EndofLastMonth}
then
(numbervar Person := {FIELD1.DATA1};
Datevar bday := date({FIELD2.DATEBIRTH});
Stringvar Role := {TABLE3.FIELD3};)
Stringvar over18 := Stringvar over18)
ELSE
(numbervar person := Numbervar person;
Datevar bday := Datevar bday;
Stringvar Role := Stringvar Role;
Stringvar over18 := Stringvar over18)



; totext(numbervar person,0,'') + ' ' + totext(datevar dbay,0,'')
+ ' ' + stringvar Role,0,'' + ' ' + stringvar over18,0,''
 
I don't see where you are passing any information to over18.
This is why it would be zero.

Need something along the lines of:

if beginedate - enddate >= 18 then
over18 := 'I can vote';

Just my 2 cents - right or wrong.
 
I see couple of problems. First you have a parenthesis in the wrong place, second you shouldn't redeclare a stringvar etc in the middle of a formula. You need to declare and instantiate all the variables in another formula:

//@Declarations
// Put in report header to instantiate your variables
global numbervar person := 0;
global Datevar bday := Date(0,0,0);
global Stringvar Role := "";
global Stringvar over18 := "";

//@YourFormula
global numbervar person;
global Datevar bday;
global Stringvar Role;
global Stringvar over18;




if
Stringvar Role <> "role1" AND
isnull({TABLE1.DATEBIRTH}) and
{TABLE2.DATEBIRTH} > bday and
{TABLE2.DATEBIRTH} < {@EndofLastMonth}
then
(Person := {FIELD1.DATA1};
bday := date({FIELD2.DATEBIRTH});
Role := {TABLE3.FIELD3};
over18 := over18)
ELSE
(person := person;
bday := bday;
Role := Role;
over18 := over18)



You need to reset the variables to defaults when you want to start over

Lisa
 
I missed taking out a "stringvar" from the body of the formula
 
I see how that is misleading, I shortended the code to make it less cumbersome and made it misleading instead. Sorry about that. When a certain condition is met, Role = 'Y'
Thank you so much for your reply. I really appreciate it.
 
Using the Global declarations solved the problem.

Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top