Solved

Start reading from beginning of file.

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

Independent Software Vendors: 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

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.
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…
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…

705 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