Converting String into Object

  • Thread starter Thread starter Rajesh Kr Shukla
  • Start date Start date
R

Rajesh Kr Shukla

Hi There,
Can any one suggest me how to convert the string into object in VB.net.
If you are familier with javascript you can use.

var i = 1
eval("textbox" + i).value = "Hello World"

What is the equivalent of this in VB.net

Cheers..Rajesh
 
Hello,

Rajesh Kr Shukla said:
Can any one suggest me how to convert the string into
object in VB.net. If you are familier with javascript you
can use.

var i = 1
eval("textbox" + i).value = "Hello World"

What is the equivalent of this in VB.net

\\\
Private Function FindControl( _
ByVal ControlName As String, _
ByVal CurrentControl As Control _
) As Control
Dim ctr As Control
For Each ctr In CurrentControl.Controls
If ctr.Name = ControlName Then
Return ctr
Else
ctr = FindControl(ControlName, ctr)
If Not ctr Is Nothing Then
Return ctr
End If
End If
Next ctr
End Function
///

Usage:

\\\
DirectCast(FindControl("btnBla", Me), Button).Enabled = False
///

Notice that the procedure listed above is "slow", if you have to access a
lot of controls by name very often, you should store references to them in a
'Hashtable' object. You can use the name of the control as key.
 
Hi,
Thanks for you reply, but my problem is different. Here I have just
taken the example of TextBox, but in my example I have got a function
which receives parameter as an Object (User defined object not the
controls on form).

That Object name I am creating in runtime.


Cheers..Rajesh
 
Hi Rajesh,

To find an object, 'someone' must know about the object. To find an object
within a set, 'someone' must have a set of references.

If you know in advance that you will need this facility with certain
objects, you can use a class, derived from HashTable, with which you register
those objects when they are created. It could be in a Module for convenience.

If this doesn't address what you're after, can you give us some more
details?

Regards,
Fergus
 
Hi Rajesh,

Basically: No.

Object names are not kept at compilation, they are obliterated. This means
you cannot reference an object by name.

Why do you want to do this? Perhaps we can suggest a better way.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: Hi,
: Thanks for you reply, but my problem is different. Here I have just
: taken the example of TextBox, but in my example I have got a function
: which receives parameter as an Object (User defined object not the
: controls on form).
:
: That Object name I am creating in runtime.
:
:
: Cheers..Rajesh
:
:
:
:
:
:
:
:
: Don't just participate in USENET...get rewarded for it!
 
Hello,

Rajesh Shukla said:
Thanks for you reply, but my problem is different. Here
I have just taken the example of TextBox, but in my
example I have got a function which receives parameter as
an Object (User defined object not the controls on form).

Sorry, I don't understand what you want to do. You may want to have a look
at the 'Activator.CreateInstance' method.
 
Back
Top