Results 1 to 7 of 7

Thread: [RESOLVED] [VB6] - building a new Backcolor property

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Resolved [RESOLVED] [VB6] - building a new Backcolor property

    i build a new property:
    Code:
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
           sprBackColor = PropBag.ReadProperty("sprBackColor", lngBackColor)
    End Sub
    
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
         PropBag.WriteProperty "sprBackColor", sprBackColor, lngBackColor
    End Sub
    
    Public Property Get sprBackColor() As OLE_COLOR
        sprBackColor = lngBackColor
    End Property
    
    Public Property Let sprBackColor(newBackColor As OLE_COLOR)
        lngBackColor = newBackColor
        Call ShowImage
        PropertyChanged "sprBackColor"
    End Property
    my question is: why these property don't save the value from project mode to the run mode?
    (i always recive black color . but if i change in project mode works fine(in project mode). and if i change in run mode, works fine. but if i change for vbyellow, in project mode, i recive black in run mode)
    thanks
    Last edited by joaquim; Nov 28th, 2009 at 02:36 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

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

    Re: [VB6] - building a new Backcolor property

    Because of this line: PropBag.WriteProperty "sprBackColor", sprBackColor, lngBackColor

    The 3rd parameter is the default value. If sprBackColor=lngBackColor, then VB does not write to the propertybag and nothing is written for that property. Well, sprBackColor will always = lngBackColor when writing, so nothing is written. Therefore, the value read is always zero/black.

    Recommend changing your routines....
    Code:
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
           sprBackColor = PropBag.ReadProperty("sprBackColor", vbBlack)
    End Sub
    
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
         PropBag.WriteProperty "sprBackColor", lngBackColor, vbBlack
    End Sub
    The above says that when writing: If lngBackColor is Black, don't write the property else write lngBackColor. When reading: If the property does not exist, use Black else use the value that was written.
    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}

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - building a new Backcolor property

    Quote Originally Posted by LaVolpe View Post
    Because of this line: PropBag.WriteProperty "sprBackColor", sprBackColor, lngBackColor

    The 3rd parameter is the default value. If sprBackColor=lngBackColor, then VB does not write to the propertybag and nothing is written for that property. Well, sprBackColor will always = lngBackColor when writing, so nothing is written. Therefore, the value read is always zero/black.

    Recommend changing your routines....
    Code:
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
           sprBackColor = PropBag.ReadProperty("sprBackColor", vbBlack)
    End Sub
    
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
         PropBag.WriteProperty "sprBackColor", lngBackColor, vbBlack
    End Sub
    The above says that when writing: If lngBackColor is Black, don't write the property else write lngBackColor. When reading: If the property does not exist, use Black else use the value that was written.
    we use, always, a default value and not a variable
    thank you for the advice.
    it's working, thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [RESOLVED] [VB6] - building a new Backcolor property

    i change my property name(only the name): from sprBackColor to BackColor.
    i need ask these: use the VB6, automatic, change to backcolor?
    is because, the backcolor be a property keyword?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [RESOLVED] [VB6] - building a new Backcolor property

    what i mean was: i have 1 property named: "BackColor". but my VB6 change it for "backcolor". why? is because to be a keyword?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

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

    Re: [RESOLVED] [VB6] - building a new Backcolor property

    I see this sometimes. Search your entire ocx project looking for backcolor. When found, ensure it is always spelled the same way. I suspect that "backcolor" is used somewhere in your declaration sections, either in an API parameter, a UDT member, an Enumeration member or something else.
    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}

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [RESOLVED] [VB6] - building a new Backcolor property

    Quote Originally Posted by LaVolpe View Post
    I see this sometimes. Search your entire ocx project looking for backcolor. When found, ensure it is always spelled the same way. I suspect that "backcolor" is used somewhere in your declaration sections, either in an API parameter, a UDT member, an Enumeration member or something else.
    thanks now i resolve these "bug". i have more problems like these, but the most important was these
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

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