Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File

Posted on 1999-07-25
6
Medium Priority
?
195 Views
Last Modified: 2011-10-03
How do you write to a file? And how do you read from a file in Visual Basic 6? I need to SOURCE CODE!!!
0
Comment
Question by:Protorian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
s_lavie earned 90 total points
ID: 1527346
Dim myInput As String

' this is how you read a file until reaching eof:
Open fileName for Input as #1
While Not Eof(#1)
Input #1, myInput
Wend
Close #1

' this is how you write to a file:
Open fileName for Output as #1
Write #1, myInput
Close #1

' #1 is the number of the file - could be other number, or use the FreeFile function
0
 
LVL 2

Expert Comment

by:s_lavie
ID: 1527347
p.s.
If you want to read a full line, use
Line Input #1, myInput
instead of:
Input #1, myInput
0
 

Author Comment

by:Protorian
ID: 1527348
I want to be able to see the content of the file.
I am writting a browser and I want to add a bookmark file.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:s_lavie
ID: 1527349
What do you mean:
> I want to be able to see the content of the file.
In myInput you have the content of a string/line in the file, if you want the whole file in the string you may concatinate the strings.
I'm not sure I understand what exactly do you need!!!
Whould you clarify your question?
0
 

Author Comment

by:Protorian
ID: 1527350
OK!!
I want to be able to read from a file (.txt) and append to
the file (.txt).

See your browser's bookmark file, well I want to be able to do the same things that your browser does.

0
 
LVL 2

Expert Comment

by:s_lavie
ID: 1527351
read from file c:\temp\bookmark.txt -

Dim myLine As String
Open "c:\temp\bookmark.txt" For Input As #1
  While Not Eof(#1)
     Line Input #1, myLine
     ' do what ever you want with myLine, for example add it to a List:
     List1.Additem myLine
  Wend
Close #1

append to file c:\temp\bookmark.txt -

Dim newLine As String
Open "c:\temp\bookmark.txt" For Append As #1
   Write #1, newLine ' append newLine to the file
Close #1

I hope its help...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

721 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