Save settings VB.net[Solved]

Posts 1–14 of 14 · Page 1 of 1
Save settings VB.net[Solved]
I was trying to make it where if textbox1.text and textbox2.text is not saved under my.settings.rememberme then a MsgBox would popup everytime the form opens..Otherwise it would not show the Msgbox if they are saved.
I tried different ways of doing this, but none work..Any ideas?
save settings saves all try this

Quote Originally Posted by Hassan View Post
Question:
Solution:

Add the following sub-procedure to your program:

[php]Sub SaveInfo()
Dim file As String = My.Computer.FileSystem.SpecialDirectories.MyDocume nts & "\Settings.txt"
Dim strB As New StringBuilder
For Each n As Object In Me.Controls
If n.GetType.Name = "CheckBox" Then
strB.AppendLine(n.Name & ":" & n.checked)
ElseIf n.GetType.Name = "RadioButton" Then
strB.AppendLine(n.Name & ":" & n.checked)
ElseIf n.GetType.Name = "TextBox" Then
strB.AppendLine(n.Name & ":" & n.text)
End If
Next
My.Computer.FileSystem.WriteAllText(file, strB.ToString, False)
End Sub[/php]Then call it from where ever you want. As an example, call it from the Form's Closing event:

Code:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        SaveInfo()
    End Sub
Then, to retrieve the saved settings add the following sub:

[php]Sub RetrieveInfo()
Dim file As String = My.Computer.FileSystem.SpecialDirectories.MyDocume nts & "\Settings.txt"
Dim x As New IO.StreamReader(file)
While Not x.EndOfStream
Dim curLine As String = x.ReadLine.Trim
If Not curLine = vbNullString Then
If curLine.Contains(":") Then
Dim sp() As String = curLine.Split(":")
If Me.Controls.ContainsKey(sp(0)) Then
Dim C_Obj As Object = Me.Controls(sp(0))
If C_Obj.GetType.Name = "CheckBox" Or C_Obj.GetType.Name = "RadioButton" Then
If sp(1) = "False" Then
C_Obj.checked = False
Else
C_Obj.checked = True
End If
ElseIf C_Obj.GetType.Name = "TextBox" Then
C_Obj.text = sp(1)
End If
End If
End If
End If
End While
x.Dispose()
End Sub[/php]Again, you can call it from where ever you want. As an example, call it on the Form's Load event:

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RetrieveInfo()
    End Sub
And you're done xD.
Quote Originally Posted by willrulz188 View Post
save settings saves all try this
I wasn't trying to do it like that..
Quote Originally Posted by HiddenoO View Post
I wasn't trying to do it like that..
well that is one way to look into /
Quote Originally Posted by willrulz188 View Post
well that is one way to look into /
I'm using the option under properties>>Settings..Lol
Quote Originally Posted by HiddenoO View Post
I'm using the option under properties>>Settings..Lol
ohh now I understand lol my bad
[php]
If My.Settings.RememberMe = String.Empty Then
MsgBox("No settings are saved")
Else
TextBox1.Text = my.settings.RememberMe
End if
[/php]
Quote Originally Posted by Jason View Post
[php]
If My.Settings.RememberMe = String.Empty Then
MsgBox("No settings are saved")
Else
TextBox1.Text = my.settings.RememberMe
End if
[/php]
Awesome, it worked..You're like a God now..
/
Quote Originally Posted by HiddenoO View Post
You're like a God now..
Tell me something I don't know
Quote Originally Posted by Jason View Post


Tell me something I don't know
Compress IP address to 4 characters, like:

192.168.0.1

To Something Like;

RUJF

Quote Originally Posted by Hassan View Post


Compress IP address to 4 characters, like:

192.168.0.1

To Something Like;

RUJF

Weren't you gone? Please stay that way
Quote Originally Posted by Jason View Post


Weren't you gone? Please stay that way
Nigga, you mad cause I gonna rule the sections again ? + I just told a thing you can't do !!
Quote Originally Posted by Hassan View Post


Nigga, you mad cause I gonna rule the sections again ? + I just told a thing you can't do !!
So? You have 6 years of VB/Programming knowledge, I have 7 months...
Quote Originally Posted by Jason View Post


So? You have 6 years of VB/Programming knowledge, I have 7 months...
I just read the following and felt like posting :P

Quote Originally Posted by Jason
Tell me something I don't know
Posts 1–14 of 14 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?