CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2001
    Posts
    2

    structured control/field names

    I have a number of tables & forms, in each of which some (but not all) of the field / control names are structured in some way, eg:
    A1, A2, A3, A4, A5, B1, B2 .... D4, D5.
    I have to perform an identical operating on each in turn, and would like to capitalise on their naming structure, e.g.:

    dim counter1 as integer, counter2 as integer
    for counter1 = 1 to 5 ' or do while, or whatever
    for counter2 = 1 to 5
    'do something to me!<counter1><counter2>
    next
    next




    Can this be done, and what is the syntax to denote some or all of the field / control name with a variable?

    Thanks, Linnet



  2. #2
    Join Date
    Sep 2000
    Location
    Ottawa, Ontario
    Posts
    356

    Re: structured control/field names

    there are 2 ways of doing this. first of all you can create a control array by setting the index property for the controls on a form (like textbox)
    and give all the textboxs the same name. Then you would refercance them by textbox(x).Text = "text"
    OR
    create a new project
    create 3 textboxs in the form
    copy this code in
    Private Sub Form_Load()
    Dim MyTextBox As TextBox

    For Each MyTextBox In Me
    MyTextBox.Text = "Hi there"
    Next MyTextBox
    End Sub

    Jean-Guy


  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: structured control/field names

    You can return a control from the Controls collection by name thus if you have ten textboxes called Text1 to Text10 you could cpitalise the text in them thus:


    Dim nItem as Integer

    for nItem = 1 to 10
    me.Controls("Text" & nItem).Text = UCase(me.Controls("Text" & nItem).Text)
    next nItem




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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