Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] How To Save Settings and Strings in Your Form [Tut]
#1
Hello everyone, this is a tutorial on how to save settings in VB. Really easy and I just learned something today (5/31/2010) from this that I never tried but should work. Big Grin!

First Step, Open VS2010... Or whatever.

Next, Create a new applicaiton...

Then After done loading

Create 1 Button and then 1 TextBox, and then another textbox... name button: Save Settings.

Go Under Project > "Example Form" Properties...

Next Find The Settings Tab.

Now Edit the Tab that says "Setting" to whatever you want and do not touch the String ComboBox and the User ComboBox.

Now, For the Code of the whole form.

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.Example = (TextBox1.Text) 'Gets the Value of TB1, Sets the String.
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox2.Text = My.Settings.Example 'Loads the String that was set from TB1
    End Sub
End Class

Thats it, this means that when you save settings from textbox1.text, then you open the same form, the settings of textbox1 and loaded under the button into TB2.

Now, For Settings, Like Options. Like This:

Do You Want To Show This Message Ever Again? (Y/N) Message Box Right?.... I Always wanted to know how to do that. Well I just found out, using this method. This is my way, even though there might be a better one this can be temporary... Really Awesome... Watch... Same Instructions. Except. Different Code. Follow Along.

First Step, Open VS2010... Or whatever.

Next, Create a new applicaiton...

Then After done loading

Create 2 Buttons name button1: Will Be Hidden/Non Hidden, button2's name will be: Hide on Next Form Startup.

Go Under Project > "Example Form" Properties...

Next Find The Settings Tab.

Now Edit the Tab that says "Setting" to "HiddenYes" without Quotes. and do not touch the String ComboBox and the User ComboBox, but edit the value to: "Yes" without quotes.

Now Erase All The Code in the Form, and Replace with this (WARNING: YOU MUST NAME ALL THE PROPER BUTTONS TEXT TO MATCH THE IMAGE BELOW FOR THIS TO WORK AND NOT GET CONFUSEDSmile

[Image: f9u80.png]

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.HiddenYes = "Yes"
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.HiddenYes = "Yes" Then
            Button2.Hide()
            MsgBox("Button is Hidden", 48, "Hidden Status")
        Else
            If My.Settings.HiddenYes = "No" Then
                Button2.Show()
                MsgBox("Button is Not Hidden", 48, "Hidden Status")
            End If
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        My.Settings.HiddenYes = "No"
    End Sub
End Class


Enjoy, post a comment if you need help. This really works and is Freaking Awesome.
[Image: t5BWm.png]
Reply
#2
Good tutorial, there are some other ways of saving info as well, so that if you use an updater it still keeps the info, like using registry.
Reply
#3
Great tutorial! Big Grin
This might actually be useful to me in the future.
Ninja
Reply
#4
So this can be used for like login information etc in your program?
Reply
#5
(03-23-2011, 04:12 PM)Pyratepig Wrote: So this can be used for like login information etc in your program?

Exactly what it's nearly for
[Image: t5BWm.png]
Reply
#6
I'm sure this will be helpful to beginners. However, I would like to suggest that you change:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.Example = (TextBox1.Text) 'Gets the Value of TB1, Sets the String.
    End Sub

to

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.Example = TextBox1.Text 'Gets the Value of TB1, Sets the String.
    End Sub

As you do not need the parenthesis.
Reply
#7
Great tutorial. Nice work, it could help others in due time.
Reply
#8
(03-24-2011, 03:31 AM)cody8295 Wrote: I'm sure this will be helpful to beginners. However, I would like to suggest that you change:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.Example = (TextBox1.Text) 'Gets the Value of TB1, Sets the String.
    End Sub

to

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.Example = TextBox1.Text 'Gets the Value of TB1, Sets the String.
    End Sub


As you do not need the parenthesis.

No one cared about that comment bro, lol. I couldn't careless...
[Image: t5BWm.png]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to hook the keyboard. [VB.NET] [TuT] Vorfin 92 60,893 09-23-2019, 11:55 AM
Last Post: Jamimartin
  Problem in form Chuggaism 3 2,020 11-07-2013, 06:35 PM
Last Post: AceInfinity
  [VB.NET] Animated Form Extend [SRC] Fragma 6 5,537 10-10-2013, 12:18 PM
Last Post: Saket
  [TUT]Creating Advanced Web Browser with Awesome Theme Imaking31 0 1,320 05-25-2013, 03:12 AM
Last Post: Imaking31
  VB.NET Port Scanner [TUT] Fragma 30 14,434 11-27-2012, 11:26 PM
Last Post: ƃu∀ ıʞƃu∀

Forum Jump:


Users browsing this thread: 3 Guest(s)