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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting VB6 code to VB 2008

Status
Not open for further replies.

Ken01

Programmer
Aug 8, 2014
62
GB
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?
 

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!
 
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
FileClose(1)
Text2.Text = " "
Text3.Text = " " : Text13.Text = ""
Text4.Text = " " : Text12.Text = ""
recpos = recpos - 1
Text2.Focus()
Exit Sub
lb04:
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
err_command1:
MsgBox(Err.Description & " " & Err.Number & " " & fname)
FileClose(1)
 
>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.
 
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
 
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
 
Ok, this *may* be the issue.

VB6's Currency type is 8 bytes
VB.NET's Decimal type is 16 bytes
 
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.

 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top