Solved

Open/save text

Posted on 1998-06-26
15
137 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
ID: 1464414
Edited text of question
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1464415
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
ID: 1464416
I needds to read more than one line
0
 

Author Comment

by:hess
ID: 1464417
The answer proposed by clifABB only reads only line of text
0
 

Author Comment

by:hess
ID: 1464418
The answer proposed by clifABB only reads only line of text
0
 

Expert Comment

by:electrick
ID: 1464419
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
ID: 1464420
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:hess
ID: 1464421
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
ID: 1464422
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
ID: 1464423
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
ID: 1464424
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
ID: 1464425
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
ID: 1464426
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
ID: 1464427
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
ID: 1464428
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

929 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

12 Experts available now in Live!

Get 1:1 Help Now