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

Stumped...Why doesn't this work?? 1

Status
Not open for further replies.

CoffeeManOhYesIAm

Technical User
Feb 17, 2005
21
0
0
US
Crystal 8.5

Hi everyone,

I've been banging my head against this formula but can't figure it out. It should be pretty simple as it basically tries to define variables based on the value of other variables that are already defined. Here's my formula code:

Code:
[blue]numberVar[/blue] dif;
[blue]numberVar[/blue] n1;
[blue]numberVar[/blue] n2;
[blue]numberVar[/blue] n3;
[blue]numberVar[/blue] n4;
[blue]numberVar[/blue] num;
[blue]numberVar[/blue] answer;

dif := .003;                     

[blue]if[/blue](dif < 0) [blue]then[/blue] n1 := (dif * 10) [blue]else[/blue] num := dif;
[blue]if[/blue](n1 < 0)  [blue]then[/blue] n2 := n1 * 10    [blue]else[/blue] num := n1;
[blue]if[/blue](n2 < 0)  [blue]then[/blue] n3 := n2 * 10    [blue]else[/blue] num := n2;
[blue]if[/blue](n3 < 0)  [blue]then[/blue] n4 := n3 * 10    [blue]else[/blue] num := n3;
[blue]if[/blue](n4 >= 0) [blue]then[/blue] num := n4; 

answer := [blue]remainder[/blue](num,3);

"And the dif is "           + [blue]totext[/blue](dif)           + chr(13) +
"And the dif * 10 is "      + [blue]totext[/blue](dif * 10)      + chr(13) +
"And the n1 is "            + [blue]totext[/blue](n1)            + chr(13) +
"And the n2 is "            + [blue]totext[/blue](n2)            + chr(13) +
"And the n3 is "            + [blue]totext[/blue](n3)            + chr(13) +
"And the n4 is "            + [blue]totext[/blue](n4)            + chr(13) +
"And the num is "           + [blue]totext[/blue](num)           + chr(13) +
"And the answer is "        + [blue]totext[/blue](answer)        + chr(13)


All pretty straightforward I think. I'm trying to set the dif variable to a number that's less than zero, but may vary from .0001 to .9999. Then I want to know if that number is evenly divisible by 3, so I should take the [blue]remainder[/blue] of it, right? And if the remainder is zero, then the number is divisible by 3.

Seems simple to me, but the funny thing is that my conditional statements are not working. Here is my output:

And the dif is 0.0030
And the dif * 10 is 0.0300 // Huh? it works in the totext() function but not the assignment operator??
And the n1 is 0.0000
And the n2 is 0.0000
And the n3 is 0.0000
And the n4 is 0.0000
And the num is 0.0000
And the answer is 0.0000


Could somebody PLEASE tell me what's going on? Where is the flaw in my reasoning?

Thanks in advance,

Geoff


 
You are starting out by setting dif to .003, so it is never < 0 and therefore n is always 0. It seems to me you want dif to vary based on some database fields.

-LB
 
HOLY CRAP! [surprise]

You're right! Thanks LB!



Wow... I feel really stupid, I think I'll go get a cup of coffee.

[purpleface]
 
Geoff

here's a hint 0.003 isn't less than Zero

highlight the box once you've thought about it.

Code:
[white]
numberVar dif;
numberVar n1;
numberVar n2;
numberVar n3;
numberVar n4;
numberVar num;
numberVar answer;

dif := .003;                     

if(dif < 1) then n1 := (dif * 10) else num := dif;
if(n1 < 1)  then n2 := n1 * 10    else num := n1;
if(n2 < 1)  then n3 := n2 * 10    else num := n2;
if(n3 < 1)  then n4 := n3 * 10    else num := n3;
if(n4 >= 1) then num := n4; 

answer := remainder(num,3);

"And the dif is "           + totext(dif,3)           + chr(13) +
"And the dif * 10 is "      + totext(dif * 10,3)      + chr(13) +
"And the n1 is "            + totext(n1,3)            + chr(13) +
"And the n2 is "            + totext(n2,3)            + chr(13) +
"And the n3 is "            + totext(n3,3)            + chr(13) +
"And the n4 is "            + totext(n4,3)            + chr(13) +
"And the num is "           + totext(num,3)           + chr(13) +
"And the answer is "        + totext(answer,3)        + chr(13)
[/white]

HTH

Gary Parker
MIS Data Analyst
Manchester, England
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top