newbie question : using variable in name

Joined
Mar 13, 2007
Messages
5
Programming Experience
Beginner
Hi

Newbie to vb.net - been playing for around 8 weeks now.

I've got a lump of code that consists of a load of variables that I need to send to my.settings

Currently I've got a long bit of code that looks like this :

din1.Text = My.Settings.d1text
din2.Text =
My.Settings.d2text
din3.Text =
My.Settings.d3text
din4.Text =
My.Settings.d4text
din5.Text =
My.Settings.d5text
din6.Text =
My.Settings.d6text
din7.Text =
My.Settings.d7text
din8.Text =
My.Settings.d8text
din9.Text =
My.Settings.d9text
etc - up to 64

is there a way to do this with a loop

for N = 1 to 64
din(n).text = my.settings.d(n)text
next

Any ideas how I do this ?

Thanks
 
There is, if the controls is in same container you can get the control by name: Me.Controls(controlname)
and setting by name: My.Settings.Item(propertyname)
VB.NET:
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Controls([/SIZE][SIZE=2][COLOR=#a31515]"controlname"[/COLOR][/SIZE][SIZE=2]).Text = [/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.Item([/SIZE][SIZE=2][COLOR=#a31515]"propertyname"[/COLOR][/SIZE][SIZE=2]).ToString[/SIZE]
 
Back
Top