BinaryReader class usage

  • Thread starter Thread starter David Compton
  • Start date Start date
D

David Compton

Hi all,

Can anyone tell me if this is possible ? :-

I have several flat files created in VB6 using UDTs and the PUT command.
They include integers, etc. and are all of fixed record length.

I want to export them to SQL, but the only way I can read these files is
from VB using GET fileno, recordno, userdefinedtype.
The UDT must be specified at designtime so I can't dynamically read
different databases from the same app.

I was wondering if I could use VB.NET and the BinaryReader class to read
these records and export them to a CSV to direct to SQL ?
I already have the code that reads the .BAS file containing the type
structure, it then works out the record length and compares it to the binary
file to see how many records it contains (or if the size doesn't match).

Can anyone confirm this is possible ? (I don't want to spend a week learning
VB.NET only to find out it's not !).
OR - Does anyone know of a program that allows you to do this already ? I
believe flat binary files are similar to SAS databases ?

Any help will be gratefully received !

Cheers.

David Compton
Autoclimate Ltd.
 
As the files sound like they are ultimately text, I am not sure I see the
value of using a BinaryReader. BinaryReaders are better for binary files
(Excel files, graphics, et al) not for fixed length text.

I would read in the text, line by line, and break it out. You can then use
your old classes to create the UDT, or place the info into SQL Server.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Hi Cowboy (or do you prefer Gregory ?),

Thanks very much for the response.

Sorry if I wasn't clear, but when I said that the files included integers I
meant that they were two byte binary integers 'PUT' there by VB.
There are also longs, dates, bools and maybe even a couple of floating point
numbers...
Hence my need to read the file in binary.

There doesn't seem to be a way to dynamically set the type structure at
runtime (I have to either recompile the exe to import each database, or run
in design mode).
I wanted to be able to point my app at any 'flat binary file', tell it
(manually or by pointing at the UDT) the record structure and then export to
CSV or SQL.

The only stumbling block is the limitation of VB6 - if only I could create a
dynamic UDT...

I did have one idea I've yet to try - tell me what you think :-
Could I load each record into a dynamic array of bytes (having REDIM'd the
array size to the record size) and then extract the data into a CSV byte by
byte (processing according to the record structure which we've specified) ?
It sounds promising, but I'm not sure if you can 'GET' into a dynamic
array...

All this would be so easy if VB had an 'eval' command like VBScript or
Java...

Another question : can the BinaryReader class be used in VB6 or is it
exclusive to .NET ?

Thanks again.

Dave MC.
 
Hi David,

All depend of course how you want to use it, but you can save a bytearea (or
blob) to msAccess and to SQL server.

You just have to "Insert" the row into the database or "Update" a field with
it.

I have place to words between "" because you should have to use that with a
"sqlcommand" or "oledbcommand" the complete name that you need is
sqlcommand.executenonquery.

Have a look for those words I did give you on/in Msdn.

And no you cannot use managed code in VB6.

Cor
 
Thanks Cor,

I have no problem putting the binary data into a database (I'm OK with the
Image type and BLOBs).
It's reading it from a binary file that's the problem.

Time to learn .NET and make use of the BinaryRead class methinks.
How hard can it be ?!

I'm not sure what 'Managed Code' is but I'm guessing you're referring to the
Eval command or dynamic UDTs.
I guess it's too much to expect from a language that is after all designed
to be BASIC.

So... Can you have VB6 and VB.NET installed simultaneously on the same
computer ?

Don't bother answering that, I'm sure I'll find out.
Thanks for your help Cowboy & Cor.

Dave MC.
 
Back
Top