Page 1 of 3

Div and Mod with Variables

Posted: Tue May 03, 2016 6:16 pm
by CElwell
How do you use div and mod with variables because I get errors with my code even tough the variable produces a number value.

Code: Select all

      put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Age") into tAge
      tAge div 12
      put it into tYears
      tAge mod 12
      put it into tMonths
      put "Age: " & tYears & " " & tMonths & return after tData 

      put tData & return after tOutput
      set the text of field "tData" to tOutput
Thank you!

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 6:23 pm
by dunbarx
Hi.

You have syntax errors, not operator errors. I started reading your code, and threw an error at line 2. You are asking LC to find a handler with the name "tAge". There isn't one. I think you want to:

Code: Select all

put tAge div 12 into someOtherVariable_EvenIncludingtAgeItselfIfYouWant
or somesuch.

Try it, modify as you go, and see what happens.

Craig Newman

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 6:28 pm
by CElwell
dunbarx wrote:Hi.

You have syntax errors, not operator errors. I started reading your code, and threw an error at line 2. You are asking LC to find a handler with the name "tAge". There isn't one. I think you want to:

Code: Select all

put tAge div 12 into someOtherVariable_EvenIncludingtAgeItselfIfYouWant
or somesuch.

Try it, modify as you go, and see what happens.

Craig Newman
I tried this also but I get an error with the left operand for both.

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 6:30 pm
by Klaus
Did you make sure that

Code: Select all

put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Age") into tAge
really returns a number in tAge?

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 6:33 pm
by CElwell
Yes, currently it gives a number which is the age in months. I am trying to divide by 12 to get just the number of years and then use mod to also show the number of months in addition to the years.

For example: tAge = 71 but want it to show as 5 years and 11 months.

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 6:43 pm
by Klaus
Hm, the little script works as exspected in LC 8 RC1 (with age 71 hardcoded!)!?

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 6:51 pm
by CElwell
Hm, the little script works as exspected in LC 8 RC1 (with age 71 hardcoded!)!?
I understand this, but it does not work with the variable which does display a value. Would you like me to show you more code? I am unsure why it is not working, but tAge does represent a value so...

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 7:00 pm
by Klaus
Hm, any invisible chars (= garbage) in tAge?

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 7:49 pm
by CElwell
No...here is a screenshot though

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 9:27 pm
by dunbarx
Hi.

Test tAge and verify it is a number:

Code: Select all

if tAge is a number then keepGoing
Craig

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 9:34 pm
by SparkOut
Check the line calculating tMonth. You have "Age" not "tAge".

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 10:09 pm
by CElwell
tAge does give a number as seen here: it gives numbers such as 71, 64, 70, and 51. So the problem must be somewhere with the div or mod.

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 11:34 pm
by dunbarx
Did you read Sparkout's post?

If you have a number in tAge, it will work. And if you have tAge itself, it will work.

You are now in the exalted group of those who struggle mightily, and finally discover the tiny flaw in the ointment. Or fly. This includes everyone here...

Craig

Re: Div and Mod with Variables

Posted: Tue May 03, 2016 11:46 pm
by CElwell
Yes, I accidently deleted it when trying to copy the code onto this forum and I fixed it but that is not the problem.

Re: Div and Mod with Variables

Posted: Wed May 04, 2016 2:20 am
by dunbarx
Hmmm.

What happens if you throw in a line just before the "div" line, where, say, you:

Code: Select all

put tAge + 4 into temp
Does that compute? Because if it does, then:

Code: Select all

put tAge div 4 into temp
will as well.

I cannot wait to find out where the gremlin lies...

Craig