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 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
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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