Simple array question
-
- Coder
- Posts: 19
- Joined: Thu Sep 08, 2005 3:14 am
Simple array question
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.
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.
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
I don't know much of arraying and stuff but you could try this:
I hope this helps a bit.
grtz
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
grtz
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Re: Simple array question
I'm trying to understand what you want.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.
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.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
-
- Coder
- Posts: 19
- Joined: Thu Sep 08, 2005 3:14 am
okay let me try to explain better
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.
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............
*****
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............
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
-
- Coder
- Posts: 19
- Joined: Thu Sep 08, 2005 3:14 am
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.
*****
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
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.