Results 1 to 2 of 2

Thread: For...Next loop for 1-D array and labels

  1. #1

    Thread Starter
    New Member mobius777's Avatar
    Join Date
    Mar 2005
    Posts
    4

    For...Next loop for 1-D array and labels

    Hello Everyone! First post here, hope it won't be my last. Wondering if someone can give me a hand with a problem:

    On the form, I have labels, grouped together, named cell1, cell2, cell3, etc.
    There are 20 cells total, with an integer pre-positioned in each one. I want to simplify the coding so that a For...Next loop will put all those number in the array for me:

    Dim Numbers(19), x As Short

    For x = 0 To 19

    Numbers(x) = cellx.Text

    Next x

    My problem is VB.NET doesn't like using the variable as the cell number ("cellx.Text"). How do I get the variable x to represent the cell number I'm working with for each cycle of the loop?

    I'm sure it's a simple solution, but I'm somewhat new to this.

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: For...Next loop for 1-D array and labels

    Hi,

    Several ways to do this.

    If your label prefix "cell" is unique to the labels you want to access try:

    Dim iCount As integer
    Dim c As Control
    For each c in Me.Controls
    If Microsoft.VisualBasic.left(c.Name,3) = cell then
    c.Text = Mid(c.Name,4,1)
    End If
    next

    If your label names are not unique then put an identifier in the Tag property

    If your labels are in a separate GroupBox etc then use

    For each c in GroupBox1.Controls
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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