Results 1 to 5 of 5

Thread: Syntax question...

  1. #1

    Thread Starter
    Lively Member Rockman's Avatar
    Join Date
    Apr 2001
    Posts
    66

    Question Syntax question...

    I need to reference a control array from a string variable, but the fact that it is an array is causing a syntax problem. This may explain it better...

    THIS WORKS (if I have a text box named txtTest):

    Code:
    Public Sub ChangeText()
    Dim sControlName as String
    
         sControlName = "txtTest"
         Me(sControlName).Text = "foobar"
    
    End Sub

    THIS DOESN'T WORK (if I have a text box array with txtTest(2)):

    Code:
    Public Sub ChangeText()
    Dim sControlName as String
    
         sControlName = "txtTest(2)"
         Me(sControlName).Text = "foobar"
    
    End Sub
    Any help would be most appreciative!
    Jeff

  2. #2
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    This does work...

    VB Code:
    1. Dim sControlName As String
    2.     sControlName = "txtTest"
    3.     Me(sControlName)(2).Text = "foobar"

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  3. #3

    Thread Starter
    Lively Member Rockman's Avatar
    Join Date
    Apr 2001
    Posts
    66
    SUPER Greg!

    Thanks a bunch!
    Jeff

  4. #4
    hellswraith
    Guest
    Another way you can do this:

    VB Code:
    1. Dim sControlName
    2.    
    3.     Set sControlName = txtText(2)
    4.    
    5.     sControlName.Text = "foobar"

  5. #5
    hellswraith
    Guest
    Forgot to add this for control array:
    VB Code:
    1. Dim sControlName
    2.     Dim intCount As Integer
    3.  
    4.     Set sControlName = txtText
    5.    
    6.     For intCount = 0 To 2
    7.        sControlName(intCount).Text = "foobar"
    8.     Next intCount
    9.  
    10.     Set sControlName = Nothing

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