Results 1 to 8 of 8

Thread: [RESOLVED] Passing Control Arrays

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Resolved [RESOLVED] Passing Control Arrays

    I have these five Sets of control arrays:
    lblComponent() (0to3)
    lblTheme() (0to2)
    lblClock() (0to1)
    lblClickWheel (only 1)
    lblContacts() (0to1)

    These are menu items, and I am moving these items from right to left and vice versa, so basically I am just using the Left, Right, Width and Visible properties. I am using a timer to move the items.

    What I want to know is that is there any possible method to pass these control arrays (i.e their names, and the upper bound values). It would be a lot easier for me to be able to pass these control arrays and it would save me a lot of repetitive coding.

    Thanx for your help in advance
    Hey... If you found this post helpful please rate it.

  2. #2

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Passing Control Arrays

    If it's the former then you can perhaps build on this.

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     MySub Text1 ' a control array
    4.    
    5. End Sub
    6.  
    7. Public Sub MySub(CtlArray As Variant)
    8.  
    9.     MsgBox CtlArray.Count
    10.    
    11. End Sub

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Passing Control Arrays

    I've always used Variant as MartinLiss showed.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Re: Passing Control Arrays

    I want to pass the control arrays itself... Heres An Example

    VB Code:
    1. Private Sub tmrTimer_Timer()
    2.     Call Procedure(send all the members of a certain control array)
    3. End Sub
    4.  
    5. Public Sub Procedure(lblLabel As Label)' Recieve All The Members of the Array
    6.    Dim intCount As Integer
    7.    For intCount = 1 to X 'The Upper Bound Value
    8.          lblLabel(intCount).Left = lblLabel.Left - 507
    9.    Next intCount
    10. End Sub

    The timer gets enabled when a command button is clicked.

    The Question is, how do I send the name of the array and the number of members in the array. And how do I recieve it?
    Last edited by khanjan_a2k; Dec 27th, 2006 at 06:27 PM.
    Hey... If you found this post helpful please rate it.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Re: Passing Control Arrays

    Oh I actually used your procedure Martin and it worked out fine. I just added the following line to get the upperbound value

    VB Code:
    1. Dim intUB As Integer
    2. intUB = CtlArray.Count - 1

    Thanx a lot.
    Hey... If you found this post helpful please rate it.

  7. #7
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] Passing Control Arrays

    You can also pass it as a String:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     MySub "Label1" 'control array name...
    5. End Sub
    6.  
    7. Private Sub MySub(sControl As String)
    8.     Dim N As Long
    9.         For N = Me.Controls(sControl).LBound To Me.Controls(sControl).UBound
    10.             Me.Controls(sControl)(N).Caption = N 'or something...
    11.         Next N
    12. End Sub

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [RESOLVED] Passing Control Arrays

    I would pass the control array As Object rather than As Variant

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