Solved

Open/save text

Posted on 1998-06-26
15
136 Views
Last Modified: 2010-05-03
How can a open/save a text file with out going through a rich text box. I want plane ascii text. The Rich text box adds all kinds of extra formating that i don't want. (Vb4)
0
Comment
Question by:hess
  • 10
  • 4
15 Comments
 

Author Comment

by:hess
Comment Utility
Edited text of question
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
To write a textfile:

hFile = FreeFile
Open "TESTFILE" For Output As #hFile
Print #hFile, sOutString
Close hFile

To read a text file:

hFile = FreeFile
Open "TESTFILE" For Input As #hFile
Input #hFile, sInString
Close hFile


0
 

Author Comment

by:hess
Comment Utility
I needds to read more than one line
0
 

Author Comment

by:hess
Comment Utility
The answer proposed by clifABB only reads only line of text
0
 

Author Comment

by:hess
Comment Utility
The answer proposed by clifABB only reads only line of text
0
 

Expert Comment

by:electrick
Comment Utility
I've had good luck using a ListBox to input text files.
Goes something like this.

Dim InputData
Open "MYFILE" For Input As #1      ' Open file for input.
Do While Not EOF(1)      ' Check for end of file.
      Line Input #1, InputData      ' Read line of data.
      List1.AddItem InputData
Loop
Close #1      ' Close file.
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
If you need to read more than one line, then put the code in a loop:
sFullString = ""
hFile = FreeFile
Open "TESTFILE" For Input As #hFile
Do Until EOF(hFile)
  Input #hFile, sInString
  sFullString = sFullString & sInString
Loop
Close hFile

(Ditto for outgoing string)
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:hess
Comment Utility
Great both of you. One problem though. I asked how to read and WRITE text files so who ever can give me that also will be awarded the points.
0
 

Author Comment

by:hess
Comment Utility
Great both of you. One problem though. I asked how to read and WRITE text files so who ever can give me that also will be awarded the points.
0
 

Author Comment

by:hess
Comment Utility
I'm Dumb. You can't say ditto for out going file Cliff because it isn't exacly the same and i don't know what changes to make.  I am an absolute begineer
0
 

Author Comment

by:hess
Comment Utility
I'm Dumb. You can't say ditto for out going file Cliff because it isn't exacly the same and i don't know what changes to make.  I am an absolute begineer
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
It would be much easier if you could give the name(s) of the variable(s) which contain the text you want to save.

However, if you are saving the contents of a text box, use this:
hFile = FreeFile
Open "TESTFILE" For Output As #hFile
Print #hFile, Text1.Text
Close hFile

I will submit this as a comment until you are satisfied with the answer.
0
 

Author Comment

by:hess
Comment Utility
Cliff,
         I'll give you the 50 points as soon as you propose an aswer so that i have the option of giving it to you (the answer in the comment was fine).  Thankyou for all of you help.


0
 

Author Comment

by:hess
Comment Utility
Cliff,
         I'll give you the 50 points as soon as you propose an aswer so that i have the option of giving it to you (the answer in the comment was fine).  Thankyou for all of you help.


0
 
LVL 6

Accepted Solution

by:
clifABB earned 50 total points
Comment Utility
Here is the answer:
hFile = FreeFile
Open "TESTFILE" For Output As #hFile
Print #hFile, Text1.Text
Close hFile

Glad I could help.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now