CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 1999
    Location
    Québec (Canada)
    Posts
    210

    Change default value in TextBox.Text

    When I load my form, the TextBox.Test = 8 and I would like to change this value during run.

    With the new value = 10 and when I reload the next time my form I would like optain the default value for my TextBox = 10

    Is't possible?
    Thanks a lot
    Redg


  2. #2
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: Change default value in TextBox.Text

    Yes, if you save a new value in a file, registry or database. VB Code itself cannot remember any changes you make during runtime.
    Vlad


  3. #3
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: Change default value in TextBox.Text

    One of the ways to do that: Add Microsoft Scripting Runtime reference to the new project, place Text1, Command1 and Command2 on the form. Paste code below, save and run.

    option Explicit
    private FSO as Scripting.FileSystemObject
    private Filer as Scripting.TextStream
    private strFile as string
    private strValue as string

    private Sub Command1_Click()
    strFile = App.Path & "\text.txt"
    set FSO = new Scripting.FileSystemObject
    set Filer = FSO.OpenTextFile(strFile, ForReading, false)
    strValue = Filer.ReadLine
    Text1.Text = strValue
    Filer.Close
    set Filer = nothing
    set FSO = nothing
    End Sub

    private Sub Command2_Click()
    set FSO = new Scripting.FileSystemObject
    set Filer = FSO.OpenTextFile(strFile, ForWriting, false)

    Filer.WriteLine Text1.Text
    Filer.Close
    set Filer = nothing
    set FSO = nothing

    End Sub




    Vlad


  4. #4
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Change default value in TextBox.Text

    You can use WriteProfileString() and GetProfileString() to save and retrieve your values to and from the registry.


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

Featured