PC Review


Reply
Thread Tools Rate Thread

Adding user type variable to dictionary

 
 
Jonathan Blitz
Guest
Posts: n/a
 
      30th May 2004
I have defined a user type and wish to add it to a Dictionary as the value
with a string as the key.
I get the following error:

Only public user defined types in public object modules can be used as
parameters or return types for public procedures of class modules or as
fields of public user defined types.

The online help says:

This error has the following cause and solution:
a.. You attempted to use a public user defined type as a parameter or
return type for a public procedure of a class module, or as a field of a
public user defined type. Only public user defined types that are defined in
a public object module can be used in this manner.
But I am in a public module and the type is defined as a public type.
So what am I doing wrong?


--
Jonathan Blitz
AnyKey Limited
Israel

"When things seem bad
Don't worry and shout
Just count up the times
Things have worked themselves out."


 
Reply With Quote
 
 
 
 
John Nurick
Guest
Posts: n/a
 
      30th May 2004
Hi Jonathan,

I can't really understand the help message, but there's an explanation
here that appears relevant (it's a long URL so watch out for line breaks
inserted by the newsgroup software):


http://groups.google.co.uk/groups?q=...ftngp02&rnum=2

which appears to say there's no easy way of doing what you want. However
you can probably work round it by replacing your UDT with a class with
properties that correspond to the fields in the UDT.

Here's the code from class module I just tried out:
'------------------------
'clsTest
Option Compare Database
Option Explicit

Dim m_Name As String
Dim m_Number As Long

Property Let Name(S As String)
m_Name = S
End Property

Property Get Name() As String
Name = m_Name
End Property

Property Let Number(N As Long)
m_Number = N
End Property

Property Get Number() As Long
Number = m_Number
End Property
'------------------------------


And here's the code from a code module that shows it working:
'------------------------------
Option Explicit

Dim dicD As New Scripting.Dictionary

Sub AddToDic(T As clsTest, K As String)
dicD.Add K, T
End Sub

Sub TestCT()
Dim T As clsTest

Set T = New clsTest
T.Name = "This is my name"
T.Number = 1
AddToDic T, "One"

Set T = New clsTest
T.Name = "Another Name"
T.Number = 2
AddToDic T, "Two"

Debug.Print "One", dicD("One").Name
Debug.Print "Two", dicD("Two").Name

dicD.RemoveAll
Set dicD = Nothing
End Sub
'-------------------------------



On Sun, 30 May 2004 13:25:05 +0200, "Jonathan Blitz"
<((jb))@anykey.co.il (remove brackets)> wrote:

>I have defined a user type and wish to add it to a Dictionary as the value
>with a string as the key.
>I get the following error:
>
>Only public user defined types in public object modules can be used as
>parameters or return types for public procedures of class modules or as
>fields of public user defined types.
>
>The online help says:
>
>This error has the following cause and solution:
> a.. You attempted to use a public user defined type as a parameter or
>return type for a public procedure of a class module, or as a field of a
>public user defined type. Only public user defined types that are defined in
>a public object module can be used in this manner.
>But I am in a public module and the type is defined as a public type.
>So what am I doing wrong?


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Type vs. Variable RyanH Microsoft Excel Programming 1 17th Nov 2008 06:38 PM
Scripting Dictionary to hold User Defined Type billbell52 Microsoft Excel Programming 2 18th Sep 2007 03:59 PM
Defining Variable Type for Items and Keys in Dictionary =?Utf-8?B?RXhjZWxNb25rZXk=?= Microsoft Excel Programming 5 4th May 2007 09:22 PM
Re: clearing a user-defined Type variable Chip Pearson Microsoft Excel Programming 0 28th Dec 2006 06:04 PM
Dictionary object: Error assigning user defined data type to item Paul Urbanus Microsoft Excel Programming 2 1st Dec 2005 04:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:55 AM.