Results 1 to 6 of 6

Thread: Some Quick VB.NET questions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Garden Grove, CA
    Posts
    72

    Some Quick VB.NET questions

    I need some help with figuring out the best way to do somthing.

    In VB6 I would use a UDT like this.

    VB Code:
    1. Type PO_Detail
    2.     PO_Detail_ID
    3.     PO_Number
    4.     Line_Description
    5.     ....
    6.     ....
    7. End Type

    VB Code:
    1. Type Purchase_Order
    2.      PO_Number
    3.      Vendor_ID
    4.      ....
    5.      ....
    6.      PO_Detail()
    7. End Type

    I would just create the object and add elements as I needed (new po line details). I'm wondering in VB.NET is there a better way?

    I am using Structure currently (UDT). Would it be better to use classes?

    Somthing like
    VB Code:
    1. Public Class PurchaseOrder
    2.      Properties, validation, etc
    3.      PurchaseOrderDetail()  'Array
    4. End Class
    5.  
    6.  
    7. Public Class PurchaseOrderDetail
    8.   Properties, validation, etc
    9. End Class

    It seems like a much cleaner way of doing it to me, but i'd like some input.

    Thanks
    Chris Wilson

  2. #2
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    it depends solely on what your requirements of the software is. A struct in vb.net is a static datatype and I prefer not to use it, because you cannot think of it in OO terms... Structs where great in the old C days when you had to make linked lists, but nowadays everything is made with objects.

    If you want to keep it very simple and static, use struct, otherwise create classes. If there are any relations between your data types, classes is the way...

    I have programmed vb.net for 1.5 years now, and I have never used the struct Only classes and objects.

    Maybe that is because I come from the OO world of C++, perhaps things would have been different if I have been a C programmer...

    And as far as i remember, you cannot reference to a struct, only by value (correct me if I am mistaking)

    //Henrik

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    structures should be used only for objects that you aren't going to create to many of. If you create a lot of 'em they use up a lot of resources and will slow your app right down. If you are going to create loads of instances uses classes
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Garden Grove, CA
    Posts
    72
    Classes seem to be the best way to do what i'm looking to do. I have a few more questions though.

    I have a Class for the PurchaseOrderDetails that I'm going to need multiples of in the PurchaseOrder Class. There could be 1, there could be 50. Is there a way to inherit properties from the ArrayList (.add, etc) to the class or do I just have to write my own?

    Thanks
    Chris Wilson

  5. #5
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Hi! if you need a "collection" of objects, I always inherit from the arraylist. There are other ways too, check out the ICollection interface...

    public protected class MyClass : inherits ArrayList
    end class


    //Henrik

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Garden Grove, CA
    Posts
    72
    Originally posted by MrNorth
    Hi! if you need a "collection" of objects, I always inherit from the arraylist. There are other ways too, check out the ICollection interface...

    public protected class MyClass : inherits ArrayList
    end class


    //Henrik
    I've been playing around with this a little and am a bit confused.

    Say I have these classes

    VB Code:
    1. Class PurchaseOrder
    2.    'confusion goes here :)
    3. End Class
    4.  
    5. Class PurchaseOrderDetail : Inherits ArrayList
    6.    'Properties and logic here
    7. End Class

    Is that right for the inheritance?

    I need multiple Details for each PO.
    How would I implement this?

    I know I can use a arraylist in the first class and add the second class to the array list. is there a good way to do it?

    man i'm confused....
    Chris Wilson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width