Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Statement to Input from Binary File

Status
Not open for further replies.

jsaliers

Programmer
Jan 23, 2003
129
US
I have been stuck with a program that needs to read in (line by line, so as to match strings) a binary file created using the Put Statement. The person who began the program did not write to the log files using record numbers. They simply did the following:

***CODE***
Code:
Dim cr As String
Dim hLogFile As Integer
Dim Temp As String

hLogFile = FreeFile
Temp = "c:\" + model + mdy + "count.txt"
Open Temp For Binary Access Write As hLogFile

Put hLogFile, , "Total Passed = " & countTotal & cr
Put hLogFile, , "Total Passed = " & countgood & cr
Put hLogFile, , "Total Failed = " & countreject & cr
    
'Enter fail modes and counts to hLogFile
For X = 1 To (failbottom - 1)
   Put hLogFile, , failmode(X) & " " & failcount(X) & cr
Next X

Close hLogFile
***END CODE***

There work out to be a total of about 24 fail modes put in after the total counts. My problem is that I need to populate a form/variables with the count for each failure mode. That is, I need to read in a line, see what fail mode it is, match it to a variable, and populate the count variable for that fail mode with the count read in the file. If it was me, I would have created a type, and put each fail mode in as a record, as the Get Statement has a variable for recnumber. However, I have what I was given, which isn't much. Any ideas how I can read in a file one line at a time and store it to a variable to see what the line is?

Thanks much in advance!

Jon
 
Maybe I have been making this too difficult on myself??? Is it possible that each line is a record, if not otherwise specified when put to the file? If this is the case, could I not do something like:
Code:
For i=1 to LineNum

   get hLogFile, i, tempVar

Next i
Anyone have any ideas/experience with this?

Jon
 
Why are you using binary output? why not do something like

Code:
open <path> for output (or append) as # <freefile>



Thanks,
James
[afro][mad]
&quot;Make it idiot-proof and someone will make a better idiot.&quot; ~bumper sticker
 
It was not my choice to use binary output. I had inherited the application from another engineer that had half-completed it, and had no time to work on it, so they left it to me to finish. Not my choice by any means. At any rate, the project has been completed, and I am no longer associated with it. If anyone is interested, I will post the final solution.

Jon
 
Can you clarify what value is assigned to cr?

If this is actually CR or CRLF (chr(13) or chr(13) & chr(10)) then you have a simple text file and can read it using Line Input.

A simple check is to see if you can open the file in Notepad. If you can and it looks OK then the following code should work:
Code:
Open &quot;c:\&quot; & model & mdy & &quot;count.txt&quot; For Input As #1
do until EOF(1)
    Line Input #1, MyText
    .
    .
    .
loop
This will read each line (up to a chr(13)) into a variable.

All you then need to do is examine MyText and process it appropriately.

 
The cr was actually something defined globally to be a carriage return ( Chr(10) and Chr(13) ). I ended up using Line Input. Sorry for the non-clarity on the cr.

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top