|
-
Sep 9th, 2010, 04:31 AM
#1
Thread Starter
Addicted Member
Property Bag error
I have module with specific Type, and in another I have this
Public Data as tMyType
Public Inp as PropertyBag
I fill Data and tried this :
Data.F1 = 1
Data.F2 = "H"
..
Set Inp = New PropertyBag
Inp.WriteProperty "1", Data
and, on the last line I got Error like
"Only user-definided types definided in public object module can be coerced to or from Variant or passed to late-bound functions."
What can I do ?
-
Sep 9th, 2010, 06:24 AM
#2
PowerPoster
Re: Property Bag error
 Originally Posted by BSA01
I have module with specific Type, and in another I have this
I fill Data and tried this :
and, on the last line I got Error like
"Only user-definided types definided in public object module can be coerced to or from Variant or passed to late-bound functions."
What can I do ?
1st advice: use the varables types in same module that you build the user-type. myabe is why you have the error. don't forget change that user -type to private instead public. i had very times these errors that way i put the user-type with the variable type(in same module) and the user-type in private and not in public.
tell me if works
-
Sep 9th, 2010, 06:57 AM
#3
Re: Property Bag error
When it complains about a "public object module" it means one that is exposed as a COM object, for example a Class or UserControl in an OCX or DLL project. Here "public" has a different meaning from its use as a scope declaration.
-
Sep 9th, 2010, 07:05 AM
#4
PowerPoster
Re: Property Bag error
 Originally Posted by dilettante
When it complains about a "public object module" it means one that is exposed as a COM object, for example a Class or UserControl in an OCX or DLL project. Here "public" has a different meaning from its use as a scope declaration.
sorry can you be more explicit?
-
Sep 9th, 2010, 07:13 AM
#5
Re: Property Bag error
If you make something like an ActiveX DLL project that has Public Types in an exposed Class, then those Types can be used in this way. This works within that project or another project referencing the DLL project.
-
Sep 9th, 2010, 07:16 AM
#6
PowerPoster
Re: Property Bag error
 Originally Posted by dilettante
If you make something like an ActiveX DLL project that has Public Types in an exposed Class, then those Types can be used in this way. This works within that project or another project referencing the DLL project.
thanks for that information
-
Sep 9th, 2010, 08:01 AM
#7
Re: Property Bag error
 Originally Posted by BSA01
...
"Only user-definided types definided in public object module can be coerced to or from Variant or passed to late-bound functions."
What can I do ?
I think replies adequately explained what the problem is. What can you do?
1. One option is to serialize the UDT (user-defined type) and save that way. By serialize, I mean save each part as a separate property. This can be very cumbersome.
2. You can actually save the UDT to file, then read the data back to a byte array via Binary file operations. Propertybags allow you to store byte arrays. But to get it back out of the byte array, store array to file & read it into the UDT via Binary file operations. More cumbersome
3. Build a routine to move your UDT into a medium that can be stored in a property bag. You would call a Serialize function you create that does this when writing to the propertybag and another Deserialize that reverses the process when reading the propertybag. One option is to convert your UDT to a delimited string and save the string. Another option requires more code since the UDT contains strings, but to convert/combine the UDT into a single byte array.
Others may chime in with other potential solutions.
-
Sep 9th, 2010, 11:12 AM
#8
Re: Property Bag error
 Originally Posted by LaVolpe
Others may chime in with other potential solutions.
Not a potential solution, but a question. What exactly are you trying to achieve? Perhaps a PropertyBag is not the best solution for your problem.
-
Sep 9th, 2010, 08:57 PM
#9
Frenzied Member
Re: Property Bag error
A good example @:Property Persistence of Array or UDT data by billmccarthy
UDT <---> String
http://visual-basic.itags.org/visual-basic/395476/
Last edited by Jonney; Sep 10th, 2010 at 01:47 AM.
Reason: UDT <---> String
-
Sep 10th, 2010, 09:03 AM
#10
Thread Starter
Addicted Member
Re: Property Bag error
 Originally Posted by joaquim
1st advice: use the varables types in same module that you build the user-type. myabe is why you have the error. don't forget change that user -type to private instead public. i had very times these errors that way i put the user-type with the variable type(in same module) and the user-type in private and not in public.
tell me if works 
No, it doesn't work.
Someone asked what I want. I want to store some data. i could use database, but I want try this, and I think it's more simple than using database, because i don't have a lot of data.
I'll try using NAME property in property bag for parsing data
like :
Type A
A as string
B as string
End Tpye
Dim C as A
Dim PB as PropertyBag
PB.write.. "0-0" - for C.A
PB.write.. "0-1" - for C.B
and so on
-
Sep 10th, 2010, 09:13 AM
#11
Re: Property Bag error
You can store UDTs to file and read them back using Binary file operations. Unsure of the advantage that a propertybag gives you?
Edited: Good manipulation trick Jonney
 Originally Posted by Jonney
Last edited by LaVolpe; Sep 10th, 2010 at 11:25 AM.
-
Sep 10th, 2010, 01:03 PM
#12
Thread Starter
Addicted Member
Re: Property Bag error
 Originally Posted by LaVolpe
You can store UDTs to file and read them back using Binary file operations. Unsure of the advantage that a propertybag gives you?
Edited: Good manipulation trick Jonney
Thank you for advice, it's better solution and I don't need Propertybag.
-
Sep 10th, 2010, 01:14 PM
#13
Re: Property Bag error
One obvious alternative is to forget about either UDTs or PropertyBags.
You can use a fabricated ADO Recordset instead and get a lot more functionality than something as crude as an array of UDTs offers. These can also be persisted to disk or a byte array and loaded back as needed too.
This means you get many of the benefits of using data access objects (such as data binding) without the need to use a database.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|