Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Read Data From One File, Write To Another

Here's what I'm trying to accomplish. I have to read through a file and find a certain section in it. I then need to write out everything from the beginning of the section to a specified stopping point. My current code finds the beginning line and then just writes that line out to the output file. I need to write out everything from this line that I'm looking for until I get to a line that reads something like "The is the end". Any help/suggestions is appreciated!

VB Code:
Dim strTemp As String sfile = Dir("C:Test*.*")      Open "c: est" & sfile For Input As #1    Open "c: estOutput.txt" For Output As #2    While Not EOF(1)        Line Input #1, strTemp        If Left(strTemp, 66) = "                      * STATEMENT OF YOUR RESPONDENTS' ACTIVITY * " Then Print #2, strTemp    Wend    Close #2    Close #1

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Read Data From Database And Write To A File
I have an access database with a table containing 6 fields.
Using ADO and datagrid i am able to display the contents of the databas in the datagrid. I would like to write these in a text file or an excel sheet.

Actually i have 2 command buttons "Save" and "Interrupt".
When i click save it should start writing the database contents in a file. when i click interrupt it should stop the process and save the contents until it was interrupted.

I am a newbie and i need help to solve this ASAP.

How To Read/write Binary Data To A File
Hi all,

How do I read/write binary data to/from a file. I dont want the user toopen the file in notepad/wordpad and read the contents


Read Multiple Files And Write Data To One File?
I need to use the FileSystemObject to open a set of files in a particular the data in the files....append data from each file to one master the master file. I have a good idea how to use this but I can't quite put it together in code. I have experience with the FSO opening a file and writing data posted to a web form to it but have never appended to one file using the TextStream object. Any push in the right direction here would be greatly appreciated.

Write Text Data To A Binary File (Also Read It Back)
Hey all.

Ii have an app that uses an array to hold text data (many reasons for this, but it is the way it is).

In any case, I encrypt the data using an AES_Rijndael Block Cipher, all is well.

I would now like to write this data to a BINARY file (I cannot do so to a text file as part of the encrypted data may contain the vbCRLF char set).

Ii need to also be able to read thebinary data back into my app, then populate an array with the DECRYPTED data (I have the encryption and decryption routines already working).

How can one do this?


Write Macro To Exprot Code(Meta Data) That Read From Diagram To Flat File
I am new to ERStudio and VB. I wounder if someone can help me write macro to export metadata in ERStudio for table name like employee with its columns employee_id number(9) not null,employee_name varchar(25)(that read from table and write it to flat file.Thanks
Sub Main
' Dim Text File variables.
Dim Word As Object
' Dim ER/Studio variables.
Dim diag As Diagram
Dim mdl As Model
Dim attr As AttributeObj
Dim entdisp As EntityDisplay

' Init The ER/Studio variables.

Set diag = DiagramManager.ActiveDiagram

Set mdl = diag.ActiveModel

Set sm = mdl.ActiveSubModel
' Start TextFile and make it visible.

Set TextFile = CreateObject ( "TextFile.Application")

TextFile.Visible = True
' Init the ER/Studio variables.
Set diag = DiagramManager.ActiveDiagram
Set mdl = diag.ActiveModel
Set sm = mdl.ActiveSubModel

Read/Write Data In Memory
I'm in the process of writing a program (in VB6)that must be able to read and write to a propriatary board that has a base address of C8000.

In the 'old days of DOS' you could use peek and poke to read and write to memory locations but how does one accomplish the same task in visual basic?

Any help would be greatly appreciated.

Ed K.

Read And Write Binary Data Files
Hi. I need to read and write some binary data files (don`t ask why) from a software made in Turbo Pascal 7 into my VB application.(I know the record structure) My point is, How do I open the file and read a record?. I now there is "OPEN FOR " command and how to use it but only with random files. Any help. Or documentation. Or any link? Thanks.

How To Write The Code To Read Data From Query
I am a beginner of VB. SUppose I have one query, called query1, in column 14, called interval
I want to write the summation in the code
such as
For i=1 to ubound(Interval)
W=w+Interval (i)
next i
But I don't know how to write the code to read the data to this loop

Read And Write Data To Sound Card?

I need your help to find the best way to do a program whoes funtion is to take the sound received from the windows driver and then do a filtration routine on it to remove some frequencies and adjust some and then return the output to the windows back to be used by other applications.

Should i write a driver?

But why to write a driver, I need to write something in a higher level between a driver level and the application level.

I would be pleased to get your comments


Read/Write NTFS Alternate Data Streams?
I'v tryed to do the folowing example in vb6, problem is that none of my tryes worked.

So, here i am, does anyone knows a way to use that method, A.D.S.?

How To Read/write Data From/to USB Serial By Visual Basic
Dear experts,
could u plz tell me how to read/write data from/to USB


Opening SQL Database To Read And Write Data In Tables.
Hello, I have done the opening of tables in an access database. But I am curious as how similar (or disimilar) SQL is to opening tables and that. The code I used to use was something like this:

database_path = "C:Program FilesMypath"
DBPath = database_path
'there is aerror

DatabaseName = "mydatabase.mdb"
full_databasename = database_path & DatabaseName
set dbServer_database = Workspaces(0).OpenDatabase(full_databasename)

whats diferent for a SQL database? i would like to use the same functions to read and write from an sql database like

dim rec as recordset
set rec = dbserver_database.OpenRecordset("SELECT * FROM [MyTable]")
if rec.recordcount > 0 then
do while not rec.eof
msgbox rec!myRecord
end if

rec!MyRec = "hi"

The references i use for access databases is the microsoft dao 3.51 object library and the sort. Can I use the same references and way of opening the database for SQL? if not what do i change? the SQL database is defined across the network as an ODBC datasource.

Thanks for your time,

Path/File Access Error. Unable To Read Or Write The Specified File

I am getting the following error

"Path/File Access Error. Unable to Read or write the specified file.

Unable to Display the Image"

Following is the Code i am using .
With ImgEdit1
.Image = gStrFilePath & "" & pImagefile
.Page = 1
.FitTo 1
End With

The OS is windows 2000 and i am using ImageEdit control

the variable gStrFilePath contains the Path of the file
PImagefile contains the Image Name . Image is Tiff image.

If i click OK on the error messages the application closes. If i run the application again i am able to display the same Image.

Pls Help me

Using ADO Recordset, Read From An Access Database File And Write To A Text File
Using the ADO data control and the recordset property I am reading records from an Access data base file, selecting and manipulating records, and then trying to write to a text file. I know how to get the records from the database file, but I need sample code for how to write out to a text file.


Read/Write To File
Can anyone help me read and write to a file? (Source Code, Link, Anything)

Help With Read And Write To File
here is the code for a vb project, please can someone tell me why it does not work. it highlights the lines:

write #1 name, age
Print #1 name, age

thank you for your help.

the code:

Option Explicit
Dim namesandages As String

Private Sub cmdaddtofileprint_Click()
Dim name As String
Dim age As String
name = txtname.Text
age = txtage.Text
Open "namesandages.txt" For Append As #1
Print #1 name, age
Close #1
txtname.Text = ""
txtage.Text = ""

End Sub

Private Sub cmdaddtofilewrite_Click()
Dim name As String
Dim age As String
name = txtname.Text
age = txtage.Text
Open "namesandages.txt" For Append As #1
write #1 name, age
Close #1
txtname.Text = ""
txtage.Text = ""

End Sub

Private Sub cmddisplayfile_Click()
Dim datatodisplay As String
Open "namesandages.txt" For Input As #1
1 stdisplayfile.Clear
Do While Not EOF(1)
Line Input #1, datatodisplay
1 stdisplayfile.AddItem datatodisplay
Close #1

End Sub

Private Sub Form_Load()
namesandages = App.Path & "
End Sub

File Write/read
how can i add new text in text.txt every time i press command1???
i need to text be added in newline not in the old text place!!!

Private Sub Command1_Click()
Open "c: ext.txt" For Output As #1
Print #1, Text1.Text & vbCrLf
Close #1
End Sub

And my second question is about File reading! In text.txt is 3 lines of text:
first line
second line
third line

How can i make my textbox display seccond line text???

Best Way To Read/write A File
Is there any other way that tends to be faster, more efficient in reading and writing from a file, else than the Open "blabla.exe" for binary as #1?

I need to use the least resources, and the fastest. Currently, i managed to get only around 100 Kb/sec or less.

I need to include a doevents when writing and reading though, to let the screen refresh.

I need this for transferring large files (through FTP), through a network (very fast connection - 100 Mbits+). Now im not utilising even 10% of my available badnwith.

I saw other ftp clients doing 4-6 Mb/sec, which is very good!

To Read And Write To Ini File
Hi All,
I am very much new to VB.Could any one of you please tell me how to read and write from ini file. It would be of great help if anyone can send me the code also.

File Read Write
i would like to read a raw(unformatted) textfile and output the same in
a formatted textfile.

Read Write To Same File
Can someone show me an example script on how to open a text file and write back to that same text file?

Read/write The Same File
It's possible to read and write in the same file? I have to read and maybe add some information to the file. The file is sequential (text). I don't know in what mode I have to open the file: input or output. And is the access keyword "read write"?
Some code example will help me.

Read/write To A File
I'm stuck with something that looks so simple from the docs....

Basicly i need 2 'commands'
a] Read a file without 'structure' Without VB6 assuming/altering things.
b] Write a file without 'structure' Without VB6 assuming/altering things.

So just a byte by byte copy.

I tried all the combinations I can find in the manual print/write/input/get/etc.
But VB6 always keeps adding a few bytes.

I searched this forum on this topic but couldnt find the answer there.
Anyone that wants to help me out on this one plz?

Kind regards.

How To Read And Write Into A File
I would like to know how to read and write into a file using vb.I am using txt files for now
thanks and regards

Read And Write To An Ini File
Hi all im very new to visual basic and am having trouble reading and writting to an ini file from a listbox i can do it with a textbox i am using the same code for a listbox and textbox but the listbox just doesnt want to save what can i do?
Thankyou in advance

File Read/write
My question is how to read and display a value of 00000. what I am doing is, to read a txt file that has a value of 00000 on the first line. Then I increment the value by 1 and write back to the same file. I am expecting to see 00001, instead, I see 1.

Does anybody how to correct this problem?

Read Write To File
i have a got some code that writes to a file below:

Open filename For Random As #fileNumber Len = recordLength

'write the record to file
Put #fileNumber, 1, myrec

'Close file
Close #fileNumber

how can i add records to the file without it erasing the records already in the file?

also how can i display this whole file in a sort of table?

Write/Read In A RES File
I try to make an Resource editor, something that help me to manage a res file received from a client.
I was able to retrive the informations from the file and put them into two arrays id and data and after add, modify, delete elements from those arrays I try to put the two arrays id and data back to res file, but it won't work.It make me a res file but it skip some lines and I can't figure out why.
Do anyone make something like this?
How can I save the two arrays into a res file?
Please help

How I Can Read && Write In Sam File ??
peace be with you

how i can read and write in the sam file


File Read-Write
Hello there
I want to creat an Address Book using VB 6.0. I am new to VB and I have made the application almost but I don't know the code how to Write and the Read from the File.
Can anybody help me out.

I want ot eneter the Datas as
Sr. No. | Name | Father's Name | Date of Birth | Address
thsi is how to write the file
and I want to customize while reading like if i wan to view by Serial nos then it shgould come by serial nos. if by Date of Birth then so.

File Read Write
This program opens a file .doc or .txt splits the contents on fullstops then searches each split for a word if found writes word to "results.doc
The program works reading txt files but when i open a word doc
i get an error message "input past end of file" has any one any idea why?
vb code
Open "D:Datawordsearch
esults.doc" For Output As #2
Open a For Input As #1
lFileLen = LOF(1)
sText = Input(lFileLen, 1)
sSplitrec = Split(sText, ".")
For i = i To UBound(sSplitrec)
If InStr(1, sSplitrec(i), Text1.Text) Then
Print #2, sSplitrec(i)
End If
Next i
Close #1
Close #2

How To Write A File In VB6.0 And Read It In

I need to write a list of Longs to a file in an application written in VB6.0, and then read the same file through an application written in

Writing the file in VB6.0 I can do as follows:

VB Code:
Dim fs As Integer                        fs = FreeFile    ' Get unused filenumber.            Open strFile For Binary Access Write As #fs                                                                                    Put #fs, , lng_Data                        Close #fs

..where lng_Data is an array of longs

But how do I read this array back into memory in
Using a binary streamreader.. I am only allowed to read byte-arrays.

In, I could serialize/deserialize the array, but that is not compatible with VB6.0.


best reg.

Big File Read And Write
look this code

Open "aaaa" For Binary As #1
CGW.FuJian = String(LOF(1), " ")
Get #1, , CGW.FuJian
Close #1
Open "bbbb" For Binary As #1
Put #1, , CGW.FuJian
Close #1

when file "aaaa" is a small file(i test a file size with 3K) ,code runs correct.but when file "aaa" is big(i test a file with size 300K),code run incorrect ---- file "bbbb" is bigger then file "aaaa" about 15%


Write / Read From File Help Req
I am transfering my skills from SQL to VB and need some urgent help with a very simple problem. So if anyone can help I would be very greatfull.

I need to design a simple form that collects input from the user with the following

Name age address etc. And write this to a txt file

Then read it back and display it on the form so the user can scroll though the records.

Also design a simple report from the txt file

Please note that there will be a max of 15 records in the file.



File Write N Read
What I need to do is accept a password and store the password at the end of a file already having some data. Later on the user should be able to retrieve the password. What I want to know is how to store the password at the end of the file. The password size would vary, so would it be necessary to store the length of the password too? How do I read the password back from the file.

I need to know this urgently

Read And Write To A File
O.K. the subject sounds like a newbie question....?
What I want to do is to have file "a" to have several lines of text with places for a variable. When file "a" is copied
into file "b" the change will happen.


name = "Bob"

file "a"
%name% jumped over the mountain.

output to file "b"
Bob jumped over the mountain.

I plan to have much more text and it might change so I do not want to hard code it in.


Read && Write A File
i want to open a file and save all of it to a variable and then to write it to a new file.
how can i do it?

File Read && Write
i am having the byte array
i have to store this byte array into the file(create file in the local machine)

send some sample code to
how to open a file in the binary mode
how to read from & write to

need help, urgent

How Do I Read && Write A CSV File In VB6
I have some CSV file with mulitple sizes I would like to Read into my VB project. This is an Example of one format.


All of these are different Variables what is the best way to Read these into the Variable's that hold these Items values?

And would Writing them be much different?



Write And Read To File
I am sure this has been asked before but I can't seem to find it.
I need to write multiple text, list, and multiple line text boxes to a file.
Then be able to read it back in on file open.
I can use the ini approach but it only reads single line values.

name: bob
phone: smith
interests: biking

Where interest would be from a multiline text box.
When opening file it needs to populate the boxes.
Any help would be great. Thanks

Read && Write File In Evb 3.0
How I can read & write a file in evb 3.0?

I've try:

Private Sub Command1_Click()
Dim file1, FsModeAppend
 file1.Open "Append", FsModeAppend
 file1.lineprint "Appending..."
 MsgBox file1.LOF, , "The length is ..."
End Sub

but I've received this error:

"An error was encountered while running this program: object required: file1.

Please help me as soon as possible ...
Thank you very much in advance

File Read/write
Hi I have a problem when it comes to files. The problem is as follow, I have a tekst file called "" in this file there is many registered barcodes whith additional information. When the user scans a barcode and the barcode is in this file i have to delete the specific line. The original text file look's something like this.
Code:60310001103 12 Ikke Ok 23.06.2003
60310001104 12 Ikke Ok 23.06.2003
60310001105 12 Ikke Ok 23.06.2003
60310001106 12 Ikke Ok 23.06.2003

and I wont to change it so it look like this
Code:60310001103 12 Ikke Ok 23.06.2003
60310001105 12 Ikke Ok 23.06.2003
60310001106 12 Ikke Ok 23.06.2003

Does anybody have a suggestion ????

Edited by - Dag on 6/24/2003 5:15:39 AM

Read And Write To File
Hi all... can any one help me on how to solve this...i need to read some data from database(MS Access)...sort the data base on one of the field and save it in text file.

Really appreciate your help...thanks.

How - INI File Read&&write?
I need to read & write ini files.
Is there is any easy way to do this with VB6 ?

How To Read / Write Data Of A Smart Card In Visual Basic
I have connected the smart card device to my com1 port. how to read or write data into the smart card so that i would use the data of a smart card into my visual basic appllication. Awaiting for reply at the earliest

Openin Excel - Read/write Data To A Cell Reference
Can any one help me to do the followng using API functions only;

1) open excel ( i am using shellexecute here)
2) open specific workbook -
3) select sheet
4) paste data into a specific cell reference
5) read data from anoher cell reference
6) save and close workbook/ excel.

I am really having problems with steps 2-6, as I don't know which functions should be referring to.




Read/write File Properties
Hi everybody.
Similar to read MP3-ID-Tags, I want to read/write "tags" (file properties) from JPEG files. I want to read the properties set in the windows explorer like "title", "theme", "comment" as well as the extended information from e.g. digital cams such as "pixel-size" etc....
I don't know how to code? Is there a standard API-function?
Can anyone provide sample code?

File Read/Write Problem
need help please:

i have a file read/write sychronization problem is VB: two VB applications (think one is client; another is server). the server is writing data into a text file every second (or as real time as possible); the client is to read data from that same text file every second (or as real time as possible).

i repeatedly run into the synchronization problem here between the VB applications. can someone help me on this??? my email is



File Read Write Problem

I am trying to write a simple program using VB's menu system to import
player files from my game to edit. I can access the file..kind of horrid like
but I cannot display the data line per line to textboxes.

Dim PrgFile As String

Private Sub mnuOpen_Click()

PrgFile = InputBox("Enter Valid File Name To Open", "Filename")

If (PrgFile = "") Then

MsgBox ("Error! Must Enter File Name!")

PrgFile = InputBox("Enter Valid File Name To Open", "Filename")


Open PrgFile For Input As #1

While Not EOF(1)

Line Input #1, temp$

alltext$ = temp$


Text1(i).Text = alltext$

Close #1

End If
End Sub

any help would be great!


Copyright 2005-08, All rights reserved