Solved

passing a control array to a function

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro: print each sheet to pdf using ExportAsFixedFormat 11 48
SLMGR Switches Are Not Working On KMS Host 3 92
VBA Shell can't Find Word document 11 92
RUNRMTCMD from AS/400 12 46
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

770 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