Results 1 to 5 of 5

Thread: text box saving

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    16

    Question

    OK anyone tell me, if you have a text box on your form and you type somthing into it, how do you save the text in the text box so it is there the next time you run your program?
    anyone this would be very helpful. thanks

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    Something like this should work:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim F As Integer
        
        F = FreeFile
        
        '//check if the file exists (for the first time the program
        '//is running
        If Dir("C:\windows\desktop\text.txt", vbNormal) <> "" Then
            Open "C:\windows\desktop\text.txt" For Input As #F '//opens specified file
            Text1.Text = Input$(LOF(F), F) '//reads the file
            Close #F '//DON'T FORGET TO CLOSE IT!!!!!!!
        Else
            '//the file isn't created so just put something
            '//like
            MsgBox "File not found"
        End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        Dim F As Integer
        
        F = FreeFile '//gets next available file number
        
        Open "C:\windows\desktop\text.txt" For Output As #F '//opens specified file
        Print #F, Text1.Text '//writes to a file
        Close #F '//AGAIN DON'T FORGET TO CLOSE IT!!!!!!
    End Sub
    [Edited by QWERTY on 06-26-2000 at 11:52 PM]

  3. #3
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    Create a standard EXE file in VB
    Place a text box on the new form

    Code:
    Private Sub Form_Load()
        Text1.Text = GetSetting("MyApp", "Startup", "Text", "")
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        SaveSetting "MyApp", "Startup", "Text", Text1.Text
    End Sub

  4. #4
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    to save ur text ...

    do u know about sequential files ?

    that way u can save ur text in a textbox to a *.txt file or whatever ...

  5. #5
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    or you can use RichTextControl instead and use FileName and SaveFile properties:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        RichTextBox1.FileName = "C:\windows\desktop\text.txt"
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        RichTextBox1.SaveFile "C:\windows\desktop\text.txt", rtfText
    End Sub

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