|
-
Jun 26th, 2000, 10:31 AM
#1
Thread Starter
Junior Member
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
-
Jun 26th, 2000, 10:47 AM
#2
Fanatic Member
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]
-
Jun 26th, 2000, 10:49 AM
#3
Lively Member
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
-
Jun 26th, 2000, 10:49 AM
#4
Hyperactive Member
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 ...
-
Jun 26th, 2000, 10:56 AM
#5
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|