|
| Author |
Message |
budgie
Joined: 04 Oct 2007 Posts: 40
|
Posted: Tue Feb 14, 2006 12:07 am Post subject: There has to be an easier way .... |
|
|
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.
Archived from group: microsoft>public>vb>dos |
|
| Back to top |
|
 |
Stephen Howe
Joined: 04 Oct 2007 Posts: 59
|
Posted: Mon Feb 13, 2006 8:22 pm Post subject: Re: There has to be an easier way .... |
|
|
> 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 |
|
| Back to top |
|
 |
budgie
Joined: 04 Oct 2007 Posts: 40
|
Posted: Tue Feb 14, 2006 4:50 am Post subject: Re: There has to be an easier way .... |
|
|
On Mon, 13 Feb 2006 15:22:36 -0000, "Stephen Howe"
wrote:
>> 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. |
|
| Back to top |
|
 |
Stephen Howe
Joined: 04 Oct 2007 Posts: 59
|
Posted: Mon Feb 13, 2006 9:16 pm Post subject: Re: There has to be an easier way .... |
|
|
> 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 |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Mon Feb 13, 2006 5:57 pm Post subject: Re: There has to be an easier way .... |
|
|
budgie wrote:
>> 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.
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/ |
|
| Back to top |
|
 |
budgie
Joined: 04 Oct 2007 Posts: 40
|
Posted: Tue Feb 14, 2006 2:09 pm Post subject: Re: There has to be an easier way .... |
|
|
On Mon, 13 Feb 2006 12:57:41 -0800, "Karl E. Peterson" wrote:
>budgie wrote:
>>> 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.
>
>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. |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Mon Feb 13, 2006 10:23 pm Post subject: Re: There has to be an easier way .... |
|
|
budgie wrote:
>> 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?
> 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/ |
|
| Back to top |
|
 |
budgie
Joined: 04 Oct 2007 Posts: 40
|
Posted: Tue Feb 14, 2006 2:26 pm Post subject: Re: There has to be an easier way .... |
|
|
On Mon, 13 Feb 2006 16:16:02 -0000, "Stephen Howe"
wrote:
>> There HAS to be an *elegant* way.
>
>Such as?
That WAS the theme of my original question.
>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.
>I don't consider a FOR loop that inelegant - it saves repeated lines.
by repeating one line. Hmmmm .. |
|
| Back to top |
|
 |
Ileana Garza Tovar
Joined: 04 Oct 2007 Posts: 7
|
Posted: Thu Apr 13, 2006 12:55 pm Post subject: Re: There has to be an easier way .... |
|
|
"budgie" escribió en el mensaje @4ax.com...
> 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 |
|
| Back to top |
|
 |
budgie
Joined: 04 Oct 2007 Posts: 40
|
Posted: Fri Apr 14, 2006 6:36 pm Post subject: Re: There has to be an easier way .... |
|
|
On Thu, 13 Apr 2006 08:55:35 -0500, "Ileana Garza Tovar"
wrote:
>"budgie" escribió en el mensaje
>@4ax.com...
>> 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. |
|
| Back to top |
|
 |
Ileana Garza Tovar
Joined: 04 Oct 2007 Posts: 7
|
Posted: Mon Apr 17, 2006 3:10 am Post subject: Re: There has to be an easier way .... |
|
|
"budgie" escribió en el mensaje @4ax.com...
> On Thu, 13 Apr 2006 08:55:35 -0500, "Ileana Garza Tovar"
> wrote:
>
> 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 |
|
| Back to top |
|
 |
budgie
Joined: 04 Oct 2007 Posts: 40
|
Posted: Mon Apr 17, 2006 8:30 pm Post subject: Re: There has to be an easier way .... |
|
|
On Sun, 16 Apr 2006 23:10:04 -0500, "Ileana Garza Tovar"
wrote:
>"budgie" escribió en el mensaje
>@4ax.com...
>> On Thu, 13 Apr 2006 08:55:35 -0500, "Ileana Garza Tovar"
>> wrote:
>>
>> 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. |
|
| Back to top |
|
 |
Ileana Garza Tovar
Joined: 04 Oct 2007 Posts: 7
|
Posted: Mon Apr 17, 2006 11:50 am Post subject: Re: There has to be an easier way .... |
|
|
"budgie" escribió en el mensaje @4ax.com...
> On Sun, 16 Apr 2006 23:10:04 -0500, "Ileana Garza Tovar"
> wrote:
>
>>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
|
|
| Back to top |
|
 |
|
|