Discussion:
There has to be an easier way ....
(too old to reply)
budgie
2006-02-13 11:07:18 UTC
Permalink
Maybe I'm having a really bad night, but I'm stumped.

As a (very) occasional VBDOS user, I have a control array with N option buttons.
At the end of user selection, the index value can obviously be anything from 1
to N (I don't use zero). But when it comes to putting the final index value
into a variable,I can't find an elegant way, and I am stuck with

IF Option2(1).Index =true THEN X=1
IF Option2(2).Index =true THEN X=2
IF Option2(3).Index =true THEN X=3
IF Option2(4).Index =true THEN X=4
IF Option2(5).Index =true THEN X=5
.......

or an equally inelegant CASE SELECT scenario.

Obviously I could run a loop testing for true, but surely there is a generic way
to somehow say X = Option2.Index in one line.

Suggestions? Be gentle, I get near VBDOS about once every several years.
Stephen Howe
2006-02-13 15:22:36 UTC
Permalink
Post by budgie
into a variable,I can't find an elegant way, and I am stuck with
IF Option2(1).Index =true THEN X=1
IF Option2(2).Index =true THEN X=2
IF Option2(3).Index =true THEN X=3
IF Option2(4).Index =true THEN X=4
IF Option2(5).Index =true THEN X=5
What about

FOR I = 1 to 5
IF Option2(I).Index =true THEN X= I: EXIT FOR
NEXT

Stephen Howe
budgie
2006-02-13 15:50:31 UTC
Permalink
On Mon, 13 Feb 2006 15:22:36 -0000, "Stephen Howe"
Post by Stephen Howe
Post by budgie
into a variable,I can't find an elegant way, and I am stuck with
IF Option2(1).Index =true THEN X=1
IF Option2(2).Index =true THEN X=2
IF Option2(3).Index =true THEN X=3
IF Option2(4).Index =true THEN X=4
IF Option2(5).Index =true THEN X=5
What about
FOR I = 1 to 5
IF Option2(I).Index =true THEN X= I: EXIT FOR
NEXT
Well, in the next part opf my post I did say:

"Obviously I could run a loop testing for true, but surely there is a generic
way to somehow say X = Option2.Index in one line."

As I have a number of these control arrays, varying in size from two option
button upwards, such a loop test isn't exactly a killer on the short arrays.
There HAS to be an *elegant* way.
Stephen Howe
2006-02-13 16:16:02 UTC
Permalink
Post by budgie
There HAS to be an *elegant* way.
Such as?
There is only a limited number of ways of doing the same thing.
Unless VBDOS hands you it on a plate you have to work.
I don't consider a FOR loop that inelegant - it saves repeated lines.

Stephen
budgie
2006-02-14 01:26:57 UTC
Permalink
On Mon, 13 Feb 2006 16:16:02 -0000, "Stephen Howe"
Post by Stephen Howe
Post by budgie
There HAS to be an *elegant* way.
Such as?
That WAS the theme of my original question.
Post by Stephen Howe
There is only a limited number of ways of doing the same thing.
Unless VBDOS hands you it on a plate you have to work.
I don't mind doing work to get results, but I did (do?) feel that there just
might be a method of directly discovering the control array index value without
a shovel and a torch.
Post by Stephen Howe
I don't consider a FOR loop that inelegant - it saves repeated lines.
by repeating one line. Hmmmm ..
Karl E. Peterson
2006-02-13 20:57:41 UTC
Permalink
Post by budgie
Post by Stephen Howe
What about
FOR I = 1 to 5
IF Option2(I).Index =true THEN X= I: EXIT FOR
NEXT
"Obviously I could run a loop testing for true, but surely there is a
generic way to somehow say X = Option2.Index in one line."
As I have a number of these control arrays, varying in size from two
option button upwards, such a loop test isn't exactly a killer on the
short arrays. There HAS to be an *elegant* way.
Quite often, option buttons are contained within their own frame. A trick
I've used many times (in VB-Windows!) is to get the frame's Tag property to
the Index value whenever an option button is clicked. Then, rather than
query the option button's Value property, I look to the frame's Tag to
quickly determine which option was selected. Make sense?
--
Working without a .NET?
http://classicvb.org/
budgie
2006-02-14 01:09:41 UTC
Permalink
Post by Karl E. Peterson
Post by budgie
Post by Stephen Howe
What about
FOR I = 1 to 5
IF Option2(I).Index =true THEN X= I: EXIT FOR
NEXT
"Obviously I could run a loop testing for true, but surely there is a
generic way to somehow say X = Option2.Index in one line."
As I have a number of these control arrays, varying in size from two
option button upwards, such a loop test isn't exactly a killer on the
short arrays. There HAS to be an *elegant* way.
Quite often, option buttons are contained within their own frame. A trick
I've used many times (in VB-Windows!) is to get the frame's Tag property to
the Index value whenever an option button is clicked. Then, rather than
query the option button's Value property, I look to the frame's Tag to
quickly determine which option was selected. Make sense?
It does make sense. I looked at frame tags but they are string vraiables (in
VBDOS at least). I could set the tag$ to represent the current index value each
time an OB is slected, but it's easier to just set an integer variable at each
click which is where I am currently.

I'm just surprised that - as VBDOS recognises that it is a control array - there
isn't an array index directly accessible somewhere in the system.
Karl E. Peterson
2006-02-14 01:23:16 UTC
Permalink
Post by budgie
Post by Karl E. Peterson
Quite often, option buttons are contained within their own frame. A
trick I've used many times (in VB-Windows!) is to get the frame's
Tag property to the Index value whenever an option button is
clicked. Then, rather than query the option button's Value
property, I look to the frame's Tag to quickly determine which
option was selected. Make sense?
It does make sense. I looked at frame tags but they are string
vraiables (in VBDOS at least). I could set the tag$ to represent the
current index value each time an OB is slected, but it's easier to
just set an integer variable at each click which is where I am
currently.
Yeah, a module level variable is another way to go, for sure. Frames are
just handy, since they're almost always associated with an array of option
buttons. They're there, and probably named similarly, eh?
Post by budgie
I'm just surprised that - as VBDOS recognises that it is a control
array - there isn't an array index directly accessible somewhere in
the system.
Always seemed like a logical thing to me, too, but it bogs down when you
start thinking about how it would actually be implemented. I mean, would
you add a property to the generic Control Array concept specifically for one
type of control? That doesn't make sense. Almost the only other option
would be for Option Buttons to have an index pointing to the selected
element of an array. Then again, there's no forcing you to put them into an
array, right? Real messy.
--
Working without a .NET?
http://classicvb.org/
Ileana Garza Tovar
2006-04-13 13:55:35 UTC
Permalink
Post by budgie
As a (very) occasional VBDOS user, I have a control array with N option buttons.
At the end of user selection, the index value can obviously be anything from 1
to N (I don't use zero). But when it comes to putting the final index value
into a variable,I can't find an elegant way, and I am stuck with
IF Option2(1).Index =true THEN X=1
IF Option2(2).Index =true THEN X=2
IF Option2(3).Index =true THEN X=3
IF Option2(4).Index =true THEN X=4
IF Option2(5).Index =true THEN X=5
.......
or an equally inelegant CASE SELECT scenario.
Hello, Budgie.

What about the following?

Select Case True
Case Option2(1).Index
' Do Anything You Want
Case Option2(2).Index
' Do Another Thing
Case Ad Nauseam
' Do Ad Nauseam things
End Select

Is somewhat Better...

¡Saludos!

Ileana Garza Tovar
budgie
2006-04-14 06:36:37 UTC
Permalink
On Thu, 13 Apr 2006 08:55:35 -0500, "Ileana Garza Tovar"
Post by Ileana Garza Tovar
Post by budgie
As a (very) occasional VBDOS user, I have a control array with N option buttons.
At the end of user selection, the index value can obviously be anything from 1
to N (I don't use zero). But when it comes to putting the final index value
into a variable,I can't find an elegant way, and I am stuck with
IF Option2(1).Index =true THEN X=1
IF Option2(2).Index =true THEN X=2
IF Option2(3).Index =true THEN X=3
IF Option2(4).Index =true THEN X=4
IF Option2(5).Index =true THEN X=5
.......
or an equally inelegant CASE SELECT scenario.
Hello, Budgie.
What about the following?
Select Case True
Case Option2(1).Index
' Do Anything You Want
Case Option2(2).Index
' Do Another Thing
Case Ad Nauseam
' Do Ad Nauseam things
End Select
That was the alternative I mentioned in my post, not much better than the basic
dumb approach.

What I wanted was something that did "X=IndexValue" in a single line in the
CmdOK_Click routine when the user left the form containing the Option array.

In the end, I put "X = Index" in the Option_Click routine and set an initial X
value in case the user left the form with the default option value, without
selecting another option.
Ileana Garza Tovar
2006-04-17 04:10:04 UTC
Permalink
Post by budgie
On Thu, 13 Apr 2006 08:55:35 -0500, "Ileana Garza Tovar"
In the end, I put "X = Index" in the Option_Click routine and set an initial X
value in case the user left the form with the default option value, without
selecting another option.
Maybe you can create a custom function to do that task, that accepts as a
Parameter an x() As Control. Then, the function could return to you the
value of the index that has been selected. If I get some free time, I could
do something like that to help you, but don't be so truthful about my free
time. :-)
--
¡Saludos!

Ileana P. Garza Tovar
budgie
2006-04-17 08:30:00 UTC
Permalink
On Sun, 16 Apr 2006 23:10:04 -0500, "Ileana Garza Tovar"
Post by Ileana Garza Tovar
Post by budgie
On Thu, 13 Apr 2006 08:55:35 -0500, "Ileana Garza Tovar"
In the end, I put "X = Index" in the Option_Click routine and set an initial X
value in case the user left the form with the default option value, without
selecting another option.
Maybe you can create a custom function to do that task, that accepts as a
Parameter an x() As Control. Then, the function could return to you the
value of the index that has been selected. If I get some free time, I could
do something like that to help you, but don't be so truthful about my free
time. :-)
Maybe you misunderstood. It is fixed with one line of code in the Option_Click
routine and one in the setup.
Ileana Garza Tovar
2006-04-17 12:50:23 UTC
Permalink
Post by budgie
On Sun, 16 Apr 2006 23:10:04 -0500, "Ileana Garza Tovar"
Post by Ileana Garza Tovar
Maybe you can create a custom function to do that task, that accepts as a
Parameter an x() As Control. Then, the function could return to you the
value of the index that has been selected. If I get some free time, I could
do something like that to help you, but don't be so truthful about my free
time. :-)
Maybe you misunderstood. It is fixed with one line of code in the Option_Click
routine and one in the setup.
Well... I didn't misunderstood. I saw what you did, and that can be
translated into a disperse Select Case (and no matter what you do, have to
be done with a Select Case one way or another). My proposal was to do a
Function that can verify ANY Option Button control array you pass to it and
get the selected choice without the need to code every Option_Click you have
in the program.
--
¡Saludos!

Ileana P. Garza Tovar
Continue reading on narkive:
Loading...