Results 1 to 17 of 17

Thread: Saving object values in a textfile.

  1. #1

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Saving object values in a textfile.

    How do I save objects values in a textfile? Particularly the backcolour of an object? This is what I have:

    VB Code:
    1. Function SaveFile()
    2.         FileOpen(1, Application.StartupPath & "config.ini", OpenMode.Output)
    3.         PrintLine(1, TreeView1.BackColor)
    4.         FileClose(1)
    5.     End Function
    But it's throwing an exception:

    -------------------------------------------------------------------
    An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll

    Additional information: File I/O with type 'Color' is not valid.
    -----------------------------------------------------------------------


    Any help on how to save objects values in a textfile?

    Thanks.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    write the .Name property of the color, and then when you load it again, use the Color.FromName(string sName) function. This assumes that you're using named colors.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I would also recommend that you use an xml config file instead of the old school ini files. That is the direction everything is going especially with .net.

  4. #4

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    ..use the Color.FromName(string sName) function.
    I'm not quite sure how to do this (the on-line help is usless!). I have this:
    VB Code:
    1. TreeView1.BackColor.Name = Color.FromName(sTemp)
    but I guess this isn't right as it's giving me a blue squiggle Any help would be appreciated.

    ..I would also recommend that you use an xml config file instead of the old school ini files.
    I'm unfamiliar with xml at the moment, but eventually...
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  5. #5

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Anybody help
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Whats the value of sTemp?

    Actually I see the trouble you are trying to set the name but Color.FromName gets a color object based on the name so it is not a string value its a color value. Try this:

    Treeview1.BackColor = Color.FromName(sTemp)

  7. #7

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    The value of sTemp is ffc0ffff and I did as you suggested Edneeis, but I get:

    ----------------------------------------------------------------------
    An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

    Additional information: This control does not support transparent background colors.
    ----------------------------------------------------------------------


    As far as i'm aware, i'm not setting any transpaernt background colours!

    Here's the two functions i'm using for loading and saving:

    VB Code:
    1. Function LoadFile()
    2.         Dim sTemp As String
    3.         FileOpen(1, Application.StartupPath & "\config.ini", OpenMode.Input)
    4.         sTemp = LineInput(1)
    5.         TreeView1.BackColor = Color.FromName(sTemp)
    6.         FileClose(1)
    7.     End Function
    8.  
    9.     Function SaveFile()
    10.         FileOpen(1, Application.StartupPath & "\config.ini", OpenMode.Output)
    11.         PrintLine(1, TreeView1.BackColor.Name)
    12.         PrintLine(1, TreeView1.ForeColor.Name)
    13.         FileClose(1)
    14.     End Function
    and the config.ini file only holds the value ffc0ffff
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It should be used like this:
    TreeView1.BackColor.Name = Color.FromName("Red")

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Also check out the ColorTranslator class if you need to do some form of conversion between color formats. It has OLE, Win32, and HTML.

  10. #10

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Originally posted by Edneeis
    It should be used like this:
    TreeView1.BackColor.Name = Color.FromName("Red")
    I understand what you mean Edneeis, but the weird thing is that this:
    VB Code:
    1. PrintLine(1, TreeView1.BackColor.Name)
    gives me a number like this: ff008040

    While this:
    VB Code:
    1. PrintLine(1, TreeView1.[i]Fore[/i]Color.Name)
    gives me an actual colour name - white
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  11. #11

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Right, it seems that some colours in a ColorDialog() return names while some return numbers.

    Is there any way to specify only named colours from a ColorDialog() without having a list of them to pick from?
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Is it a greenish color?

    try this:
    VB Code:
    1. TreeView1.BackColor=ColorTranslator.FromHtml("#ff008040")

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yeah that should do it just Try..Catch it and in the catch add a "#" to the front and try it again.

    VB Code:
    1. Try
    2.             treeview1.BackColor = Color.FromName(sTemp)
    3.         Catch
    4.             treeview1.BackColor = ColorTranslator.FromHtml("#" & sTemp)
    5.         End Try

  14. #14

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Angry

    Bah! I think i'll give up. Your above suggestion does work.... if the colour isn't a word ("white", "green", "blue") and your other suggestion with Color.FromName works if it isn't a number! And it can be either!!!

    I thinks i'll just have a list of colours to pick from instead of a ColorDialog()

    Thanks for everyone's help on this
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  15. #15
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Originally posted by Edneeis
    Yeah that should do it just Try..Catch it and in the catch add a "#" to the front and try it again.

    VB Code:
    1. Try
    2.             treeview1.BackColor = Color.FromName(sTemp)
    3.         Catch
    4.             treeview1.BackColor = ColorTranslator.FromHtml("#" & sTemp)
    5.         End Try
    Did we cross posts because this should cover both names and numbers?

  16. #16

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    I think we did! Another frustration eased by the mighty Edneeis!
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  17. #17
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well I don't know about mighty but I'm glad I could help.

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