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

Not Sure What I Need -Generic Collection? 2

Status
Not open for further replies.

UncleCake

Technical User
Feb 4, 2002
355
0
0
US
I have a class that prints invoices. I need to send the print class something (I think a list) that contains three items, which are InvoiceNumber as String, LotCharge as Boolean, CandianCurrency as Boolean.

So, to clarify, this would be a list of about 500 of the three items above. I am not sure how to build the class, but I think I need a generic collection.

I want this in a class because I think that I can use IntelliSense in my form because it I have many forms that will need to print and I need all of the three arguments populated.

-UncleCake
 
A collection is generic. It only sees items as objects. Or you could do an array of objects as well.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Sorry Sorwin, I am not knowledgeable enough about .Net go further. Can you give me a few more hints?
 
I'm kind of confused on what you need then. You know about collections and I said a collection is already generic. You will need to explain better what you need exactly if that didn't answer your question.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Thanks for you follow-up. I am kind of at a road block (mentally) of where to go/what to do. I may be having problems because I am transitioning from VB6 to .Net 2005.

To clarify, I need to build a list of the three items mentioned above and pass it to a print class that will loop through the list and print all of the invoices in the list. I am not sure how to build the list. Like you said, I do know about collections, but I am not sure how to use them in this application.
 
?
Code:
Dim All As New Collection
All.Add(InvoiceNumber)
All.Add(LotCharge)
All.Add(CandianCurrency)
or
Code:
Dim All As Object() = {InvoiceNumber, LotCharge, CandianCurrency}

I'm still not getting it. Do you have some code you need help adjusting? Maybe you could post that.

If you are asking how to make a print class try doing a search here and google to see how people are printing to find what you might want/need then make a class as you need it.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
When you say "generic collection", are you referring to Generics? (
Anyways, you could use one. You definitely do not need to though. I would probably use a Generic List. Here's an example:

Code:
Public Class TestClass
    Public ID As Integer
    Public Name As String
End Class

        Dim MyList As New List(Of TestClass)
        Dim t1 As New TestClass
        t1.ID = 1
        t1.Name = "one"
        Dim t2 As New TestClass
        t2.ID = 2
        t2.Name = "two"
        MyList.Add(t1)
        MyList.Add(t2)
        For Each tc As TestClass In MyList
            MessageBox.Show(tc.Name)
        Next

So you define a list to accept objects of your type, and you add to that list. When you are ready to process them, you loop through them with a For Each construct.

I'm not sure though if you're saying you need to store three different types of objects, or if your objects have three different attributes which you set. If it's the former, then you need to use a "plain" ArrayList, Array, Collection, etc. as Sorwen stated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top