[RESOLVED] using variables in control names
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] using variables in control names

  1. #1
    Join Date
    Oct 2011
    Location
    Visual Basic 2010/ .NET 4.0
    Posts
    6

    [RESOLVED] using variables in control names

    Hello,

    I'm pretty new to VB

    I would like loop through control names at run time. Is it possible to do something like the following:
    Code:
    Dim n As Integer
    n = 0
    
    For n 0 to 15
     Textbox1.Text &= CStr(button(n).name & Environment.Newline
    next n
    Is something like this possible? If so, what is the correct syntax?

    Thank you

  2. #2
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,844

    Re: using variables in control names

    You would have to create a control array to do something like the above.

    You can use a for each loop to loop through the controls on a given form or panel and get something like you seem to be looking for.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: using variables in control names

    Code:
    For Each ctrl As Control In Me.Controls
      MsgBox(ctrl.Name)
    Next

  4. #4
    Join Date
    Oct 2011
    Location
    Visual Basic 2010/ .NET 4.0
    Posts
    6

    Re: using variables in control names

    Thank you,

    I created a control array and it did the trick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center