Page 1 of 1

Simple array question

Posted: Wed Sep 14, 2005 1:49 am
by Rocket Boy
Alright, I have an array that's like...

Array(1 to 30) as Integer

I want to use it to keep track of the Z-Order of windows in a GUI. So, the idea is each of the elements of that array hold an ID number of a given window, the top one being 1.

What I'm looking to do, is a way to put the ID of the window into 1 (Array(1) = WindowId), easy... but then I need a way to bump all the others up or change them around accordingly. So if window number 3 was on top, and then window number 8 is now in Array(1) I want number 3 to go to Array(2) and then have a way to get the other windows into where they should be for elements 3 to 30. Okay, maybe this isnt so simple. The point is, it makes a difference which order the windows are in, since they will be drawn in that order...

Thanks.

Posted: Wed Sep 14, 2005 2:02 am
by SebMcClouth
I don't know much of arraying and stuff but you could try this:

Code: Select all

DIM SHARED WindowCascade(0 to 29) AS INTEGER

'you code here

'say that 1 is on top and 30 on the bottom, then it could be:
'WindowCascade (0) = 1 --> WindowCascade (29) = 30
'When you click on 30 it comes to the top, so you need a routine
'checking this.

If WindowClicked = 30 THEN
  'rearrange cascade
  WindowCascade (0) = 30: 'etc
END IF
I hope this helps a bit.

grtz

Re: Simple array question

Posted: Wed Sep 14, 2005 12:40 pm
by moneo
Rocket Boy wrote:Alright, I have an array that's like...
Array(1 to 30) as Integer
I want to use it to keep track of the Z-Order of windows in a GUI. So, the idea is each of the elements of that array hold an ID number of a given window, the top one being 1.

What I'm looking to do, is a way to put the ID of the window into 1 (Array(1) = WindowId), easy... but then I need a way to bump all the others up or change them around accordingly. So if window number 3 was on top, and then window number 8 is now in Array(1) I want number 3 to go to Array(2) and then have a way to get the other windows into where they should be for elements 3 to 30. Okay, maybe this isnt so simple. The point is, it makes a difference which order the windows are in, since they will be drawn in that order...

Thanks.
I'm trying to understand what you want.

You said "So if window number 3 was on top". Does that mean that number 3 is in array(1) at this moment, or does "top" mean something else?

Then you said "and then window number 8 is now in array(1)". How did it get there, or was it already there?

Then you said "I want number 3 to go to Array(2)". Why? If it's at the "top" wouldn't you want to put number 3 into array(1) and number 8 to fall down to array(2)?

Please explain with a little more detail. Maybe show a few examples with the window numbers shifting in the array. I already have a little piece of array code that does something similar. Maybe we can adapt it to what you want.

BTW, I don't understand Seb's solution at all.
*****

Posted: Wed Sep 14, 2005 2:49 pm
by SebMcClouth
Neither do I... I just tried sumfin...

grtz
Bas

okay let me try to explain better

Posted: Wed Sep 14, 2005 4:05 pm
by Rocket Boy
Top means the ID of the window is in Array(1). So, window #3 is in Array(1), someone clicks on window #8, which was previously in Array(4) - Array(1) now equals 8 and Array(2) now equals 3, whatever was in Array(2) before moves to Array(3), and Array(3) moves into Array(4) to fill the space that window #8 left behind and nothing above array(4) is affected.

Posted: Wed Sep 14, 2005 5:52 pm
by moneo
SebMcClouth wrote:Neither do I... I just tried sumfin...

grtz
Bas
You're a riot, Seb! :D

Posted: Wed Sep 14, 2005 6:41 pm
by moneo
Rocket Boy,

I've got the routine you need. It was written in 1986 by a group of us at Citibank-Mexico as a challenge.

Instead of an array of window ID numbers like you have, they array contained train wagon numbers. You select a wagon number, it gets moved to the head of the train, and the rest of the array is adjusted accordingly. This is exactly what you need. Give me a chance to convert it from Spanish to English, from GWBasic to QB, and to test it. It's about 10 lines of code.

I'll be back............
*****

Posted: Wed Sep 14, 2005 6:55 pm
by Rocket Boy
javascript:emoticon(':D') thanks! can't wait :)

Posted: Wed Sep 14, 2005 8:26 pm
by moneo
Ok, here it is. This is a test version for a range of 1 to 5 elements in the array, so you can see how it works. Later you adapt the code to your program. So compile it and test it. Good luck!
Any problems or questions, just ask.

Code: Select all

defint a-z
const anum=5
dim array(1 to anum)
for x=1 to anum:array(x)=x:next x  'Prime the array

do 
   gosub display
   getwin:
   input "Enter window number to move to top (0 to finish) ",win
   if win<0 or win>anum then print "ERROR: invalid window number":goto getwin
   if win=0 then system
   j=1:while win <> Array(j):j=j+1:wend  'Find where window number is now
   for k=j to 2 step -1                  'Bubble window number to the top
       swap Array(k),Array(k-1)
   next k
loop

display:
  for n=1 to anum
      if n<anum then print Array(n);"--"; else print array(n)
  next n
return
*****

Posted: Wed Sep 14, 2005 9:09 pm
by Rocket Boy
Thanks, that should help alot!