Solved

Start reading from beginning of file.

Posted on 2004-08-16
3
222 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 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

21 Experts available now in Live!

Get 1:1 Help Now