Using a String as a Window Name

I have a String value of “SomeWindowName”

I have a Window named SomeWindowName
I have a PushButton on that Window named MyButton

Is there a way to refer to that window and it’s controls using the String?

Specifically instead of SomeWindowName.MyButton, I want to use the String value of “SomeWindowName”.MyButton.

Not like you’ve described

What is it you’re trying to accomplish that you have this string ?

[quote=53636:@Norman Palardy]Not like you’ve described

What is it you’re trying to accomplish that you have this string ?[/quote]

It’s designed to keep track of Windows that are opened and in what order they got opened so that when a given window is closed, I can force the focus to the proper window. I store all the windows into an array and when they are opened, I assign #1 to a window. When another window gets opened and #1 is still open, then the first window becomes #2 and the window just opened becomes #1. So, if I have 4 windows open, and #1 gets closed (the most recently opened window), then #2 becomes #1, #3 becomes #2, and #4 becomes #3.

The remaining #1 window should then be the “focused” window.

I’ve found that code, for example in a module, or a timer on another window, can cause a specific window to loose focus when that code is run.

When I know which window is #1, and the window’s name is stored in the array, I would like then to just simply use the String value of the window name to set it’s focus.

Otherwise, I have to use a Select Case statement to evaluate if the string value is then, etc etc.

Kind of convoluted it seems but it’s just an idea I came up with, not knowing a better way. It does work … I was just hoping to get around writing a Select Case statement.

Years ago, when I programmed in Clipper, this was possible and it made for some very slick code. If I remember correctly, preceding a string variable with && (or something like that) would use the word contained within the variable as if it was the name of something.
You could do much more than just that with it too.

Why not use an array of type Window instead of String.

Property: myWindowArray() as Window

Create next window:
dim w as someWindow
myWindowArray.Insert(0, w)

Close the current window:
dim n as integer
n = myWindowArray(self)
if n>= 0 then myWindowArray.Remove(n)
myWindowArray(0).Show // give the first window focus

[quote=53675:@Tim Hare]Why not use an array of type Window instead of String.

Property: myWindowArray() as Window

Create next window:
dim w as someWindow
myWindowArray.Insert(0, w)

Close the current window:
dim n as integer
n = myWindowArray(self)
if n>= 0 then myWindowArray.Remove(n)
myWindowArray(0).Show // give the first window focus[/quote]

I’ll give it a shot.

OK, tried it, get errors all over the place.

as an example…
Doesn’t compute “n = myWindowArray(self)” in the Close event of a window. Says Expected Int32 but got wThree.wThree

Sorry, that should be
n = myWindowArray.IndexOf(self)

And you’ll have to think this through a little on your own. The point is, it is perfectly legal to use the windows themselves in the array. And a lot easier code in the long run, too.

[quote=53679:@Tim Hare]Sorry, that should be
n = myWindowArray.IndexOf(self)

And you’ll have to think this through a little on your own. The point is, it is perfectly legal to use the windows themselves in the array. And a lot easier code in the long run, too.[/quote]

Ok, then that brings up a question because in my “test app” for this, I am using a string array of 2 dimensions (columns). Column 1 contains the Window name and Column 2 contains the order it is opened (as explained above).

The question is, can a 2 dimension array contain different data types… myArray(dimension1 as Window, dimension2 as string) and if so, how would I declare / initialize that ?

No. I would keep the array ordered, instead of keeping a separate sequence number. You basically described a stack where you push/pop elements. If you need to track sequence separately, use 2 parallel arrays.