Converting from UDT to structure or object - please help

C

Clark Stevens

I have a program that I'm converting from VB6 to VB.NET. It reads in a text
file containing barcode numbers and their corresponding descriptions. Then
the user enters the barcode number and the program finds the matching
barcode description.

In VB6 I used an UDT to store the barcode number along with the description.
Then I declared an array of the barcode UDT.

I'm thinking of converting the UDT to a structure in VB.NET and doing
something like this:

Structure BCStructure
BCNumber as Integer
BCDescription as String
End Structure

Public BC() as BCStructure

Is there a more efficient way to handle this in VB.NET? Should I setup a
barcode class and use an object collection instead? What are the
advantages/disadvantages?

All suggestions welcome
 
K

Klaus H. Probst

That's OK as long as you're not going to change the number of items in the
array, because .NET arrays are immutable.

But you can use an ArrayList, or a Hashtable or any of the other container
classes.

But your approach is pretty much there.
 
H

Herfried K. Wagner [MVP]

* "Clark Stevens said:
I have a program that I'm converting from VB6 to VB.NET. It reads in a text
file containing barcode numbers and their corresponding descriptions. Then
the user enters the barcode number and the program finds the matching
barcode description.

In VB6 I used an UDT to store the barcode number along with the description.
Then I declared an array of the barcode UDT.

I'm thinking of converting the UDT to a structure in VB.NET and doing
something like this:

Structure BCStructure
BCNumber as Integer
BCDescription as String
End Structure

Public BC() as BCStructure

Is there a more efficient way to handle this in VB.NET? Should I setup a
barcode class and use an object collection instead? What are the
advantages/disadvantages?

If that's a good solution depends on the number of barcodes. These days
we finished a project for university (written in Java :-() that was
connected to a barcode scanner to scan barcodes placed on walls. We
only had 10 barcodes in our sample, and there will never be more than
100 barcodes. So we simply used a text file containing the number
followed by a tab and followed by the description or a filename and
loaded it into an array/collection. Then we used linear search to find
the item.

Your records are very small, and if there are only few of them, using an
array is IMO a good solution. For string IDs, I would use a hashtable,
but that's not the case for simple barcode scanners. If there are lots
of items and managing them and searching is a complicated process, using
a database may be the better solution.
 
C

Clark Stevens

Herfried K. Wagner said:
we finished a project for university (written in Java :-() that was
connected to a barcode scanner to scan barcodes placed on walls. We
only had 10 barcodes in our sample, and there will never be more than
100 barcodes. So we simply used a text file containing the number
followed by a tab and followed by the description or a filename and
loaded it into an array/collection. Then we used linear search to find
the item.

This program will be used with a barcode scanner as well. I don't
anticipate there being a lot of records, so it sounds like I am on the right
track here. I thank you, and everyone else who responded, for your help.
This newsgroup is great!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top