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
Printable View
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
Something like this should work:
[Edited by QWERTY on 06-26-2000 at 11:52 PM]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
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
do u know about sequential files ?
that way u can save ur text in a textbox to a *.txt file or whatever ...
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