We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Saving masked text box

I have a masked text box and two text boxes. I would like to save all of these fields so that when the "open" button is clicked the field repopulate....

anybody have any idea on how to do this?
If so please help me out.

thanks in advance :)

3
Contributors
4
Replies
3 Days
Discussion Span
1 Year Ago
Last Updated
5
Views
ng5
Light Poster
42 posts since Dec 2011
Reputation Points: 19
Solved Threads: 0
Skill Endorsements: 0

Go to the project Properties, then click on "Settings" down the left side. Add as many string variables as you have text boxes to save. For example, if you add the string setting, MyText1 you can load the textbox on form load as

TextBox1.Text = My.Settings.MyText1

and save the value on form close for the next run as

My.Settings.MyText1 = TextBox1.Text

Reverend Jim
Carpe per diem
Moderator
3,615 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32

See if this.post helps for other options.

I personally prefer files to save/load to/from and in your case, I would save each ctl's.Text as a single line, load those lines into an Array and set values to each ctl.Text from there.

codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8

I have 24 textboxes textbox1 textbox2 textbox3 etc, and 11 maskedtextboxes maskedtextbox1 maskedtextbox2 maskedtextbox3 etc

could someone post a code snippet of what this would look like? (maybe one or two of each not all 35 textboxes...) and settings or anything i need to change? thanks much :)

ng5
Light Poster
42 posts since Dec 2011
Reputation Points: 19
Solved Threads: 0
Skill Endorsements: 0

See if this helps.

Imports System.IO
Public Class Form1
    Private myCoolFile As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test.txt" '// your file.

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        File.WriteAllText(myCoolFile, saveCoolControls("TextBox", 3) & vbNewLine & saveCoolControls("MaskedTextBox", 3)) '// overwrite/create file.
    End Sub
    Private Function saveCoolControls(ByVal selCoolControlType As String, ByVal numberOfCoolControls As Integer) As String
        Dim sTemp As String = ""
        For i As Integer = 1 To numberOfCoolControls '// loop thru controls on Form.
            With CType(Me.Controls(selCoolControlType & i), Control) '// locate specified control.
                If Not sTemp = "" Then sTemp &= vbNewLine '// saves lines and adds line.breaks.
                sTemp &= .Name & ":" & .Text '// add .Name and .Text to save and load from, separated by ":".
            End With
        Next
        Return sTemp '// return the data for saving.
    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IO.File.Exists(myCoolFile) Then '// check if file exists.
            For Each itm As String In File.ReadAllLines(myCoolFile) '// load file content in Array.
                If Not itm = "" Then '// verify that line has content.
                    With itm '// locate ctl by name and add value to it.
                        CType(Me.Controls(.Substring(0, .IndexOf(":"))), Control).Text = .Substring(.IndexOf(":") + 1)
                    End With
                End If
            Next
        End If
    End Sub
End Class
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.3052 seconds using 2.69MB