By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,576 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,576 IT Pros & Developers. It's quick & easy.

Converting String into Object

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hello,

"Rajesh Kr Shukla" <rk******@india.com> schrieb:
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.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2

P: n/a
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



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

P: n/a
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
Nov 20 '05 #4

P: n/a
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"
"Rajesh Shukla" <rk******@india.com> wrote in message
news:On**************@TK2MSFTNGP10.phx.gbl...
: 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
:
:
:
:
:
:
:
: *** Sent via Developersdex http://www.developersdex.com ***
: Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

P: n/a
Hello,

"Rajesh Shukla" <rk******@india.com> schrieb:
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.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.