Page 1 of 1

Error: Undefined Variable using calculation block

Posted: Tue Oct 09, 2007 1:21 am
by earthground
I was building a project earlier using FlowcodeV3, my lab partner and I developed a program that accepts a number as input to Port B from switches. Then the program must divide the number by 3 to find out if the remainder is equal to zero or not. If the remainder=0 the program should display the original input number as output to Port A on the LED's. If the remainder!=0 the program should display all LED's HIGH(lit up).

Here is my concern:

I am using two variables in my program. The first variable is

Code: Select all

inputNumber
which is used for the value entered by the switches on Port B. The second variable is

Code: Select all

remainder
which is used to store the value of the remainder found by dividing

Code: Select all

inputNumber MOD 3
.

In my calculation block I entered:

Code: Select all

remainder = inputNumber MOD 3 
, then pressed ok to get an error saying that one of the variables is undefined.

In the Input block I established the above variables and used

Code: Select all

inputNumber
.

My partner did everything the same way and his program worked flawlessly. But on my machine I could not get past the calculation block due to this variable problem. Are there any likely causes of this problem?

Posted: Tue Oct 09, 2007 8:01 am
by Steve
Are you sure you spelled the variable names correctly (they are not case sensitive)?

And are you sure the variables have been defined ok? And that they are not string variables?

You can enter variables into calculations using the "variables..." button in the calculation window and then clicking the "use variable" button. Doing this will ensure that the variables exist and that they are spelt correctly.

If you are still having problems, please send your program to us and we'll have a look.

Posted: Tue Oct 09, 2007 10:48 pm
by earthground
I tried defining both variables in my first input block and pressed to use the

Code: Select all

inputNumber
(for the input). Setting it up this way, my calculation block gave me the error stating that I had an undefined variable. So, then I tried the only other way I could think of which was to define the variable

Code: Select all

remainder
by itself in the calculation block's variables menu, and having the

Code: Select all

inputNmuber
variable set up and used by the input block. Both ways gave me the same error message saying that I had the undefined variable.

My calculation block consists of

Code: Select all

remainder=inputNumberMOD3
. I have class again tomorrow and I am going to try again using a different machine to see if maybe there is something wrong with the computer I was working on.

Posted: Wed Oct 10, 2007 8:19 am
by Steve
Make sure you have spaces around the "MOD" operator.

i.e., instead of

Code: Select all

remainder=inputNumberMOD3 
use

Code: Select all

remainder = inputNumber MOD 3

Posted: Wed Oct 10, 2007 2:23 pm
by earthground
Hey I went to the lab today and got the program working. For some reason the calculation block was saying that I had an undefined variable, yet when I proceeded ahaed to putting the rest of the program together and went back to re=enter the calculation block, it accepted it. I'm not sure why but I'm glad that I was able to get the program to work finally.

MOD Space

Posted: Sat Oct 13, 2007 2:31 am
by earthground
Thanks for that tip. It works great.