|
-
Sep 10th, 2000, 09:47 AM
#1
Thread Starter
Junior Member
Hello,
How would I set up my program so that the text in two text boxes is saveable in .txt format.
Also, how to open already saved files.
So lets say in text1, I have:
"Blah"
and in text2 I have:
"Boo!".
When I save that, I want it to be saved in a .txt file like this:
[Text1]
Blah
[Text2]
Boo!
Then when I open the file, I need VB to know which is which and put them back in the right box.
Thanks,
System
-
Sep 10th, 2000, 12:06 PM
#2
Lively Member
Private Sub Text_Save()
Dim f%
f = FreeFile
Open "c:\blah.txt" For Output As #f
Print #f, Text1
Close #f
f = FreeFile
Open "c:\boo.txt" For Output As #f
Print #f, Text2
Close #f
End Sub
Private Sub Text_Open()
Dim f%
f = FreeFile
Open "c:\blah.txt" For Input As #f
Text1 = Input(LOF(f), f)
Close #f
f = FreeFile
Open "c:\boo.txt" For Input As #f
Text2 = Input(LOF(f), f)
Close #f
End Sub
-
Sep 10th, 2000, 12:28 PM
#3
Fanatic Member
You could also use:
Code:
Private Sub cmdSave_Click()
Open "d:\testfile.txt" For Output As #1
Print #1, "[Text1]"
Print #1, Text1.Text
Print #1, "[Text2]"
Print #1, Text2.Text
Close #1
End Sub
Private Sub cmdOpen_Click()
Dim tString As String, tText
Open "d:\testfile.txt" For Input As #1
Do Until EOF(1)
Line Input #1, tString
If Left$(tString, 1) = "[" And Right$(tString, 1) = "]" Then
tText = Mid(tString, 2, Len(tString) - 2)
Else
Select Case tText
Case "Text1"
Text1.Text = tString
Case "Text2"
Text2.Text = tString
End Select
End If
Loop
Close #1
End Sub
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Sep 10th, 2000, 01:05 PM
#4
Thread Starter
Junior Member
makai:
Thanks, but that would save it in two seperate files, and I need both in one.
RealisticGraphics:
I am using that code, except for the open part, I could not get that going right. Anyway, I need to save it as "Save As..." format so that people can pick where and the name of the file. How would I change that code, so they can pick the save settings?
Thanks,
System
-
Sep 10th, 2000, 02:33 PM
#5
Fanatic Member
Add a common dialog control to your form (I called mine cd1) and then use the following code. BTW, what do you mean you couldn't get the Open code to work?
Code:
Private Sub cmdSave_Click()
cd1.ShowSave
Open cd1.FileName For Output As #1
Print #1, "[Text1]"
Print #1, Text1.Text
Print #1, "[Text2]"
Print #1, Text2.Text
Close #1
End Sub
Private Sub cmdOpen_Click()
Dim tString As String, tText
cd1.ShowOpen
Open cd1.FileName For Input As #1
Do Until EOF(1)
Line Input #1, tString
If Left$(tString, 1) = "[" And Right$(tString, 1) = "]" Then
tText = Mid(tString, 2, Len(tString) - 2)
Else
Select Case tText
Case "Text1"
Text1.Text = tString
Case "Text2"
Text2.Text = tString
End Select
End If
Loop
Close #1
End Sub
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Sep 10th, 2000, 07:52 PM
#6
Thread Starter
Junior Member
?
What is a common dialog control?
-System
-
Sep 10th, 2000, 08:00 PM
#7
_______
<?>
Code:
'using common dialog
'write a text box output to a file
'called YourFile and save it as text file.
'
'open a project and go to
'Project\Components\Microsoft Common dialog Control
'click it to add it to the toolbox
'
'double click it in the toolbox to add it to the form.
Private Sub Command1_Click()
CommonDialog1.CancelError = True
CommonDialog1.Flags = cdlOFNOverwritePrompt
On Error GoTo errhandler
'Set the properties of the text control
CommonDialog1.Filter = "Text Files(*.txt)|*.txt*|HTML Files(*.htm,*.html)|*.htm*|All files(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.FileName = "YourFile"
CommonDialog1.DefaultExt = "txt"
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
Print #1, Text1.Text
Close #1
errhandler:
Exit Sub
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 10th, 2000, 08:08 PM
#8
Thread Starter
Junior Member
Don't have
I don't have:
"Project\Components\Microsoft Common dialog Control"
-System
-
Sep 10th, 2000, 08:19 PM
#9
Thread Starter
Junior Member
N/M
Never Mind, I got it set up so it will work good enough. thanks.
Thanks for you help.
(I will have more questions soo. ;^) )
-System
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
|