10-17-2012 07:53 PM
I have to duplicate a binary file read in which I have an excel macro written in vba that already does it. I want to write it in labview and have been trying the examples for binary file reads and cant seem to get it to work. Anyone know how to code in labview the vba code "f.OpenAsTextStream(ForReading, TristateUseDefault)" - it is not unicode or ascii but described as a system default in vba.
The format argument can have any of the following settings:
Constant |
Value |
Description |
---|---|---|
TristateUseDefault |
-2 |
Opens the file using the system default. |
TristateTrue |
-1 |
Opens the file as Unicode. |
TristateFalse |
0 |
Opens the file as ASCII. |
10-18-2012 04:44 AM
It looks as if the vba code is opening a text file, not a binary one. The format "TristateUseDefault" just means that the system default of ASCII or Unicode will be used.
Have you tried the "Read From Text File" function? If so, what happened?
If this doesn't work, please attach an example of the file you are trying to read.
MC
10-18-2012 07:43 AM
The read from text file returns this set of wingdings as shown in the attachment snippet...
The section of vba that deals with this operation looks like this:
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim ff, f, ts, s
Set ff = CreateObject("Scripting.FileSystemObject")
For i = 0 To NumFiles
FileSize = FileLen(FileNames(i))
BinFileName = Mid(FileNames(i), Len(DirectoryName) + 2, Len(FileNames(i)) - (Len(DirectoryName) + 5))
Set f = ff.getfile(FileNames(i))
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Next
10-18-2012 08:34 AM
Well, from what's shown in the Data String indicator, it's apparent that the data is not in human readable format. However, the vba code simply opens the file as a text file, not as a binary file, and reads in all the data.
Presumably there's another vba function which takes the data and converts or formats it in some way. Maybe that would be the next place to look for clues as to how to interpret the content.
Once you know that, it should be possible to work out which binary file function to use, or whether it is necessary to read it as a text file and format/convert it yourself.
MC
10-18-2012 01:57 PM
I figured it out. It is a binary file with ASCII Codes that has to be read one I8 byte at a time and then converted to its corresponding ASCII Character. The conversion process was for it to get the binary byte typecasted as a string type then converted from a hex string to a number to make sense out of it.
Thanks for your help
10-18-2012 02:29 PM