Can't determine afterwards the first/last array-element
Posted: Fri Dec 27, 2013 1:08 pm
Hi,
I have a problem with determining afterwards the number of the first element and the number of the last element in an array.
I made a little stack to test.
All works well if the number of the last element of the array is 7 or less.
Above the 7 it gives strange results, results like these below:
(In this example array[x] expands from the first element x=4 to the last element x=9)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Element number Element Value
4 8
The number of elements in the Array is: 1
The first element in the array has number: 4
The last element in the array has number: 4
5 10
The number of elements in the Array is: 2
The first element in the array has number: 4
The last element in the array has number: 5
6 12
The number of elements in the Array is: 3
The first element in the array has number: 4
The last element in the array has number: 6
7 14
The number of elements in the Array is: 4
The first element in the array has number: 4
The last element in the array has number: 7
8 16
The number of elements in the Array is: 5
The first element in the array has number: 8
The last element in the array has number: 7
9 18
The number of elements in the Array is: 6
The first element in the array has number: 8
The last element in the array has number: 7
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
I made a test-stack with 2 buttons and 3 card fields.
The first 2 card fields are input fields and are named "ElementFromField" and "ElementToField" in succession to input the numbers of the first and the last array elements.
Than a button named "Fill Array" that fills the Array.
The script is:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
global gMyArray, gFirstElement, gLastElement
on mouseUp
put card field "ElementFromField" into x
put card field "ElementToField" into y
if x>0 and y >= x
then
put "Element number" & tab & "Element Value" & return & return into card field "theResultField"
put x into gFirstElement
put y into gLastElement
repeat with theElement = x to y
put 2 * theElement into gMyArray[theElement]
put theElement & tab & tab & tab & tab & gMyArray[theElement] & return after card field "theResultField"
put the number of lines in the keys of gMyArray into p
put "The number of elements in the Array is: " & p & return after field "theResultField"
put the first line of the keys of gMyArray into q
put "The first element in the array has number: " & q & return after field "theResultField"
put the last line of the keys of gMyArray into r
put "The last element in the array has number: " & r & return after field "theResultField"
end repeat
else
put "wrong numbers!" into card field "theResultField"
end if
end mouseUp
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The third field displays the results as seen above in the first box between the lines -------- and ----------.
The second button is named Clear Array and it does just that.
The script is:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
global gMyArray
on mouseUp
delete variable gMyArray
put empty into card field "theResultField"
end mouseUp
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The problem is: I want to create in my app each time an one-dimensional array with a different number of elements (and with different values for the first and last element numbers) and then determine afterwards what the first and the last element numbers are.
Am I doing something wrong?
Can anyone help me.
Thanks in advance.
Joop Sleijster
I have a problem with determining afterwards the number of the first element and the number of the last element in an array.
I made a little stack to test.
All works well if the number of the last element of the array is 7 or less.
Above the 7 it gives strange results, results like these below:
(In this example array[x] expands from the first element x=4 to the last element x=9)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Element number Element Value
4 8
The number of elements in the Array is: 1
The first element in the array has number: 4
The last element in the array has number: 4
5 10
The number of elements in the Array is: 2
The first element in the array has number: 4
The last element in the array has number: 5
6 12
The number of elements in the Array is: 3
The first element in the array has number: 4
The last element in the array has number: 6
7 14
The number of elements in the Array is: 4
The first element in the array has number: 4
The last element in the array has number: 7
8 16
The number of elements in the Array is: 5
The first element in the array has number: 8
The last element in the array has number: 7
9 18
The number of elements in the Array is: 6
The first element in the array has number: 8
The last element in the array has number: 7
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
I made a test-stack with 2 buttons and 3 card fields.
The first 2 card fields are input fields and are named "ElementFromField" and "ElementToField" in succession to input the numbers of the first and the last array elements.
Than a button named "Fill Array" that fills the Array.
The script is:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
global gMyArray, gFirstElement, gLastElement
on mouseUp
put card field "ElementFromField" into x
put card field "ElementToField" into y
if x>0 and y >= x
then
put "Element number" & tab & "Element Value" & return & return into card field "theResultField"
put x into gFirstElement
put y into gLastElement
repeat with theElement = x to y
put 2 * theElement into gMyArray[theElement]
put theElement & tab & tab & tab & tab & gMyArray[theElement] & return after card field "theResultField"
put the number of lines in the keys of gMyArray into p
put "The number of elements in the Array is: " & p & return after field "theResultField"
put the first line of the keys of gMyArray into q
put "The first element in the array has number: " & q & return after field "theResultField"
put the last line of the keys of gMyArray into r
put "The last element in the array has number: " & r & return after field "theResultField"
end repeat
else
put "wrong numbers!" into card field "theResultField"
end if
end mouseUp
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The third field displays the results as seen above in the first box between the lines -------- and ----------.
The second button is named Clear Array and it does just that.
The script is:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
global gMyArray
on mouseUp
delete variable gMyArray
put empty into card field "theResultField"
end mouseUp
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The problem is: I want to create in my app each time an one-dimensional array with a different number of elements (and with different values for the first and last element numbers) and then determine afterwards what the first and the last element numbers are.
Am I doing something wrong?
Can anyone help me.
Thanks in advance.
Joop Sleijster