Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have following code,

My.Settings.h301 = TextBox301.Text
My.Settings.h302 = TextBox302.Text
My.Settings.h303 = TextBox303.Text
My.Settings.h304 = TextBox304.Text
My.Settings.h305 = TextBox305.Text

I want to convert above code like following;

For i = 301 To 305 Step 1
    My.Settings.h & i = TextBox & i.Text
Next

So, please provide me correct for next loop code. Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
493 views
Welcome To Ask or Share your Answers For Others

1 Answer

  • To pass a string as a control name, you can use: ParentControl.Controls("ControlName").
  • To pass a string as an application setting name, you can use: My.Settings("SettingName").

Hence, your code should look something like the following:

For i = 301 To 305 Step 1
    My.Settings("h" & i.ToString) = Me.Controls("TextBox" & i.ToString).Text
Next

Please note that if the parent of your textboxes is not the form, you'll need to replace Me with the parent control name.

Hope that helps :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...