Converting VB6 Fileopen/input/close to vb.net

R

Robert Styma

I am converting a VB6 program to VB .net and trying to
get the last vestages of VB6 out. There are many places in this
program that use fileopen, followed by a bunch of calls to the input
function to get data and then fileclose. The files were created with
fileopen/print/println/fileclose so all the quotes and spaces are in the
correct places for the input function. It is not practical to change the
format
of these files.

My question involves, what do I use in place of the input() call?

My searches on Google have been less than helpful. The input function is
not really a good search term. :)
Here is a code fragment which shows what I am looking at:
Dim ClientFileName As String
Dim EventTitle As String = ""
Dim EventRound As String = ""
Dim StatChange As Short
Dim FirstReq As String = ""

ClientFileName = "C:\TABW\JUDGES\HOST.TAB"

On Error GoTo ReadError
FileOpen(1, ClientFileName, OpenMode.Input, OpenAccess.Read,
OpenShare.Shared

Input(1, EventTitle)
Input(1, EventRound)
Input(1, StatChange)
Input(1, FirstReq)

FileClose(1)

Sometimes I a reading numbers and sometimes character strings (in quotes).

Any pointers would be most appreciated.
 
S

Steven Cheng [MSFT]

Hi Robert,

As for the VB6 file api, based on my testing , in .net framework, these
file functions are still supported (under Microsoft.VisualBasic namespace)
for back compatible purprose. Here is a simple test function I used in
VB.NET to read the file with those vb6 funcctions:

-=============================

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim file_num As Integer = FreeFile()

' Open the file.
Dim file_name As String = "..\..\data.txt"

FileOpen(file_num, file_name, _
OpenMode.Input, OpenAccess.Read, OpenShare.Shared)


Dim str As String = ""


Dim i, j As Integer
Dim f As Single

str = LineInput(file_num)
TextBox1.AppendText(vbCrLf & str)

Input(file_num, i)
TextBox1.AppendText(vbCrLf & i)

Input(file_num, j)
TextBox1.AppendText(vbCrLf & j)

Input(file_num, f)
TextBox1.AppendText(vbCrLf & f)


' Close the file.
FileClose(file_num)


End Sub
End Class
==============================

For standard binary file read/write, in .NET, you can use BinaryReader
/BinaryWriter class. BTW, binary file format these class expected may
differ from other platform such as VB6, JAVA, C++ ....

#BinaryReader Class
http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.aspx

#NET Streams Explained
http://www.ondotnet.com/pub/a/dotnet/2003/04/14/streams.html

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Robert Styma

H Steven,
I have the progam working with the fileopen call from the Visual Basic
namespace. I was looking at what it would take to get rid of the
visual basic namespace completely. Most of the old VB functions have
..net method equivalents. mid -> String.substr, etc. The equivalents for
open and
close are pretty straightforward, however I have not found something that
behaves the same as the Input(fileno, target) function.

--
Robert Styma
Principal Engineer (DMTS)
Alcatel-Lucent
 
S

Steven Cheng [MSFT]

Thanks for your reply Robert,

As for the VB6 compatible file ip api in VB.NET, it comes from the
Microsoft.VisualBasic.FileSystem class. I've performed some investigation
through reflector code. Unfortunately, FileSystem class use a completely
stand alone components set for those VB6 file methods(such as FileOpen,
Input, .....) rather than use the .NET standard System.IO components
internally. That also proves my former consideration that the binary file
parsing between VB6 and .NET are not quite compatible.

Currently, for those binary forma files that are originall generated via
VB6, I suggest you remain accessing them via the Microsoft.VisualBasic's
file api. Meanwhile, I suggest you consider start convert them to the
format generated by System.IO classes if possible. BTW, for further
interoperability consideration, Text/XML based file is always the preferred
choice which can be used seamlessly among multi platform.

If you have any further questions, welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?Um9iZXJ0IFN0eW1h?= <[email protected]>
References: <[email protected]>
Subject: RE: Converting VB6 Fileopen/input/close to vb.net
Date: Wed, 2 Apr 2008 06:53:00 -0700
 
R

Robert Styma

Hi Steven,
Thank you for your response. The bottom line is that the functionality
provided by the input() no longer exists. The darth of information on the
web was due to the fact that it does not work that way any more. The files I
am reading are text files containing numbers and quoted strings. Some are
blank delimited and some are comma delimited. I thnk my approach is going to
be to use a bit of polymorphism. Make a class named strinput with several
instances of a routine named input which takes 2 parameters by reference.
The new filesystem classes have a method which will eat a whole file in one
swallow and spit it out as a single string. That is the first parameter to
my input() functions. The second parameter is a string or and integer or a
short or a double or a single. Lop off the next piece and convert it to the
correct type. That will minimize my impact on the existing code and give me
a performance boost too.
--
Robert Styma
Principal Engineer (DMTS)
Alcatel-Lucent
 
C

Cor Ligthert[MVP]

Robert,

Don't mix up the name of a namespace with .Net

The Microsoft namespace contains VisualBasic which is a full part of
Microsoft .Net

Beside that there are more namespaces like the more general System
namespace.

Those both are full parts of Net, so trying to find equivalents of both of
them is a little bit a waste of time while often parts in the Microsoft
namespace optimizes the parts in the System namespace.

Cor
 
S

Steven Cheng [MSFT]

Thanks for your reply Rebert,

If the file format is of text, then, you can use the new StreamReader or
BinaryReader classes (wrapper filestream) in System.IO namespace to read
the file. However, you may need to manually read out those
characters(according to the file format and value offset...) and parse them
into the actual values(number or other types).
Just like you need to rewrite the file parsing code for the original file
with new classes.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?Um9iZXJ0IFN0eW1h?= <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: Converting VB6 Fileopen/input/close to vb.net
Date: Wed, 2 Apr 2008 19:45:00 -0700
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top