Solved

Start reading from beginning of file.

Posted on 2004-08-16
3
227 Views
Last Modified: 2010-05-02
Hi, I have a program that reads data from a binary file, 4kilobytes at a time (using INPUT). My problem is, when i close that file and open a new file to do the same, the program does not start from the beginning of the file, and just reacts as if it has reached the end of the file. How can i tell it to begin reading from the beginning of the file again? Heres my code:

Earlier in the code, a file is opened with the following line:
  Open CD.FileName For Binary As #1
  FileSize = FileLen(CD.FileName) / 4096


The following code is then executed everytime i want the next 4k of data from that file:

 cmdSend.Enabled = False
 Dim DataChunk As String
 If FilePos < FileSize Then
  FilePos = FilePos + 1
  DataChunk = Input(4096, #1)
  Ws.SendData DataChunk
  lblConnection = "Transferring... " & Math.Round((FilePos / FileSize * 100), 0) & "%"
  DoEvents
 Else
  Ws.SendData "FileEnd" & FileLen(CD.FileName)
  FilePos = 0
  cmdSend.Enabled = True
  Close#1
 End If

 
0
Comment
Question by:pyromatt
[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
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Burbble earned 50 total points
ID: 11815599
Try this:

Open CD.FileName For Binary As #1
Seek #1, 1 '<-- add this line

(etc etc...)

-Burbble
0
 

Author Comment

by:pyromatt
ID: 11816244
It works!!! thanks! :)
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11817318
Glad I could help :-)

Thanks for the points.

-Burbble
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing a value with stream reader AFTER a ";" 3 90
Hide vba in gp 7 125
MS SQL store procedure to calculate and return result 6 74
Send outlook email from VBS Script 2 66
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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