Results 1 to 4 of 4

Thread: [RESOLVED] [2005] Struggling with array

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Resolved [RESOLVED] [2005] Struggling with array

    Hello,
    I'm struggling with something that is pretty basic

    I want to create a Products array which stores the product id, a Quantity, and a Value.

    I then want to loop through a DataTable containing the data, and put certain data from this table into the array.

    With the array, I simply want to send this array over to another form (this bit, I can cope with), and display it in a ListView.

    I've been messing around with brackets and curly brackets for ages, to no avail.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Struggling with array

    why not create a list of a structure something like this

    Code:
    Public Class Form1
    
        Private Structure Product
            Sub New(ByVal iID As Integer, ByVal iQuantity As Integer, ByVal iValue As Object)
                ID = iID
                Quantity = iQuantity
                Value = iValue
            End Sub
    
            Dim ID As Integer
            Dim Quantity As Integer
            Dim Value As Object
        End Structure
    
        Private Products As New List(Of Product)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Products.Add(New Product(1, 14, 1.456))
        End Sub
    End Class
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Struggling with array

    If all productid, qty and value are of the same datatype (double, for example) then you can use a strongly typed array... Otherwise, you'll have to declare your array as an array of object then cast it back to the correct type when retreiving the values form the elements... Having said that, it's a bad idea to use an array of objects. So instead, you should create a Product structure or class then create an array of type Product.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Struggling with array

    Excellent. Thanks guys. I'd have never have thought of doing this.

    Something else to learn!!!!
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

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