CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  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
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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
  •  





Click Here to Expand Forum to Full Width

Featured