Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

passing a control array to a function

Posted on 2002-04-17
Last Modified: 2010-08-05
Has anyone got an example of how to pass a control array to a function. I have tried both with the parenthesis and withou ..no success. In the function I am iterating through the control array using the count property.

The control array I am passing is a textbox array and I am passing it as a textbox
FuncX(TxtArray() as TextBox)as Boolean


Question by:merlin007
  • 2
  • 2

Accepted Solution

corvanderlinden earned 100 total points
ID: 6947662
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdTest
      Caption         =   "Test"
      Height          =   495
      Left            =   1800
      TabIndex        =   2
      Top             =   1320
      Width           =   1215
   Begin VB.TextBox txtText
      Height          =   315
      Index           =   1
      Left            =   960
      TabIndex        =   1
      Top             =   720
      Width           =   1215
   Begin VB.TextBox txtText
      Height          =   315
      Index           =   0
      Left            =   960
      TabIndex        =   0
      Top             =   360
      Width           =   1215
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdTest_Click()
test txtText
End Sub

Function test(arrtxt As Variant)
    Debug.Print txtText.Count
    Debug.Print txtText(0).Text
    Debug.Print txtText(1).Text
End Function

Author Comment

ID: 6947819
Thanks corvanderlinden.
This works fine.
I was just wondering if is there a way to avoid variants in this case. I am using VB6.

LVL 15

Expert Comment

ID: 6948337
I would suggest "As Object"

Expert Comment

ID: 6949934
Correction :

Function test(arrtxt As Variant)
   Debug.Print arrtxt.Count
   Debug.Print arrtxt(0).Text
   Debug.Print arrtxt(1).Text
End Function

I do not think you can avoid the variants
If you want early binding a possible solution is :

Function test(arrtxt As Variant)
   Dim ctl As TextBox
    Set ctl = arrtxt(0)
    Debug.Print "early bound : " & ctl.Text
End Function

Author Comment

ID: 6950118
Thanks corvanderlinden.
I had spotted the typo.
I will use your last suggestion later on


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question