Newbie question: Passing type arrays to functions. 
Author Message
 Newbie question: Passing type arrays to functions.

Below is some code I have been trying to implement:

In a bas file:

Public Type typeMenuItem
    strCaption As String
    bolVisible As Boolean
    bolEnabled As Boolean
End Type

In a class file:

Public Sub StandardMenu(ByRef mnuarrItems() As typeMenuItem)

VB however gives a message about how only public members defined in public
modules can be used.
Of course this is what I am doing.
Does this mean that you can not pass user defined types to a class or am I
missing something?



Sat, 21 Sep 2002 03:00:00 GMT  
 Newbie question: Passing type arrays to functions.
I can't see the problem I would have thought that it would work. However,
you may try the class side using a variant instead and see if that would
work...?


Quote:
> Below is some code I have been trying to implement:

> In a bas file:

> Public Type typeMenuItem
>     strCaption As String
>     bolVisible As Boolean
>     bolEnabled As Boolean
> End Type

> In a class file:

> Public Sub StandardMenu(ByRef mnuarrItems() As typeMenuItem)

> VB however gives a message about how only public members defined in public
> modules can be used.
> Of course this is what I am doing.
> Does this mean that you can not pass user defined types to a class or am I
> missing something?



Sat, 21 Sep 2002 03:00:00 GMT  
 Newbie question: Passing type arrays to functions.
I think the problem may be that you are creating the type within a Private
Class module like a form.  The function will work if you change the public
to private in your sub declaration.  This means that you can only Use Public
if you are creating a Public Object.  If you want other members of the same
project to access this Sub, try declaring it Friend.

If this makes no sense to you, keep in mind I'm not a language major, so
here is the code I tested it on.
In My Form Class
=========================
Option Explicit
Private Sub Command1_Click()
    Dim mnuarr() As mnuItem
    ReDim mnuarr(2)
    mnuarr(0).mnuName = "Blan"
    mnuarr(1).mnuType = "FSDFSD"
    getmnuarr mnuarr
End Sub

Friend Sub getmnuarr(ByRef mnuarr() As mnuItem)
    Debug.Print ("Hi I worked")
End Sub
=========================
In My Module Class
=========================
Option Explicit

Public Type mnuItem
    mnuName As String
    mnuType As String
End Type
=========================

Quote:

>Below is some code I have been trying to implement:

>In a bas file:

>Public Type typeMenuItem
>    strCaption As String
>    bolVisible As Boolean
>    bolEnabled As Boolean
>End Type

>In a class file:

>Public Sub StandardMenu(ByRef mnuarrItems() As typeMenuItem)

>VB however gives a message about how only public members defined in public
>modules can be used.
>Of course this is what I am doing.
>Does this mean that you can not pass user defined types to a class or am I
>missing something?



Sat, 21 Sep 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie question about passing arrays into a sub routine

2. Help: Question about passing user-defined type to a function

3. question on passing and returning arrays from functions

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

5. Question: Passing arrays to functions

6. Question on passing an array to and from a function

7. How to pass an integer array/userdef type array into an Oracle Stored procedure

8. Passing user data type to function causes type mismatch error

9. Convert array of value type to array of reference type

10. Urgent!Passing user defind type array

11. Passing Array or a user defined data type as a parameter to a storedprocedure in Oracle

12. Passing Arrays of Types in Chipmunk Basic?

 

 
Powered by phpBB® Forum Software