Results 1 to 24 of 24

Thread: [RESOLVED] Save Settings using button?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Resolved [RESOLVED] Save Settings using button?

    I want it so that when i click button2, all the settings like, font color for example, will be save to a .ini or .xml(which ever one is better). What do i need to do for this ? Thanks!

  2. #2

    Re: Save Settings using button?

    You could use My.settings to store all of this information. In your button click event, just type in
    vb Code:
    1. My.settings.save

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    It didn't work =\

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Save Settings using button?

    Quote Originally Posted by x DeaDLy View Post
    It didn't work =\
    Remember the comment on your other thread about thinking?

    What do you want to save? formlesstree has shown you how you can save your settings - its up to you to decide which settings to save and what you want to call them.

    If you want to know more about my.settings try reading the documentation or googling. Here's an article : http://www.devsource.com/c/a/Languag...tion-Settings/

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Save Settings using button?

    "It didn't work =\" - unfortunately that doesn't tell us anything.

    1) what code did you try?
    2) Did you get an error?
    3) If so, what was the error?
    4) If NOT, then what happened that shouldn't have happened? What didn't happen that should have?
    5) Post any and all relevant code.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Save Settings using button?

    You can use PropertyBindings which take no code.

    In Design View, click your button once, then open the Properties Panel and click the + at the top to expand "(ApplicationSettings)".

    Then click "(PropertyBindings") and once it's highlighted click the "..." button that appears. Then go through the list of properties and when you find one you want to save, click it once to highlight it, then from the drop down box click New and create a name for the setting. Then click OK and your program will save it and load it for you.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    Sorry guys, idk y im acting like this today. Ok what I am trying to do is save the forecolor change of label1. here is my entire project code:
    Code:
    Public Class Form1
        Dim instance As ColorDialog
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim MyDialog As New ColorDialog
            MyDialog.Color = Label2.ForeColor
            MyDialog.Color = Label1.ForeColor
            MyDialog.Color = CheckBox1.ForeColor
            If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
                Label2.ForeColor = MyDialog.Color
                Label1.ForeColor = MyDialog.Color
                CheckBox1.ForeColor = MyDialog.Color
            End If
        End Sub
    
    Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
    
        End Sub
    End Class
    I tried what you told me to do Vectris but the, Forecolor change of the label won't save. Like the default color is black, i change it to red, hit the "Save" button. close the form and open it back up, but the change of forecolor of the label did not get saved. my friend used a .ini file to save his color change in delphi. Thanks hope this clears things out. Again i apologize for my behavior

  8. #8
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Save Settings using button?

    You shouldn't have any Save button, just follow the instructions I gave you and as long as you close form without Pressing the Stop button on the debug it will save.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    "In Design View, click your button once, then open the Properties Panel and click the + at the top to expand "(ApplicationSettings)"." Click what button once? and I just want to know how to save the changes using an .ini file. Thanks for you help

  10. #10

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    Ok i found out how to create a .ini file using the code:
    Code:
    Public Function App_Path() As String
            Return System.AppDomain.CurrentDomain.BaseDirectory()
        End Function
        Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
            objWriter = New StreamWriter(App_Path() & "\test.ini")
            objWriter.WriteLine(Label1.ForeColor)
            objWriter.WriteLine(Label2.ForeColor)
            objWriter.Close()
        End Sub
    but wen i save it, it saves it shows up in the .ini file when i open it, but it does not load my configuration, like i set the label1.forecolor to red using colordialog. how wud i load the .ini file? Thanks

  11. #11
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628

    Re: Save Settings using button?

    StreamReader?

  12. #12

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    Quote Originally Posted by BillBoeBaggins View Post
    StreamReader?
    Can you give me a code to set it up please? Thanks

  13. #13
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628

    Re: Save Settings using button?

    I am willing to bet it is almost exactly the reverse of what your doing now.
    Reverse your assignments. Change an object from a Writer to a Reader.

    You'll appreciate it more if you figure it out on your own.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    ok i made the streamreader but don't know how to make it read my "test.ini" for the forecolor. Here is what i typed for the StreamWriter:
    Code:
    Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
            objWriter = New StreamWriter(App_Path() & "\test.ini")
            objWriter.WriteLine("[Color]")
            objWriter.Write(ColorDialog1.Color)
            objWriter.Close()
            MsgBox("Saved!")
        End Sub
    and here is the StreamReader code:
    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            objReader = New StreamReader(App_Path() & "\test.ini")
            objReader.Read()
        End Sub
    also, do i put the streamreader in the Form1_load? Thanks!

  15. #15
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628

    Re: Save Settings using button?

    For your StreamReader piece.
    1. You will need to use the ReadLine() method
    2. You will need to loop through the file using I believe the Peek method (Testing for End of File)
    3. You will need to assign the values "Read" and load them into the associated properties in the correct order as they were written.

    I forget the firiing order of events so I am not sure if Form_Load is best as I am not sure if the Objects even exist at this point.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    Im tryin will know if i succeed

  17. #17

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    Did not succeed, here is the code for streamwriter and reader:
    Code:
    Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
            objWriter = New StreamWriter(App_Path() & "\test.ini")
            objWriter.WriteLine("[Color]")
            objWriter.Write(Label1.ForeColor)
            objWriter.Close()
            MsgBox("Saved!")
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim EntireFile As String
            objReader = New StreamReader(App_Path() & "\test.ini")
            EntireFile = objReader.ReadToEnd()
            objReader.Close()
        End Sub

  18. #18
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628

    Re: Save Settings using button?

    I have nothing to test this code on.
    I am sure people could think of better ways of storing/pulling the data out/in but that is my sample, and that demonstrates what you need.
    vb Code:
    1. Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
    2.         objWriter = New StreamWriter(App_Path() & "\test.ini")
    3.         objWriter.WriteLine("[Color]" & label1.ForeColor )
    4.         objWriter.Close()
    5.         MsgBox("Saved!")
    6.     End Sub
    7.  
    8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    9.         'Dim EntireFile As String
    10.         Dim OneLine As String
    11.  
    12.         objReader = New StreamReader(App_Path() & "\test.ini")
    13.         OneLine = objReader.ReadLine()
    14.         objReader.Close()
    15.     End Sub
    16.     Label1.ForeColor=Right(OneLine,Len(OneLine)-7)

  19. #19
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Save Settings using button?

    Quote Originally Posted by x DeaDLy View Post
    "In Design View, click your button once, then open the Properties Panel and click the + at the top to expand "(ApplicationSettings)"." Click what button once? and I just want to know how to save the changes using an .ini file. Thanks for you help
    What button? What's the button that your trying to save the color of? That's the button.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  20. #20

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    Thanks man oh ya where do i put the
    Label1.ForeColor=Right(OneLine,Len(OneLine)-7) ?
    and it gives me an Error where it says "Right" on that same line, i will try to figure it out though

  21. #21

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    Quote Originally Posted by Vectris View Post
    What button? What's the button that your trying to save the color of? That's the button.
    Sorry, found out what you were talking about, thx for being patient =]

  22. #22
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628

    Re: Save Settings using button?

    gives me an Error where it says "Right" on that same line, i will try to figure it out though
    It is probably not a VB.Net supported function so you would need to find an equivalent.

    where do i put the
    Label1.ForeColor=Right(OneLine,Len(OneLine)-7) ?
    Anywhere after you retrieve the value. You could dump it into a variable and then use it later if you wanted.

  23. #23
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Save Settings using button?

    Quote Originally Posted by x DeaDLy View Post
    Sorry, found out what you were talking about, thx for being patient =]
    Well now that you know try it out. If you do it right you can skip all this coding stuff.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  24. #24

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Save Settings using button?

    LoL ya i did ahaha thx much man!

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