Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiler Error - Not an Appropriate Name pallaver Excel Discussion (Misc queries) 1 July 16th 08 02:20 AM
Declaring variables in Module vs. Public Jeff Excel Discussion (Misc queries) 5 November 19th 07 08:27 PM
Compiler Error Bobzter100 Excel Discussion (Misc queries) 4 November 10th 07 11:02 AM
Help with compiler error Pank Mehta Excel Programming 1 March 11th 05 12:03 PM
Compiler Error Chris Excel Programming 2 December 9th 04 05:02 PM


All times are GMT +1. The time now is 09:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"