LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

OpenAsTextStream

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.

0 Kudos
Message 1 of 6
(2,728 Views)

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

0 Kudos
Message 2 of 6
(2,708 Views)

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
   

0 Kudos
Message 3 of 6
(2,696 Views)

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

0 Kudos
Message 4 of 6
(2,688 Views)

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

0 Kudos
Message 5 of 6
(2,672 Views)
No worries, glad you got it sorted MC
0 Kudos
Message 6 of 6
(2,663 Views)