[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

passing a control array to a function

Posted on 2002-04-17
5
Medium Priority
?
149 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
[X]
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
5 Comments
 
LVL 2

Accepted Solution

by:
corvanderlinden earned 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Suggested Courses

650 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