Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open/save a text file

Status
Not open for further replies.

tom1597530

Programmer
Oct 13, 2009
11
SK
Hello. I am amateur in programming and I am not English, so sorry for my English :). I need a code from you:
I have Text1, Text2, Text3, Command1, Command2.
When I'll write a number, let's say, "12345" into the Text1 and I'll write "test" into the Text2 and I'll press Command1, it will save text from Text1 into a text document (.txt) congenitally to the desktop. It will have name written in Text2. And when I'll press Command2, it will load the number 12345 into the Text3.

Please, write me a complete code, 'cause I'm amateur and the best way to learn it for me is to read it in the code. Thank you very much.
 

How about:
Code:
Option Explicit

Private Sub Command1_Click()

Open "C:\" & Text2.Text & ".txt" For Output As #1
Print #1, Text1.Text
Close #1

End Sub

Private Sub Command2_Click()
Dim strTextLine As String

Open "C:\" & Text2.Text & ".txt" For Input As #1
Do While Not EOF(1)
   Line Input #1, strTextLine
   Text3.Text = strTextLine
Loop
Close #1

End Sub
This code does not put the file on the Desktop - it is on C:\

Have fun.

---- Andy
 
OMG, it works! Thank you, Andy I'm really grateful, I was searching it for 2 weeks. Thaaaaaaaaaaaaaaaanx :).
 
And can somebody please tell me, how can I lock that text file? I mean, that nobody can change info in it, but when you push the Command2 it WILL load the text? Thank you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top