Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
compiler error: public object module
Dear gurus:
Upon compiling the following code I receive the error message: "Compiler error Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions." Option Explicit Type MyType x As Integer y As Integer End Type Public Sub MyTest() Dim Coord(10) As MyType Call FillCoord(Coord) Call PrintCoord(Coord) End Sub Private Sub FillCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Coordinate(i).x = i + 1 Coordinate(i).y = i + 3 Next i End Sub Public Sub PrintCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Debug.Print Coordinate(i).x, Debug.Print Coordinate(i).y Next i End Sub This piece of code was in Module1 under Modules. In order to avoid the compiler error, I removed the type definition to another module Module2. Now under Modules there are Module1 and Module2. Module1 contains the following code: Option Explicit Public Sub MyTest() Dim Coord(10) As MyType Call FillCoord(Coord) Call PrintCoord(Coord) End Sub Private Sub FillCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Coordinate(i).x = i + 1 Coordinate(i).y = i + 3 Next i End Sub Public Sub PrintCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Debug.Print Coordinate(i).x, Debug.Print Coordinate(i).y Next i End Sub And Module2 contains the following code: Option Explicit Type MyType x As Integer y As Integer End Type But the compiler error remains the same. How should I change the organization of the code to avoid this compiler error? Many thanks in advance! Wang |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
compiler error: public object module
You can put it all in one single module: Private Type MyType x As Integer y As Integer End Type Public Sub Test() Dim Coord(10) As MyType Call FillCoord(Coord()) Call PrintCoord(Coord()) End Sub Public Sub FillCoord(ByRef Coordinate() As MyType) Dim i As Integer For i = 0 To 10 Coordinate(i).x = i + 1 Coordinate(i).y = i + 3 Next i End Sub Public Sub PrintCoord(ByRef Coordinate() As MyType) Dim i As Integer For i = 0 To 10 Debug.Print Coordinate(i).x Debug.Print Coordinate(i).y Next i End Sub "Wang" schreef in bericht ... Dear gurus: Upon compiling the following code I receive the error message: "Compiler error Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions." Option Explicit Type MyType x As Integer y As Integer End Type Public Sub MyTest() Dim Coord(10) As MyType Call FillCoord(Coord) Call PrintCoord(Coord) End Sub Private Sub FillCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Coordinate(i).x = i + 1 Coordinate(i).y = i + 3 Next i End Sub Public Sub PrintCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Debug.Print Coordinate(i).x, Debug.Print Coordinate(i).y Next i End Sub This piece of code was in Module1 under Modules. In order to avoid the compiler error, I removed the type definition to another module Module2. Now under Modules there are Module1 and Module2. Module1 contains the following code: Option Explicit Public Sub MyTest() Dim Coord(10) As MyType Call FillCoord(Coord) Call PrintCoord(Coord) End Sub Private Sub FillCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Coordinate(i).x = i + 1 Coordinate(i).y = i + 3 Next i End Sub Public Sub PrintCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Debug.Print Coordinate(i).x, Debug.Print Coordinate(i).y Next i End Sub And Module2 contains the following code: Option Explicit Type MyType x As Integer y As Integer End Type But the compiler error remains the same. How should I change the organization of the code to avoid this compiler error? Many thanks in advance! Wang |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
compiler error: public object module
Dear Moon,
I've changed the program according to your reply. It works fine! Thank you very much! Wang "moon" wrote: You can put it all in one single module: Private Type MyType x As Integer y As Integer End Type Public Sub Test() Dim Coord(10) As MyType Call FillCoord(Coord()) Call PrintCoord(Coord()) End Sub Public Sub FillCoord(ByRef Coordinate() As MyType) Dim i As Integer For i = 0 To 10 Coordinate(i).x = i + 1 Coordinate(i).y = i + 3 Next i End Sub Public Sub PrintCoord(ByRef Coordinate() As MyType) Dim i As Integer For i = 0 To 10 Debug.Print Coordinate(i).x Debug.Print Coordinate(i).y Next i End Sub "Wang" schreef in bericht ... Dear gurus: Upon compiling the following code I receive the error message: "Compiler error Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions." Option Explicit Type MyType x As Integer y As Integer End Type Public Sub MyTest() Dim Coord(10) As MyType Call FillCoord(Coord) Call PrintCoord(Coord) End Sub Private Sub FillCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Coordinate(i).x = i + 1 Coordinate(i).y = i + 3 Next i End Sub Public Sub PrintCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Debug.Print Coordinate(i).x, Debug.Print Coordinate(i).y Next i End Sub This piece of code was in Module1 under Modules. In order to avoid the compiler error, I removed the type definition to another module Module2. Now under Modules there are Module1 and Module2. Module1 contains the following code: Option Explicit Public Sub MyTest() Dim Coord(10) As MyType Call FillCoord(Coord) Call PrintCoord(Coord) End Sub Private Sub FillCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Coordinate(i).x = i + 1 Coordinate(i).y = i + 3 Next i End Sub Public Sub PrintCoord(Coordinate As Variant) Dim i As Integer For i = 1 To 10 Debug.Print Coordinate(i).x, Debug.Print Coordinate(i).y Next i End Sub And Module2 contains the following code: Option Explicit Type MyType x As Integer y As Integer End Type But the compiler error remains the same. How should I change the organization of the code to avoid this compiler error? Many thanks in advance! Wang |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Compiler Error - Not an Appropriate Name | Excel Discussion (Misc queries) | |||
Declaring variables in Module vs. Public | Excel Discussion (Misc queries) | |||
Compiler Error | Excel Discussion (Misc queries) | |||
Help with compiler error | Excel Programming | |||
Compiler Error | Excel Programming |