473,473 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help needed converting VB6 file IO code sample to VB.net

The following code is being used in a VB6 program to read and write a simple
binary file.

I need to move things into the 21st century and recode this in VB.Net

The new VB.Net program will need to continue to operate in the same enterprise
level situation.

Rollout will be slow and so for the moment the new code will have to be able
to read and write these files in the exact same format as the Old VB6 code.

The code is:
-------------------------------------------------------------
Public Type TransferHeader
Hub As String
Version As Long ' I appreciate that this should be an Integer in VB.Net
End Type

Private Sub SetFileHeaderData(Filename As String, Data As TransferHeader)
Dim DataFile As Byte
DataFile = FreeFile()
Open Filename For Binary Access Write As #DataFile
Put #DataFile, , Data
Close #DataFile
End Sub

Private Function GetHeaderOfFile(HeaderFile As String) As TransferHeader
Dim TempHeader As TransferHeader
Dim DataFile As Byte
DataFile = FreeFile()
Open HeaderFile For Binary Access Read As #DataFile
Do Until EOF(DataFile)
Get #DataFile, , TempHeader
If Len(TempHeader.Hub) 0 Then
GetHeaderOfFile = TempHeader
End If
Loop
Close #DataFile
End Function
-------------------------------------------------------------

Does anyone know how to do this?

Many thanks in advance.

--
Rory
Jun 27 '08 #1
3 1231
While I'm not imminently familiar with VB6 it looks like you need to
look around for the FileStream, StreamWriter, and SteamReader
objects. The StreamReader can open the file and using the
StreamReader.Peek() method you can see if there are any more rows left
(Peek returns -1 if EOF). Then use StreamReader.ReadLine to pull the
data out of the row.

Pretty sure thats what you're looking for.

Jun 27 '08 #2
On Apr 22, 9:16*am, "cfps.Christian" <ge0193...@otc.eduwrote:
While I'm not imminently familiar with VB6 it looks like you need to
look around for the FileStream, StreamWriter, and SteamReader
objects. *The StreamReader can open the file and using the
StreamReader.Peek() method you can see if there are any more rows left
(Peek returns -1 if EOF). *Then use StreamReader.ReadLine to pull the
data out of the row.

Pretty sure thats what you're looking for.
Plus the BinaryReader and BinaryWriter classes.
Jun 27 '08 #3
>While I'm not imminently familiar with VB6 it looks like you need to
>look around for the FileStream, StreamWriter, and SteamReader
objects. The StreamReader can open the file and using the
StreamReader.Peek() method you can see if there are any more rows
left
(Peek returns -1 if EOF). Then use StreamReader.ReadLine to pull the
data out of the row.
Pretty sure thats what you're looking for.
Plus the BinaryReader and BinaryWriter classes.
Cheers to you both. I now have a working sample which uses a Binary reader
to retrieve the details from the 1st record in the data. and extract the
Int and the String.

I have managed to resolve the fact that bytes 2 through 6 are the string
I need (All strings will be 4 chars) and the next 2 are the 32 bit integer
I need.

Can someone tell me what the first 2 (values 04 and 00) and last 2 bytes
(values 00 and 00) are for?

Is this to indicate encoding and end of record?

Once I know what these codes mean I should be able to construct the "Writer"
half of the equation.

Thanks once again

--
Rory
Jun 27 '08 #4

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

Similar topics

0
by: Phil B Brubaker | last post by:
I'm converting to VB6 and seeking a way to download Run-Time DLLs only if they are needed on a users win 95 or 98 system. Found some INF code that may do what i'm after. Here is a sample ......
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: Mae | last post by:
Dear All, I have a problem here, I'm using C# Webform calling a webservices. The webservices return me a XMLnode, using this XMLnode I want to convert it to dataset so I can bind to the...
1
by: ACaunter | last post by:
Hi all, I'm in need of audio code for asp.net (listening to it, and also recording audio), then saving the file. if anyone could help that would be great! Also, i need code to modify images,...
1
by: john | last post by:
Hello, I am trying to convert a project from vb6 to vb.net. The code is a sample from an sdk for Canon digital camera's. I have gotten most of the issues resolved, but there are some that I am...
15
by: Jake | last post by:
Hello, We have some code (see below) that has been working intermittently and I was wondering if someone had a better approach or an idea on why we get these errors. This part of code basically...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
3
by: Sun | last post by:
Hi everyone . I have two files named a.txt and b.txt. I open a.txt with ultraeditor.exe. here is the first row of the file: neu für then I switch to the HEX mode: 00000000h: FF FE 6E 00 65...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.