User type parameters

bruno.trudo

Board Regular
Joined
Jan 14, 2004
Messages
98
Hi,

is it possible to use user declared type as a parameter of the method of class. I tryed it, but without success.
i.e.

I have a type declared in module
Public Type AdfPoint
PID as String
.
.
Note as String
End Type

and I would like to declare a method of class
Public Sub Add(Point As AdfPoint)
.
.
End Sub

If I create an instance of this class in code and try to use variable Point as AdfPoint as parameter, VB shows an error Variable required - can't assign to this expression
Is there a solution?
Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

TommyGun

MrExcel MVP
Joined
Dec 9, 2002
Messages
4,202
This was added in a standard module and worked fine. Maybe I am missing your problem...

<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Type</SPAN> MyType
    Name <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    BoardName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Type</SPAN>

<SPAN style="color:#00007F">Public</SPAN> BoardArray() <SPAN style="color:#00007F">As</SPAN> MyType
<SPAN style="color:#00007F">Public</SPAN> BoardCount <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> Add(value <SPAN style="color:#00007F">As</SPAN> MyType)
    BoardCount = BoardCount + 1
    <SPAN style="color:#00007F">ReDim</SPAN> <SPAN style="color:#00007F">Preserve</SPAN> BoardArray(BoardCount - 1)
    BoardArray(BoardCount - 1) = value
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> TestType()
    <SPAN style="color:#00007F">Dim</SPAN> ThisIsMe <SPAN style="color:#00007F">As</SPAN> MyType
    
    <SPAN style="color:#00007F">With</SPAN> ThisIsMe
        .Name = "Tommy"
        .BoardName = "TommyGun"
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
    
    Add ThisIsMe
    
    MsgBox BoardArray(BoardCount - 1).Name & vbNewLine & _
        BoardArray(BoardCount - 1).BoardName
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,091
Messages
5,768,039
Members
425,451
Latest member
JohnBrooksBiddle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top