W
Wang
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
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