Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET equiv. to VB6.0 FileGet( )

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
CA
Hey guys,

I have a random data file (although I know that I need it broken into chunks of 114 characters), and I need to parse it and load it into a database.

We have an old application that does this (written in VB6.0), but we want to add functionality and am re-writing this in .NET. The legacy app is using the FileGet() method and a structure to load the values we need from this datafile, but I'm having problems duplicating this within .NET. It seems that when I extract the text from my code, and dump it out to a text file record-by-record, there are these weird block characters that throw off the index count for when I'm doing my substring calls.

I know that you can still use the VB6.0 library within .NET, but I'd love to find a way within vb.net.

Any thoughts?

Thanks,

D'Arcy
 
In VB.NET file I/O is designed to be object-like... Try this reference on MSDN


Fair warning though... I've discovered that if I am opening and closing a file very quickly, I get errors from the program stepping on its own toes and trying to open the file before closing it again. Easiest fix for this is to open the files at the beginning of your program and close them at the end.
 
D'Arcy,

What I am doing (and it works) in PC and WinCE device is to use BinaryReader and BinaryWriter classes for the best performance. This tricky part is getting the structure defined properly - especially the string components. Most likely you are using fixed len strings?

Post your VB6 structure definition so I may have more information to digest to see if I can furthur assist (if you want it).

I am NOT pleased by how difficult MS has made writing and reading structure's in VB.NET - especially structures with fixed len strings. It is not a trivial task and is frankly much easier to do in VB6. Serialization is the easy way in VB.NET but preceeds the structure with a bunch of metadata info that bloats the file and oh yeah Serialization is not supported in WinCE.

Regards,
Terry
tnygaard@lcra.org
 
Not a fixed length string. I'm only using the file IO for writing ASCII characters from a telnet server's sentdata.

Here's what I have now that seems to work fine for me.

Code:
    Sub WriteTextToFile(ByVal ToFile As String)
        On Error GoTo ErrHandle

        Dim i As Long
        For i = 1 To ToFile.Length
            If Asc(Mid(ToFile, i, 1)) < 32 Or Asc(Mid(ToFile, i, 1)) >= 127 Then CharFile.WriteLine(Asc(Mid(ToFile, i, 1)).ToString & " ")
        Next
        Exit Sub

ErrHandle:
        MsgBox(Err.Number & Err.Description & "WriteTextToFile")
        Resume Next
    End Sub

I used to have the Dim CharFile As New System.IO.StreamWriter("D:\charfile.txt") in the beginning of that sub, and CharFile.Close at the end of the sub. I've since moved them to the Load and Closed subs of the form respectively and that seemed to work out the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top