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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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>
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,417
Members
448,895
Latest member
omarahmed1

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
Back
Top