Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok this one may be difficault for some of you.

 

 

This is the problem. I have a converter program that converts binary data to text formated data. The class was written in VB6. I would like to convert the class to VBNET.

 

The problem is I don't know anything about Structures except that it replaces Type declerations.

 

Now, when I convert the Type over to structure I have many errors still in my dimentioned varialbles.

 

Example: VB6

Type bLineData
   ByteOfData      As String * 1       '1 Char only
   LotsOfData(25)      As Byte         '25 bytes only
End Type 

 

Change to VBNET:

 

Structure bLineData
   Dim ByteOfData      As String * 1       'Not Working 
   Dim LotsOfData(25)    as Byte           'Not Working
End Structure

 

 

 

If someone could modify the code below, or parts of it and give me example of how I should convert the code to VBNET that would be great.

 

Code Working On:

 

Module modConvert

Type LabelArea
   DateTimeValue(5) As Byte
   FileName            As String * 8   ' Redundent but here
   DeviceName          As String * 10  ' Name of part or part number
   Operator            As String * 10  ' Person that ran/collected test data
   TestingMode As Byte                 ' first bit 0 = TBB, 1 = TBS
   StationName         As String * 1   ' Station A,B,C,D and F
   LotName             As String * 10  ' Lot for device that were tested
   Comment             As String * 50  ' Comments of test
   TimePoint As Integer                ' Test number mostly for HiRel applications\
   SetQuantity As Integer              ' Number of device that were tested
   LoggingRate As Integer              ' Results sorted after N test 1 in 5, 2 in 10
   TestMax As Integer                  ' Number of test used to collect data
   DataBlockNum As Integer             ' Not used currently
   LoggedQuantity As Integer           ' Actual Logged quantity
   IndexMax As Integer                 ' Device Index
   Reserved(17) As Byte                ' Future use
End Type

Type TestItemArea
   TestNumber          As Byte         'Test Number
   ItemGroupCode       As Byte         'Item Group Code
   ItemCode            As Integer      'Item Code
   BEConditionFlag     As Byte         'BE Condition & Flag
   ResultBiasFlag      As Byte         'Result as BIAS Flag
   LimitItemName       As String * 6   'Limit Item Name
   LimitUnit           As Integer      'Limit Unit, second byte not used
   LimitValue          As Single       'Limit Value
   LimitMax            As Single       'Limit Min
   LimitMin            As Single       'Limit Max
   bias1Name           As String * 4   'Bias 1 Name
   bias1Unit           As String * 2   'Bias 1 Unit
   bias1Value          As Single       'Bias 1 Value
   bias2Name           As String * 4   'Bias 2 Name
   bias2Unit           As String * 2   'Bias 2 Unit
   bias2Value          As Single       'Bias 2 Value
   TimeCondition       As String * 4   'Time Condition Name
   TimeUnit(1)         As Byte         'Time Unit
   TimeValue           As Single       'Time Value
   DLIFlags            As Byte         'DL Inhibit Flags
   Reserved(6)         As Byte         'Reserved
End Type

Type WafferData
   wafferID         As Byte            'Always 'W'
   wafferNumber     As Byte            'Waffer Number
   NumberOfDevices  As Integer         'Number of devices
   Reserved         As Integer         'Reserved
End Type

Type DeviceData
   deviceID         As Byte            'Always 'D'
   ZeroZero         As Byte            'Always '00'
   SerialNumber     As Integer         'Number of devices
   BinNumber        As Integer         'Reserved
End Type

Type TestData
   TestNumber      As Byte             'TestNumber
   Flags           As Byte             'Flags
   TestValue       As Single           'Test Resualt Value
End Type

Type bLineData
   ByteOfData      As String * 1       'Extract data for check
End Type






End Module

  • *Experts*
Posted

All arrays dimensioned in VB.NET begin their indexes at zero, so

Dim LotsOfData(25) As Byte actually declares an array with a

length of 26.

 

Fixed-length strings are not supported in VB.NET, as you've

noticed. One way I could think of recreating this effect is an

array of Char variables, so LimitItemName As String * 6 would

change to LimitItemName(5) As Char, although I don't think it's

very efficient to convert between a Char array and a string when

you're changing the value of this variable. There may be another

way around this. If you stuck all these variables in a class, you

could trim the string in the Property accessor subs to ensure its

size does not exceed the maximum you want.

 

It's also worth noting that an Integer in VB6 is 16-bit, but an

Integer in VB.NET is 32-bit. In VB.NET, the 16-bit number variable

is Short. Bytes remain the same old 8 bits.

 

For more info, read the article "Upgrade Recommendation: Avoid

Arrays and Fixed-Length Strings in User-Defined Types" in the

help files.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

Ok, this is starting to get very frustrating. VB.NET is not VB6 at all. If you someone tells you different kick them in the shins!

 

This is the problem:

 

I need to read binary data from a file. In VB6 this is what it looked like:

       Dim getLabelArea As LabelArea 'This is my Structure Code in VB6

'Open file code for binary omitted
           Get(FileInNum, getLabelArea, FileIndex)
           'This would take the Type and store the values read in binary mode into the Type Structure


 

This is VBNET


           Seek(FileInNum, FileIndex)
           Input(FileInNum, getLabelArea) 'I need for getLabelArea to extract the data in the dimentioned order and store the data in the Difined Structure.

 

There maybe another way to read the data binary other than using the FileGet function. If there is where can I get some information or code on this?

  • *Gurus*
Posted

Why not try serialization of classes? You can do that with XML or binary methods, to name two. The days of opening files, loading and parsing are gone, and so are the ones of relying on structures with fixed-length members, let the framework do the work for you.

 

I suggest XML Serialization as a great way to persist classes. It's saved me a boatload of work.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

There is not too much documentation on the XML serialization. I only found 1 document that shows a sample. And it does not look like what I am trying to do.

 

If you could explain, or give sample code of this XML method, please do so.

  • 1 month later...
Posted (edited)

I can't get fixed length arrays to work either, but you can get a fixed length string with this:

 

<vbfixedstring(x)> public StringName as string

 

where x is the number of letters

 

UPDATE:

 

Try using <vbfixedarray(x)> public ArrayName as whatever.

Edited by brian728s
  • 1 month later...
Posted

Update:

 

I have had no problem with the Top structure. The <VBFixedArray(6)> I knew about and was using.

 

To help in your troubleshooting, the section of the file that I am reading and having problems with is the LimitItemName; its stored as ASCII and is 6 char's long.

 

My problem is on the second Stucture when calling it through the file reader:

 


'Module:
   Public Structure LabelArea
       Public DateYearTested As Byte
       Public DateMonthTested As Byte
       Public DateDayTested As Byte
       Public DateHourTested As Byte
       Public DateMinuteTested As Byte
       Public DateSecondTested As Byte
       <VBFixedString(8)> Public FileName As String            ' Redundent but here (8)
       <VBFixedString(10)> Public DeviceName As String         ' Name of part or part number (10)
       <VBFixedString(10)> Public Operator As String           ' Person that ran/collected test data (10)
       Public TestingMode As Byte                              ' first bit 0 = TBB, 1 = TBS (1)
       Public StationName As Char                              ' Station A,B,C,D and F (1)
       <VBFixedString(10)> Public LotName As String            ' Lot for device that were tested (10)
       <VBFixedString(50)> Public Comment As String            ' Comments of test (50)           
       Public TimePoint As Short ' Test number mostly for HiRel applications\
       Public SetQuantity As Short                            ' Number of device that were tested
       Public LoggingRate As Short                            ' Results sorted after N test 1 in 5, 2 in 10
       Public TestMax As Short                                ' Number of test used to collect data
       Public DataBlockNum As Short                          ' Not used currently
       Public LoggedQuantity As Short                         ' Actual Logged quantity
       Public IndexMax As Short                              ' Device Index
       <VBFixedArray(18)> Public Reserved As Byte              ' Future use (18)
   End Structure

   Public Structure TestItemArea
       Public TestNumber As Byte                               'Test Number
       Public ItemGroupCode As Byte                            'Item Group Code
       <VBFixedArray(2)> Public ItemCode As Byte                                'Item Code
       Public BEConditionFlag As Byte                          'BE Condition & Flag
       Public ResultBiasFlag As Byte                           'Result as BIAS Flag
       <VBFixedString(6)> Public LimitItemName As String       'Limit Item Name
       Public LimitUnit As Short                               'Limit Unit, second byte not used
       Public LimitValue As Single                             'Limit Value
       Public LimitMax As Single                               'Limit Min
       Public LimitMin As Single                               'Limit Max
       <VBFixedString(4)> Public bias1Name As String           'Bias 1 Name
       <VBFixedString(2)> Public bias1Unit As String           'Bias 1 Unit
       Public bias1Value As Single                             'Bias 1 Value
       <VBFixedString(4)> Public bias2Name As String            'Bias 2 Name
       <VBFixedString(2)> Public bias2Unit As String            'Bias 2 Unit
       Public bias2Value As Single                             'Bias 2 Value
       <VBFixedString(4)> Public TimeCondition As String       'Time Condition Name (4)
       <VBFixedString(2)> Public TimeUnit As Byte               'Time Unit (2)
       Public TimeValue As Single                              'Time Value
       Public DLIFlags As Byte                                 'DL Inhibit Flags
       <VBFixedArray(7)> Public Reserved As Byte               'Reserved
   End Structure

 

 

This is a stripped down version of what I am doing, the section of code that I am having problems with is noteded below.

Function ConvertFile() As Boolean

'...Inside class function

               FileIndex = 1
               FileGet(FileNum, getLabelArea, FileIndex) ', FileIndex)
               FileIndex = FileIndex + 127

'...Removed Company code...

'...Continue Public code...

                   For i = 1 To getLabelArea.TestMax
                       FileGet(FileNum, getTestItemArea, FileIndex)


                       TestItemL1 = TestItemArea.LimitItemName.ToString  'Always returns 0, not wanted, should return String of Text (6 chr's long)
                       FileIndex = (i * 64) + 128
                   Next i
'...End Public code...
End Function

  • 2 months later...
Posted

Hi, I am having problems with using VBFixedArray's.

 

I am declaring it like so:

 

<VBFixedArray(MaxSize)> Dim myArray() as String

 

but when I go to initialize all the indices like so:

 

For i=0 to MaxSize-1

Template.myArray(i) = ""

Next i

 

I get an error "Object reference not set to an instance of an object"

 

My template is set up as follows:

 

<code>

 

Structure TemplateType

...

<VBFixedArray(MaxSize)> Dim myArray() as String

...

Public Sub Initialize()

ReDim myArray(MaxSize)

End Sub

End Structure

 

Public Template As TemplateType

 

Public Function InitializeTemplate() as Object

...

For i = 0 to MaxSize-1

Template.myArray(i) = ""

'The line above fails

Next i

...

End Function

 

</code>

 

Please help as I have sadly been trying to figure this out for a good 10+ hours.

 

Thank you

ip

Posted

Forget it, problem solved.

 

This was originally a vb6 that i upgraded to .net and it created a initialize function that redim'd myArray, but the initialize function was never actually called, so i just through a call to it in my initialize template function before i started setting myarray(i) equal to anything.

 

Arg, the relief of finding such a simple solution after ragging my brains out for 10+ hours.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...