Results 1 to 13 of 13

Thread: Property Bag error

  1. #1

    Thread Starter
    Addicted Member BSA01's Avatar
    Join Date
    Apr 2009
    Location
    Bosnia and Herzegovina
    Posts
    146

    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 ?

  2. #2
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: Property Bag error

    Quote Originally Posted by BSA01 View Post
    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  4. #4
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: Property Bag error

    Quote Originally Posted by dilettante View Post
    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  6. #6
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: Property Bag error

    Quote Originally Posted by dilettante View Post
    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Property Bag error

    Quote Originally Posted by BSA01 View Post
    ...
    "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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Property Bag error

    Quote Originally Posted by LaVolpe View Post
    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.

  9. #9
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    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

  10. #10

    Thread Starter
    Addicted Member BSA01's Avatar
    Join Date
    Apr 2009
    Location
    Bosnia and Herzegovina
    Posts
    146

    Re: Property Bag error

    Quote Originally Posted by joaquim View Post
    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

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Quote Originally Posted by Jonney View Post
    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 LaVolpe; Sep 10th, 2010 at 11:25 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    Addicted Member BSA01's Avatar
    Join Date
    Apr 2009
    Location
    Bosnia and Herzegovina
    Posts
    146

    Re: Property Bag error

    Quote Originally Posted by LaVolpe View Post
    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.

  13. #13
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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
  •  



Click Here to Expand Forum to Full Width