Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating runtime Select Case??

Status
Not open for further replies.

debeebop

Programmer
Dec 14, 2005
6
EG
Hello everyone,

After generating an array of option buttons during runtime I am trying to manage the user's actions on them.

How do you actaully manage runtime generated controls?

I have tried to use:
Code:
Private sub Option1(index as integer)
  
Select Case index

Case 1
 'actions
Case 2
 'different actions
.
.
.

End Select

End Sub
But then, the number of Cases should correspond to the number of the generated option buttons.

I appreciate your help everyone.
 
I am no expert and someone else may have an Idea about this. But you are talking about generating code on-the-fly. You might be able to do something like this through VB Scripting. I would be interested to see what anybody else has to say about this. I have been looking for this for a while. Good luck

Scoty ::)
 
Code:
dim cCtl as Control
for each cCtl in Controls
   if TypeOf cCtl is OptionButton Then 
      'do stuff
   end if
next
If you're having trouble with the "do stuff" part, explain more about what you want your buttons to do and I'll see if I can help.

HTH

Bob
 
Bob -
It sounds like each option button instance should do something different. And that's a problem, unless debeebop is able to categorize (refactor) them. It may be possible to put this custom functionality into discrete classes that implement a common Interface, which can be called via CreateObject().

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Well, sort of a problem. Obviously, there's a finite set of buttons that the op has in mind. One has the feeling that he doesn't know how to deal with situations wherein less than all of the buttons are available.

<It may be possible to put this custom functionality into discrete classes that implement a common Interface, which can be called via CreateObject().

Yes, that would be fun, wouldn't it? We'll see what the OP has to say for himself. :)

Scoty, feel free to expand on the "this" that you're looking for also. You aren't in fact talking about generating code on the fly....

Bob
 
Bob,
Yes, the "This" was speaking of generating and executing VBscripts on the fly. But I found something else that may be of use. Right here in our own forum shows how to execute code stored in a string. So if debeebop is loading the parameters of the "Option"s from a datasource they could also store and retrieve the code that particular selection should execute.

It's not truly dynamic but it should work.

Scoty ::)
 
EbExecuteLine, as we have repeatedly explained in this forum, and contrary to multiple incorrect Web postings, is unstable, and does not work at all in compiled programs

An alternative, executing VB Script, might a derivative of my code in thread222-1143404 (and variations in several other threads)
 
strongm,
I posted the suggestion then ran across your thread about scripting. Scripting does run better in compiled enviroment.
Scoty ::)
 
Well, all of that aside (and thanks to strongm for the heads up), I don't believe the OP was talking about generating code on the fly. If the OP cares to weigh in at some point, I'm sure we can help.

Happy New Year,

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top