Pass control array to sub/function ? 
Author Message
 Pass control array to sub/function ?

I need to be able to pass a control array to a function

i.e
Dim Ret%
Ret% = TestFunc%(txtField)

Function TestFunc%(Ctrl() as control)
        'do something here
        TestFunc% = True
end function

I keep getting "type mismatch" error - i understand that in VB3 it was not
possible
to pass a control array

I'm using vb4 enterprise edition - is it possible with this version?

I don't want to have to create an ordinary array, copy the control array
values to it and\pass  that array if I can help it

Can anyone help?

Thanks in advance



Fri, 27 Aug 1999 03:00:00 GMT  
 Pass control array to sub/function ?

Harry: I've posted the help article below, but I'm wondering if it applies
to your situation. If you want to look for it, pull up "Difference in
Passing Controls Between Visual Basic 3.0 and Visual Basic 4.0 (ReadMe)" in
your online help. It suggests that you need to explicitly pass the
parameter (your control array) by value.

Hope this works.

Bret

Quote:
>>Begin Help Article:

If you are calling a Function or Sub procedure in a .DLL or .VBX that was
written for Visual Basic 3.0, and the Declare statement for the Function or
Sub has a parameter that is defined As Control, then the correct Visual
Basic 4.0 parameter should have a ByVal preceding the parameter name.  This
is because in Visual Basic 3.0 a parameter defined As Control incorrectly
passed an hCtl (the handle to the control) rather than a pointer to the
hCtl.  Because all other parameters passed by reference (they had no ByVal
preceding them) were passed as pointers to the parameters, the As Control
parameters were an exception which has been corrected in Visual Basic 4.0.
For example, a DLL function such as:

HWND FAR Pascal GetControlHwnd(HCTL hCtl)
{
        return VBGetControlHwnd(hCtl);

Quote:
}

would have a Visual Basic 3.0 declaration of:

Declare Function GetControlHwnd Lib libname.dll (hCtl As Control) _
As Integer

and should have a Visual Basic 4.0 declaration of:

Declare Function GetControlHwnd Lib libname.dll (ByVal hCtl As _
Control) As Integer

Visual Basic 4.0 resolves this problem in the vast majority of the cases,
and can correctly identify the proper value to pass to Visual Basic APIs.
However, to make absolutely sure that the program using this .VBX or .DLL
will be compatible with future releases of Visual Basic, you should follow
the correct methodology in setting parameters.

End Help Article <<



Fri, 27 Aug 1999 03:00:00 GMT  
 Pass control array to sub/function ?

->I need to be able to pass a control array to a function
->
->i.e
->Dim Ret%
->Ret% = TestFunc%(txtField)
->
->Function TestFunc%(Ctrl() as control)
->   'do something here
->   TestFunc% = True
->end function
->
->I keep getting "type mismatch" error - i understand that in VB3 it
was not
->possible
->to pass a control array
->
->I'm using vb4 enterprise edition - is it possible with this version?
->

Use the Object data type in your Function argument declaration.

Paul
~~~~



Sat, 28 Aug 1999 03:00:00 GMT  
 Pass control array to sub/function ?

Hi,

You can also pass it as a variant.

--
=========================
Gurvan Robineau
Invited Researcher
Medical Physics Department
School of Medicine
University of Patras
PO BOX 1410
26500 Patras
Greece

tel. +30 61 996 114
fax +30 61 999 861
=========================



Sat, 28 Aug 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Passing Control Array to a SUB/FUNCTION

2. pass an array as function/sub argument

3. Question on passing array parameters to VB.NET Sub/Function

4. Passing array back from Sub/Function

5. Passing arrays to SUBs and FUNCTIONs

6. Passing arrays from a server-function/sub to a server -variable

7. pass an array as function/sub argument

8. Passing Arrays to Sub / Functions

9. Passing arrays in a sub/function

10. Passing Control Arrays to Sub-Procedures

11. Passing control arrays to subs

12. Q: Passing first (original) element of a control array to a SUB

 

 
Powered by phpBB® Forum Software