Page 1 of 2

Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 2:26 am
by RossG
My array doesn't appear to be set up the way it should.
(Tried to insert an image)

.........1
1........ 0
2......... 4

i.e the first element doesn't have an index number
but accepts data but isn't really the first element.
The first one is the second one with index 1.

(What about "Whose on next"!)

My problem or is it LC?

(Mod because my representation of the array didn't appear
in the post as in the preview)

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 3:44 am
by dunbarx
Hi.

How did you make this array?

Craig Newman

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 11:03 am
by MaxV
What is the result of:

Code: Select all

put the keys of my_array
??

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 12:03 pm
by RossG
I made the array with

repeat with i = 1 to 36
put 0 into theArray
end repeat.

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 1:40 pm
by RossG
I had a thought that my prog. might have tried to put a number
into array[0] but have watched the array being set up in the
debugger and the ghost element appears after the 36 real ones.

So it's not being done by my prog.

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 4:16 pm
by FourthWorld
What does the code used to verify the array look like?

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 4:32 pm
by MaxV
Using this code:

Code: Select all

repeat with i = 1 to 36
   put 0 into theArray[i]
end repeat
put the keys of theArray into temp
sort numeric temp
put temp
I get

Code: Select all

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
No problem for me.
Moreover this code:

Code: Select all

repeat with i = 1 to 36
    put 0 into theArray[i]
end repeat
put the keys of theArray into temp
put the number of lines of temp
returns 36.

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 5:04 pm
by dunbarx
Hi.

All you have written, aside from the first post, is as it should be. Can you duplicate the result you got initially, with the missing first key?

As an aside, you have discovered, at least for me, that the sortDirection can be placed either before or after the container reference. Anyone else know this?

Craig

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 5:07 pm
by FourthWorld
I wonder if the erroneous output might be the result of having two arguments for the combine command provided in the wrong order.

combine tVarA with tab and return

...will yield something that looks like the OP's example, but:

combine tVarA with return and tab

...will produce something more like what's expected.

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 5:55 pm
by RossG
I've tried the same code in Rev 3.0 and it produces
the correct result.

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 7:32 pm
by FourthWorld
What does the code look like?

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 8:40 pm
by RossG
ForthWorld

repeat with i = 1 to 36
put 0 into theArray
end repeat

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 8:55 pm
by RossG
Stranger and stranger.

I opened the one-button prog I did with Rev 3
to initialize the array in LC and it makes the
array correctly.

As for getting the index of the elements in the array
I think I'll settle for putting them into theArray[1] and
the other data into theArray[2].

Later:
I've set up the array successfully without putting 0 into
each element. One of those mysteries that may never
be solved.

Thank you all for your efforts.

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 8:57 pm
by dunbarx
Hi.

This is what you posted before. This yields an array of 36 keys, each with a "0" as its associated element. Try:

Code: Select all

on mouseUp
   repeat with i = 1 to 36
         put 0 into theArray[i]
   end repeat
   
   combine theArray with return and comma
   sort theArray numeric
   put theArray into fld 1 --or whatever
end mouseUp
Works just fine. So are you saying that in a later version of LC, a similar handler loses the first key?

Craig

Re: Array Problem -LC 7.0.1

Posted: Mon Nov 09, 2015 9:19 pm
by RossG
Craig

I'll not spend any time trying to solve this mystery.
Have to get on with my coding.

Later: I think my problem was caused by trying to delete
the array as it would be generated afresh on the next cycle.
I tried to put "" into each element.

Now, how do I "neutralize" the array?
delete array36
doesn't work.