
Executing a string as a VB cmd during runtime
Hi Steve,
Yeh, there's probably a few ways you can do this. The first that comes to mind is
reflection, eg :Type.InvokeMember
But it isn't as simple as that <g> The issues are whether these things are defined
at design time WithEvents or not. The reason is, that VB.NET, creates a property
get/set for each control if they are declared as WithEvents, so:
Friend WithEvents foo As Bar
becomes
Private _foo as Bar
Friend Property foo() as Bar
Get
....
End Get
Set
...
End Set
End Property
The reason this is important to know is because if you are after the field, it now
has an "_" at the start of the name and the field is always private. Alternatively
you can invoke the property Get. The following code works on the hidden private
fields:
Dim rdbColor(9) As RadioButton
Dim i as Int32
For i = 1 to 9 ' what happened to item (0) ???
rdbColor(i) = CType(Me.GetType.InvokeMember("_RadioButton" & i, _
Reflection.BindingFlags.GetField Or _
Reflection.BindingFlags.NonPublic Or _
Reflection.BindingFlags.Instance, _
Nothing, Me, Nothing), _
RadioButton)
Next
Quote:
> Hi Bill,
> I'm trying to get a control array assigned to 9 consecutive radio buttons. I
> would like to put it in a for next loop. The code would do the following:
> Dim rdbColor(9) As RadioButton
> rdbColor(1) = RadioButton1
> rdbColor(2) = RadioButton2
> rdbColor(3) = RadioButton3
> ...
> rdbColor(9) = RadioButton9
> Thank you for your help.
> Steve L.
> > Hi Steve,
> > Depends on what you mean by command. You may be able to use reflection,
> > CallByName, or scripting host, or il emit. Just depends on what it is you
> are
> > trying to do.
> > > How does one execute a VB command from a string during runtime. I
> believe it
> > > has to do with the ExecWait command, but I'm not sure. Thank you for
> your
> > > help.
> > > Steve