Solved

passing a control array to a function

Posted on 2002-04-17
5
142 Views
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

Thanks

Merlin007
0
Comment
Question by:merlin007
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
corvanderlinden earned 100 total points
ID: 6947662
VERSION 5.00
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
   End
   Begin VB.TextBox txtText
      Height          =   315
      Index           =   1
      Left            =   960
      TabIndex        =   1
      Top             =   720
      Width           =   1215
   End
   Begin VB.TextBox txtText
      Height          =   315
      Index           =   0
      Left            =   960
      TabIndex        =   0
      Top             =   360
      Width           =   1215
   End
End
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
0
 

Author Comment

by:merlin007
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.

merlin007
0
 
LVL 15

Expert Comment

by:ameba
ID: 6948337
I would suggest "As Object"
0
 
LVL 2

Expert Comment

by:corvanderlinden
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
0
 

Author Comment

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

Merlin007
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now