We help IT Professionals succeed at work.

How do I convert user-defined types from vb6 to .net

KarlTheHopeless asked
I have a random access file which is used in VB6. The records conform to a user-defined TYPE which has a record length of 2762 bytes.

I have created a STRUCTURE in vb .net which (supposedly) contains the SAME variables - but I seem to have lost 118 bytes in the process.

Why is this so.

Here is my VB6 user-defined type ...


Type Pupildetails

fullname As String * 30: birthdate As String * 10

BEG As String * 1: COMP As String * 1: ESS As String * 1
GRAM As String * 1: READ As String * 1
SPELL As String * 1: VERB As String * 1

Temp As Integer: Eabil As Integer

TotalEngMinutes As Integer
TotalMatMinutes As Integer
NProbs As Integer

FirstEverMatPageFileno As Integer
ExtraEnglish As Integer

ClassYear As Integer: PrintMonthly As Boolean
LongshTest As Integer: PUNC As Integer

Avwords As Integer: Avsents As Integer: Home As String * 1

OpTest As Integer: PrintAnswers As Integer
HandoutTimetab As Integer
IssueNumber As Integer: TheTeacherIs As Integer
TutorNumber As Integer
HandoutFlags1 As Integer
Essential As Integer
EstimatedMabil As Integer
IndSchool As Boolean
PreviousLastMatPage As Integer: Targeting As Integer
PaceControlledBy As String * 1
DoNext As String * 2: Revising As Boolean
ExtraEssential As Integer
TotalMinsWork As Integer
AutoTimes As Integer
nstars(1 To 2) As Integer
StarsToDate As Integer

LastTestDate As Date
LastDeadLine As Date
DaysStretch As Integer
NumberToPrint As Integer: Fee As Integer
AgeLastMatPage As Integer
Deadline As Date
TestDate As Date
ExamDate As Date
ExamToCome As Boolean
EstimatedEabil As Integer
DaysLate(1 To 80) As Integer
UrgencyFactor As Single
AverageOfLastMatPages As Single
Boy As Boolean
BirthdayCardPrintedOn As Date
AvLanguage As Integer
Bulletin(1 To 304) As Byte

PluralsAge As Single: ChoosewAge As Single: spellAge As Single
PuncAge As Single: OppositesAge As Single

ProgressChartUpdated As Boolean
FirstPrintDate As Date
StoredBackUpPoint As String * 30
WhenResetMathsPages As Integer
LowestPresentNoOfResetMathsPages As Integer
PresentNoAtResetOfMathsPages As Integer
Pace As Integer
LangNormForAge As Integer: LangNormForClass As Integer
MathsNormForAge As Integer: MathsNormForClass As Integer
AveNormForAge As Integer: AveNormForClass As Integer

EarlyFinishDate(1 To 4) As Date
LateFinishDate(1 To 4) As Date
YearSixYear As Integer
DecimalAgeOfPupil As Single
DecimalAgeOfClass As Single
MatPageAverages As Single
EngPageAverages As Single
ExpectedMatAge As Single
AheadBy As Single
Asents As Single
Awords As Single
LangAheadBy As Single
grandtotalhoursdone As Single
SomeDataHasBeenWrittenToDisk As Boolean
MyAssessmentOfEabil As Integer
MyAssessmentOfMabil As Integer
ExpectedEngAge As Single
FirstEverMatPagePresentNo As Integer

TestPoint(1 To 10) As Integer
PracPoint(1 To 10) As Integer
Age(1 To 10) As Single
MinsDone(1 To 10) As Integer
PostAgeWrong As Boolean
PastStartBaseForRevision As Boolean
HighestEverMatPage As Integer
DatePrinted(1 To 200) As Date
Spare2 As String * 94

EstimatedAverageAbil As Integer
PlTest As Integer: Check12 As Integer
LastBackUpRecordNo As Integer
HalfWayImageNumber As Byte
Spare3 As Byte
NeedsExtraSpelling As Boolean
Spare4 As String * 1
Spare5(1 To 2) As Integer
AgeOfPupil As String * 6
Spare6(1 To 2) As Integer
PrintDate(1 To 2) As Date
LowestMab As Byte: HighestMab As Byte: Spare7 As Integer
LastMatPage As Integer
PuncTest As Integer: PuncPrac As Integer
ChoosewTest As Integer: ChoosewPrac As Integer
PupilHasTest As Boolean
Unsurpassability As Boolean: TestNumber As Integer

MatPagesOnlyAverage As Single: MatPagesOnlyAheadBy As Single
PuncFinished As Integer: SpellFinished As Integer: ChoosewFinished As Integer
PlFinished As Integer: OppFinished As Integer
Paid As Integer: Pupilosity As Boolean: Wonderfulness As Boolean
Magnitude As Boolean: Magnificence As Boolean
Flag(1 To 10) As Boolean
Cribs1And2 As Boolean

End Type


Here is my STRUCTURE for .NET ...

(The variables **DO** match the TYPE above).


Structure Pupildetails

        <VBFixedString(30)> Public fullname() As String
        <VBFixedString(10)> Public birthdate() As String
        <VBFixedString(1)> Public BEG() As String
        <VBFixedString(1)> Public COMP() As String
        <VBFixedString(1)> Public ESS() As String
        <VBFixedString(1)> Public GRAM() As String

        <VBFixedString(1)> Public READ() As String
        <VBFixedString(1)> Public SPELL() As String
        <VBFixedString(1)> Public VERB() As String
        Dim Temp As Short
        Dim Eabil As Short
        Dim TotalEngMinutes As Short
        Dim TotalMatMinutes As Short
        Dim NProbs As Short
        Dim FirstEverMatPageFileno As Short
        Dim ExtraEnglish As Short
        Dim ClassYear As Short
        Dim PrintMonthly As Boolean
        Dim LongshTest As Short
        Dim PUNC As Short
        Dim Avwords As Short
        Dim Avsents As Short

        <VBFixedString(1)> Public Home() As String
        Dim OpTest As Short
        Dim PrintAnswers As Short
        Dim HandoutTimetab As Short
        Dim IssueNumber As Short
        Dim TheTeacherIs As Short
        Dim TutorNumber As Short
        Dim HandoutFlags1 As Short
        Dim Essential As Short
        Dim EstimatedMabil As Short
        Dim IndSchool As Boolean
        Dim PreviousLastMatPage As Short
        Dim Targeting As Short
        <VBFixedString(1)> Public PaceControlledBy() As String

        <VBFixedString(2)> Public DoNext() As String
        Dim Revising As Boolean
        Dim ExtraEssential As Short
        Dim TotalMinsWork As Short
        Dim AutoTimes As Short
        <VBFixedArray(1)> Dim nstars() As Short
        Dim StarsToDate As Short
        Dim LastTestDate As Date
        Dim LastDeadLine As Date
        Dim DaysStretch As Short
        Dim NumberToPrint As Short
        Dim Fee As Short
        Dim AgeLastMatPage As Short
        Dim Deadline As Date
        Dim TestDate As Date
        Dim ExamDate As Date
        Dim ExamToCome As Boolean
        Dim EstimatedEabil As Short
        <VBFixedArray(79)> Dim DaysLate() As Short
        Dim UrgencyFactor As Single
        Dim AverageOfLastMatPages As Single
        Dim Boy As Boolean
        Dim BirthdayCardPrintedOn As Date
        Dim AvLanguage As Short
        <VBFixedArray(303)> Dim Bulletin() As Byte
        Dim PluralsAge As Single
        Dim ChoosewAge As Single
        Dim spellAge As Single
        Dim PuncAge As Single
        Dim OppositesAge As Single
        Dim ProgressChartUpdated As Boolean
        Dim FirstPrintDate As Date

        <VBFixedString(30)> Public StoredBackUpPoint() As String
        Dim WhenResetMathsPages As Short
        Dim LowestPresentNoOfResetMathsPages As Short
        Dim PresentNoAtResetOfMathsPages As Short
        Dim Pace As Short
        Dim LangNormForAge As Short
        Dim LangNormForClass As Short
        Dim MathsNormForAge As Short
        Dim MathsNormForClass As Short
        Dim AveNormForAge As Short
        Dim AveNormForClass As Short
        <VBFixedArray(3)> Dim EarlyFinishDate() As Date
        <VBFixedArray(3)> Dim LateFinishDate() As Date
        Dim YearSixYear As Short
        Dim DecimalAgeOfPupil As Single
        Dim DecimalAgeOfClass As Single
        Dim MatPageAverages As Single
        Dim EngPageAverages As Single
        Dim ExpectedMatAge As Single
        Dim AheadBy As Single
        Dim Asents As Single
        Dim Awords As Single
        Dim LangAheadBy As Single
        Dim grandtotalhoursdone As Single
        Dim SomeDataHasBeenWrittenToDisk As Boolean
        Dim MyAssessmentOfEabil As Short
        Dim MyAssessmentOfMabil As Short
        Dim ExpectedEngAge As Single
        Dim FirstEverMatPagePresentNo As Short
        <VBFixedArray(9)> Dim TestPoint() As Short
        <VBFixedArray(9)> Dim PracPoint() As Short
        <VBFixedArray(9)> Dim Age() As Single
        <VBFixedArray(9)> Dim MinsDone() As Short
        Dim PostAgeWrong As Boolean
        Dim PastStartBaseForRevision As Boolean
        Dim HighestEverMatPage As Short
        <VBFixedArray(199)> Dim DatePrinted() As Date

        <VBFixedString(94)> Public Spare2() As String
        Dim EstimatedAverageAbil As Short
        Dim PlTest As Short
        Dim Check12 As Short
        Dim LastBackUpRecordNo As Short
        Dim HalfWayImageNumber As Byte
        Dim Spare3 As Byte
        Dim NeedsExtraSpelling As Boolean

        <VBFixedString(1)> Public Spare4() As String
        <VBFixedArray(1)> Dim Spare5() As Short
        <VBFixedString(6)> Public AgeOfPupil() As String
        <VBFixedArray(1)> Dim Spare6() As Short
        <VBFixedArray(1)> Dim PrintDate() As Date
        Dim LowestMab As Byte
        Dim HighestMab As Byte
        Dim Spare7 As Short
        Dim LastMatPage As Short
        Dim PuncTest As Short
        Dim PuncPrac As Short
        Dim ChoosewTest As Short
        Dim ChoosewPrac As Short
        Dim PupilHasTest As Boolean
        Dim Unsurpassability As Boolean
        Dim TestNumber As Short
        Dim MatPagesOnlyAverage As Single
        Dim MatPagesOnlyAheadBy As Single
        Dim PuncFinished As Short
        Dim SpellFinished As Short
        Dim ChoosewFinished As Short
        Dim PlFinished As Short
        Dim OppFinished As Short
        Dim Paid As Short
        Dim Pupilosity As Boolean
        Dim Wonderfulness As Boolean
        Dim Magnitude As Boolean
        Dim Magnificence As Boolean
        <VBFixedArray(9)> Dim Flag() As Boolean
        Dim Cribs1And2 As Boolean

    End Structure


The length of the TYPE is 2762 bytes, but the length of the STRUCTURE is only 2644 bytes.

How can this be so?

Thank you.
Watch Question

For starters, I think you are doing some of the arrays incorectly...
For example one of your arrays
    <VBFixedArray(3)> Dim LateFinishDate() As Date
defines an array with indexes from 0 to 2 (3 elements)

But the old definision was
   EarlyFinishDate(1 To 4) As Date
defines an array with indexes from  1 to 4 (4 elements)


Hello HooKooDooKu

Well, if I define a STRUCTURE as having just ...

           <VBFixedArray(3)> Dim LateFinishDate() As Date

... then, according to .NET, it has a LEN of 32.bytes

So, the number 3 in brackets is surely the UPPER BOUND - not the number of elements - which is going to be one GREATER than the UPPER BOUND.


The problem was with the second pair of brackets; as in ...

<VBFixedString(30)> Public fullname() As String.

The MS UPGRADE software should not have put them in.

The correct code should have been updated to, ...

<VBFixedString(30)> Public fullname As String
Glad you found the answer...

But I though I had read that one of the differences between VB6 and VB.Net was that VB.Net was going to start doing things like C/C++ code... which ment when you declared an array you specified the number of elements, and the 1st element had an index of 1.  VB6, on the other hand, you specified the upper bound of the array, and the lower bound (if not specified ) started at zero, so Dim X(10) created an array from X(0) to X(10).

I wonder if LEN perhaps included some memory space for the array itself (i.e. something that indicates how many elements are in the array) plus the data.  Not sure.that the parts of the structure might be getting allocated on DWORD


Hello HooKooDooKu

In order to keep the **LEN** the same for the ARRAYS I had to change ..

Dim X (1 to 5)


Dim X(4)