Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    311

    Unanswered: simple array work

    can someone show me some basic multidementional array code? I am a C# prog and lookin at vb6 code, i can read it but dont quite get it:

    ' is this arr, col can it have properties?
    TO(TDW).Item(DW_AMT).ErrorCode = "2670"

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Quote Originally Posted by mikezcg
    can someone show me some basic multidementional array code? I am a C# prog and lookin at vb6 code, i can read it but dont quite get it:

    ' is this arr, col can it have properties?
    TO(TDW).Item(DW_AMT).ErrorCode = "2670"
    Which version of VB?

    In VB6, you can create a user defined type, and then an array of these UDTs.

    For instance
    Code:
    Type ErrorType
      ErrorCode Long
      ErrorDescr String
    End Type
    
    Dim udtErrors() as ErrorType
    
    '...
    Redim udtErrors(0)
    
    udtErrors(0).ErrorCode = 7
    udtErrors(0).ErrorDescr = "This is an example Error..."
    
    redim preserve udtErrors (UBound(udtErrors)+1)  ' note the PRESERVE keyword
    
    udtErrors(UBound(udtErrors)).ErrorCode = 9
    udtErrors(ubound(udtErrors)).ErrDescription = "Divide by Zero..."
    '...
    
    Private Sub PrintErrors
      Dim N as Integer
      For N = lbound(udtErrors) to ubound(udtErrors)
        Printer.Print udtErrors(N).ErrorCode, udtErrors(N).ErrorDescr
      Next N
      Printer.Enddoc
    End Sub
    Ref the installment on arrays here

    Note that the above is single-dimension dynamic array of a user defined type.

    VB supports multidimensional arrays, but IF the array is of a standard type, all array elements are of the same type.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Quote Originally Posted by mikezcg
    can someone show me some basic multidementional array code? I am a C# prog and lookin at vb6 code, i can read it but dont quite get it:

    ' is this arr, col can it have properties?
    TO(TDW).Item(DW_AMT).ErrorCode = "2670"
    In VB6, you can create a user defined type, and then an array of these UDTs.

    For instance
    Code:
    Type ErrorType
      ErrorCode Long
      ErrorDescr String
    End Type
    
    Dim udtErrors() as ErrorType    ' dynamic array of ErrorType
    ' or
    Dim udtErrFixed(99) as ErrorType ' Fixed 100 element array of ErrorType
    
    '...
    Redim udtErrors(0)  ' A dynamic array MUST be redimmed before use.  In this case, it is redimmed to a 1 element array.
    
    udtErrors(0).ErrorCode = 7
    udtErrors(0).ErrorDescr = "This is an example Error..."
    
    redim preserve udtErrors (UBound(udtErrors)+1)  ' note the PRESERVE keyword
    
    udtErrors(UBound(udtErrors)).ErrorCode = 9
    udtErrors(ubound(udtErrors)).ErrorDescr = "Divide by Zero..."
    '...
    
    Private Sub PrintErrors
      Dim N as Integer
      For N = lbound(udtErrors) to ubound(udtErrors)
        Printer.Print udtErrors(N).ErrorCode, udtErrors(N).ErrorDescr
      Next N
      Printer.Enddoc
    End Sub
    Ref the installment on arrays here

    Note that the above is single-dimension dynamic array of a user defined type.

    VB supports multidimensional arrays, but IF the array is of a standard type, all array elements are of the same type.
    Last edited by loquin; 02-28-07 at 17:36.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

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