473,396 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

BinaryReader class usage

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.
Nov 20 '05 #1
4 3969
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!
************************************************** ********************
"David Compton" <dc******@nomorespam.autoclimate.com> wrote in message
news:O8**************@TK2MSFTNGP09.phx.gbl...
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.

Nov 20 '05 #2
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.
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:#I**************@TK2MSFTNGP09.phx.gbl...
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!
************************************************** ********************
"David Compton" <dc******@nomorespam.autoclimate.com> wrote in message
news:O8**************@TK2MSFTNGP09.phx.gbl...
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.


Nov 20 '05 #3
Cor
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
Nov 20 '05 #4
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.

"Cor" <no*@non.com> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris P. | last post by:
I have a C# application that connects to Perl application on a UNIX server. I am able to connect and communicate both directions with the server, but there are several occasions when it appears...
3
by: liljester | last post by:
Is there a way to tell this method how many bytes to read from the stream? the msdn documentation doesnt explain its usage very well... Any help would be much appreciated
14
by: Laszlo Szijarto | last post by:
Can BinaryReader be forced to read a stream, say a TCP/IP stream or memory stream or even file stream in big endian order or do I have to write something custom to reverse the byte order? So, for...
2
by: Bob Rock | last post by:
I already found an alternative way to accomplish this (using ReadBytes), still I'd like to understand why I'm getting and error reading a text file using the following method. The exception is...
2
by: RP2001 | last post by:
I've serialized in various variables of various types (mainly CString, int, double) into an instantiated MFC CArchive class and saved it as a binary file. I am able to open the binary file and...
3
by: Kevin Trojanowski | last post by:
I'm about to rip out what little hair I have left; I have a class that uses a BinaryReader, and the data is getting munged. A subset of the code follows; I've removed the parts that aren't...
6
by: Question with BinaryReader | last post by:
I use BinaryReader to read my binary dafa files, when i call ReadBytes, why it always return more 4 bytes. The following is my code. FileStream fs = new FileStream(file, FileMode.OpenOrCreate,...
1
by: Vitaly | last post by:
// Open input file and create the BinaryReader. br = new BinaryReader(new FileStream("Test.dat", FileMode.Open, FileAccess.Read)); // Read binary data. d = br.ReadDouble(); A question is...
3
by: =?Utf-8?B?VmljdG9y?= | last post by:
Hi, Could you tell me can I keep the MemoryStream open and "close" the BinaryReader? As the MemoryStream is used for buffering the TCP data and BinaryReader is only used to read the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.