Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Converting VB6 code to VB 2008

Converting VB6 code to VB 2008

Converting VB6 code to VB 2008

Hello, I am trying to convert some old VB6 programs which were used for file and record management, into VB 2008 format.
I have successfully run the conversion process and debugged any compiler errors.
However any statement which attempts to read from a relative file encounters the error :
"Unable to read past end of stream".
The old VB6 Get and Put statements have all been replaced with Fileget and Fileput and all record
schema are correctly defined in the Modules.
I have checked several Microsoft web-sites but they are not helpful.
Has anyone got any ideas?

RE: Converting VB6 code to VB 2008

Reading past the end of the stream means you've tried to read past the end of the file. Are you using a StreaReader to read the file? Can you post code where you read the file?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: Converting VB6 code to VB 2008

Hello Jebenson, Thank you for your reply. I have enclosed some of the code I am using to search for a record on the file.
The error also occurs when attempting to display all the records from the file :
On Error GoTo err_command1
Dim fname, WVAL As String
wkadd = False
v = Text10.Text
fname = My.Application.Info.DirectoryPath & "\Customers.rdf"
rem Open sample file for random access.
FileOpen(1, fname, OpenMode.Random)
rem WVAL = Mid$(Form1.Text1, 1, 8)
WVAL = InputBox("Enter code to find : ", , WVAL) ' Define record number.
recpos = 1
rem Read the sample file using the FileGet statement **** This causes the 'End of Stream' Error *****
While Not EOF(1)
FileGet(1, cusrec, recpos)
If Trim(CStr(LCase(Mid(cusrec.Accnum, 1, Len(WVAL))))) = Trim(LCase(WVAL)) Then
GoTo lb04
End If
recpos = recpos + 1
End While
MsgBox("Code not found !")
wkadd = True
Text1.Text = WVAL
Text2.Text = " "
Text3.Text = " " : Text13.Text = ""
Text4.Text = " " : Text12.Text = ""
recpos = recpos - 1
Exit Sub
Text1.Text = cusrec.Accnum
Text2.Text = cusrec.CsType
Text3.Text = cusrec.Csname
Text4.Text = CStr(cusrec.Cs_OS)
Text12.Text = cusrec.Csaddr1
Text11.Text = cusrec.CsPcode
Text13.Text = CStr(cusrec.Cs_Ytd)
MsgBox("Click on Save after any changes. " & recpos)
FileClose(1) ' Close
Exit Sub
MsgBox(Err.Description & " " & Err.Number & " " & fname)

RE: Converting VB6 code to VB 2008

>all record schema are correctly defined in the Modules

Sure? For example, an Integer in VB.NET and an Integer in VB6 are different things. Perhaps you could show us your cusrep declaration, and your structure definition.

RE: Converting VB6 code to VB 2008

Sorry, I have only just found the reply as nothing came through to my email. I have attached 2 of the converted structures
from the Module section.

Structure myrec ' Define user-defined type.
<VBFixedString(5),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=5)> Public Accnum() As Char
<VBFixedString(24),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=24)> Public Csname() As Char
<VBFixedString(24),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=24)> Public Csaddr1() As Char
<VBFixedString(16),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=16)> Public Csaddr2() As Char
<VBFixedString(16),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=16)> Public Csaddr3() As Char
<VBFixedString(8),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=8)> Public CsPcode() As Char
'UPGRADE_WARNING: Fixed-length string size must fit in the buffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="3C1E4426-0B80-443E-B943-0627CD55D48B"'
<VBFixedString(5),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=5)> Public CsType() As Char
Dim Cs_OS As Decimal
Dim Cs_Ytd As Decimal
Dim Orptr As Short
Dim Slptr As Short
End Structure
Public cusrec As myrec
Public bval(20) As String
Public dval(20) As String
Public xrec1 As Short

Structure myrec1 ' Define user-defined type.
<VBFixedString(6),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=6)> Public OrdNum() As Char
<VBFixedString(5),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=5)> Public CusOrd() As Char
<VBFixedString(4),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=4)> Public Ord_Type() As Char
<VBFixedString(10),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=10)> Public Ord_date() As Char
Dim Ord_Value As Decimal
Dim Ord_Sts As Short
Dim Olptr1 As Short
End Structure
Public ordrec As myrec1

RE: Converting VB6 code to VB 2008

Ok. And the original VB6 declarations for the UDTs?

RE: Converting VB6 code to VB 2008

These are the VB6 module declarations:

Type myrec ' Define user-defined type.
Accnum As String * 5
Csname As String * 24
Csaddr1 As String * 24
Csaddr2 As String * 16
Csaddr3 As String * 16
CsPcode As String * 8
CsType As String * 5
Cs_OS As Currency
Cs_Ytd As Currency
Orptr As Integer
Slptr As Integer
End Type
Public cusrec As myrec

Type myrec1 ' Define user-defined type.
OrdNum As String * 6
CusOrd As String * 5
Ord_Type As String * 4
Ord_date As String * 10
Ord_Value As Currency
Ord_Sts As Integer
Olptr1 As Integer
End Type
Public ordrec As myrec1

RE: Converting VB6 code to VB 2008

Ok, this *may* be the issue.

VB6's Currency type is 8 bytes
VB.NET's Decimal type is 16 bytes

RE: Converting VB6 code to VB 2008

Thank-you very much for the help.

I found that when I changed all the data-types to string on the record structure then the problem was resolved.

Some extra code was needed for internal data manipulations.

Happy New Year.

RE: Converting VB6 code to VB 2008

It is customary here at TT to give stars for helpful posts.
Click on “Great post!” link to award a star.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close