"variable has no value"
Author |
Message |
gsquare567
|
Posted: Sun May 11, 2008 3:55 pm Post subject: "variable has no value" |
|
|
2 questions:
1) How can i get the length of a pre-set array
2) Why am i not allowed to dynamically initialize an array here : (focus on exactNoteTimes array)
i preset 0 and then in the second last line use it to to make 1, which is used to make 2, etc.
so if i preset 0 then why is i-1 not set? the first run it will pe 1-1 = 0, and 0 is 3000 (note the second line). in the last line i set exactNoteTimes(i) and then the next run it will be i-1, so there should be no problem.
code: |
var exactNoteTimes : array 0 .. 300 of int
exactNoteTimes (0) := 3000
.....................
for i : 1 .. 300 % i is the note number, starting at 1
%if the note has NOT been sent (variable has not been set yet)
if noteStatus (i) = 0 then
%then check if the time is right
if lastTimeSent + noteTimeIncreases (i)
<= Time.Elapsed then
% amount of time ahead of the last note
noteStatus (i) := 1 %if it is right, set the note to ON so we move it after this if statement
lastTimeSent := exactNoteTimes(i-1) + noteTimeIncreases (i) %update the last time a note was sent to NOW
exactNoteTimes (i) := lastTimeSent |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Sun May 11, 2008 7:40 pm Post subject: RE:"variable has no value" |
|
|
1)
To get the upper limit you can use the function upper and to get the lower limit you can use the function lower.
Example:
Turing: |
var foo: array 1 .. 100 of int
put "upper: ", upper(foo )
put "lower: ", lower(foo )
|
2) I am kind of confused by your question and code snipit. But my guses is that if any of the if stamets are not ture the array will not have an element set and there will be no value for the next time the ifs become true.
for example if i = 1 and noteStatus (1) not = 1 then exactNoteTimes (1) will not be set and on the next loop if noteStatus (2) = 0 and lastTimeSent + noteTimeIncreases (2) <= Time.Elapsed then exactNoteTimes(2-1) will be undefined. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
|
|