Results 1 to 7 of 7

Thread: HelpNeeded!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    1

    Unhappy HelpNeeded!!!

    i have made two programs and the both contain many textboxes and one contains a datetimepicker but if i make it a .exe file then every time i close the application it doesnt save the contents and i need it to what do i do?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: HelpNeeded!!!

    Welcome to VBForums

    Thread moved from the 'Assembly language' forum to the 'VB.Net' (VB2002 and later) forum

    (for the benefit of others, 1020lokie's profile says VB 2010 )

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: HelpNeeded!!!

    If you want to persist the values in the textbox, you will need to save it somewhere and load it back again when your application starts the next time.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: HelpNeeded!!!

    I recommend writing the information to a settings file. You can go all difficult with:
    option1="value"
    option2="value2"
    To make a regular INI file, but for starters you could simply use the order of the values in your program.

    Use the streamreader/streamwriter object:
    Writing the information (on form closing)
    Code:
    Dim settingsfile As String = Application.StartupPath & "\Settings.txt"
    If IO.File.Exists(settingsfile) Then IO.File.Delete(settingsfile)
    Dim writer As New IO.StreamWriter(settingsfile, True)
    writer.WriteLine(TextBox1.Text)
    writer.WriteLine(TextBox2.Text)
    writer.WriteLine(TextBox3.Text)
    'etc.
    writer.Close()
    Reading the information (on form load)
    Code:
    Dim settingsfile As String = Application.StartupPath & "\Settings.txt"
    If IO.File.Exists(settingsfile) Then
        Dim reader As New IO.StreamReader(settingsfile)
        TextBox1.Text = reader.ReadLine()
        TextBox2.Text = reader.ReadLine()
        TextBox3.Text = reader.ReadLine()
        reader.Close()
    End If
    I recommend parsing the lines, since it is more resilient to user-made mistakes.
    Code:
    Dim reader As New IO.StreamReader(settingsfile)
    Do While reader.Peek <> -1
        Dim textline As String = reader.ReadLine().TrimStart()
        If textline.StartsWith("username=") Then
            TextBox1.Text = textline.Remove(0, 9)
        ElseIf textline.StartsWith("password=") Then
            TextBox2.Text = textline.Remove(0, 9)
        End If
    Loop
    reader.Close()

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: HelpNeeded!!!

    Try this:

    1. Open project properties, Settings tab.
    2. Add a setting
    Name: TextBoxValues
    Type: System.Collections.Specialized.StringCollection
    Scope:User

    3. Add the following code to your form:
    vb.net Code:
    1. Dim textBoxes() As TextBox
    2.  
    3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.     textBoxes = New TextBox() {TextBox1, TextBox2}  '<--- add all textbox names here whose value you want to persist.
    5.     With My.Settings
    6.         If .TextBoxValues Is Nothing Then .TextBoxValues = New System.Collections.Specialized.StringCollection
    7.         For i = 0 To textBoxes.Length - 1
    8.             If .TextBoxValues.Count <= i Then .TextBoxValues.Add("")
    9.             textBoxes(i).Text = .TextBoxValues(i)
    10.             AddHandler textBoxes(i).Validating, AddressOf TextBoxes_Validating
    11.         Next
    12.     End With
    13. End Sub
    14.  
    15. Private Sub TextBoxes_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    16.     Dim tb As TextBox = CType(sender, TextBox)
    17.     Dim i As Integer = Array.IndexOf(textBoxes, tb)
    18.     My.Settings.TextBoxValues(i) = tb.Text
    19.     My.Settings.Save()
    20. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: HelpNeeded!!!

    References, i hope u may have some choices here
    (1) Code Project
    (2) http://="http://msdn.microsoft.com/e...s.80%29.aspx"]
    (3) Ged mead
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: HelpNeeded!!!

    i'd recommend (ApplicationSettings).
    for a textbox:

    vb Code:
    1. '1/ in design view select your textbox
    2. '2/ in your properties window expand (ApplicationSettings)
    3. '3/ select (PropertyBinding) + click the ellipsis to the right
    4. '4/ select the Text property from the list + click the dropdown arrow to the right
    5. '5/ click (New...) + type in a Name for the setting
    6. '6/ click ok on the setting window + ok on the window beneath

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