Pls help me with this VB6 Code conversion

  • Thread starter Thread starter ErwinRommel
  • Start date Start date
E

ErwinRommel

in VB6, you can refer a control using this;

form1.items("textbox1").text = "Value"

can you help me how to do this in VB.NET.


thanks in advance.
 
I don't know if this is the best or most elegant way, but ...

form1.textbox1.text = "Value"

HTH

Mitch
 
Thanks Mitch. What if I have a variable control name? like this

updatetext("Textbox1"

Public sub updatetext(controlname as string
form1.items(controlname).text = "value
end su

Can you do this in VB.NET?
 
* "ErwinRommel said:
in VB6, you can refer a control using this;

form1.items("textbox1").text = "Value"

can you help me how to do this in VB.NET.

This would not work in VB6, use 'Controls' instead of 'Items'. In
VB.NET, you can add all controls to a 'Hashtable' (use the names as
keys) and then do a lookup in the hashtable.
 
Okay, I see what you're saying, have a look at the forms Controls property.
This is a collection of all the controls on the form. As far as I can see
you need to refer to each control by its index rather than its name, or
cycle through looking for all textbox controls or all label controls eg

dim tb as textbox
for each tb in Form1.Controls
if tb.Name = "textbox1" then
do something
end if
next tb

I haven't played around with Forms.Controls too much so someone out there
may know a better way. If variable control names on a form are really
important for your app, then maybe it would be worth making a custom
collection of textboxes that have keys corresponding to the name of the
individual textboxes.

Good luck

Mitch
 
Back
Top