how to get an object by its name

G

Guest

I need to convert a form in vb6 with several named "lbcol1","lbcol2",...
"lbcol" and so onn array of label
the funtion that in vb6 was alright was:
Private Function GimmeLabel(Index As Integer, Nome As Integer) As VB.Label
Dim Obj As Object
For Each Obj In Me.Controls

If Obj.name = "lbcol" + CStr(Nome) Then
If Obj.Index = Index Then
Set DammiLabel = Obj
Exit For
End If
End If
Next
End Function
How to translate in vb.net
More in general isThere a function in vb.net equlvalent to the
java/actionscript function eval
Thanks best regards
Davide
 
G

Guest

well but The problem is that that i search by name lbcol1 that is defined as
vb6.labelarray that is not a control i need to find the labelarray first
the labelarray class seems don't have got the name property...
any idea don't rewriting all code?


Rob Windsor said:
Accessing controls by their names or indices
http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en

There is no built in equivalent to eval() in VB.NET

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/

DavideR said:
I need to convert a form in vb6 with several named "lbcol1","lbcol2",...
"lbcol" and so onn array of label
the funtion that in vb6 was alright was:
Private Function GimmeLabel(Index As Integer, Nome As Integer) As VB.Label
Dim Obj As Object
For Each Obj In Me.Controls

If Obj.name = "lbcol" + CStr(Nome) Then
If Obj.Index = Index Then
Set DammiLabel = Obj
Exit For
End If
End If
Next
End Function
How to translate in vb.net
More in general isThere a function in vb.net equlvalent to the
java/actionscript function eval
Thanks best regards
Davide
 
K

kevininstructor

I would assume if you want to keep with the same logic then look at the link
Rob provided which also points to "Creating control Arrays in VB.NET" via
MSDN. Another thought would be to find controls with a specific prefix using
the FindControl function listed in the primary link.

DavideR said:
well but The problem is that that i search by name lbcol1 that is defined
as
vb6.labelarray that is not a control i need to find the labelarray first
the labelarray class seems don't have got the name property...
any idea don't rewriting all code?


Rob Windsor said:
Accessing controls by their names or indices
http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en

There is no built in equivalent to eval() in VB.NET

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/

DavideR said:
I need to convert a form in vb6 with several named "lbcol1","lbcol2",...
"lbcol" and so onn array of label
the funtion that in vb6 was alright was:
Private Function GimmeLabel(Index As Integer, Nome As Integer) As
VB.Label
Dim Obj As Object
For Each Obj In Me.Controls

If Obj.name = "lbcol" + CStr(Nome) Then
If Obj.Index = Index Then
Set DammiLabel = Obj
Exit For
End If
End If
Next
End Function
How to translate in vb.net
More in general isThere a function in vb.net equlvalent to the
java/actionscript function eval
Thanks best regards
Davide
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top