Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Help with Multidimensional "Variable" Arrays


Message #1 by jleung@m... on Thu, 13 Feb 2003 11:22:41 -0600
If you go this route and you know the count of the rows, I would ReDim 
once with the proper depth. ReDim'ing is slow. For example on my machine 
(1.7 GHz) with a 10,000 count, the redimming took about 3 seconds. With 
dimming once, it took less than a second.


> If you set up the right tools, a two-dimensional array is farily easy to 
do.
Put the following code in a new project Form1:

Option Explicit

Private mvArray()                       As Variant
Private Const ARR_START_DATE            As Integer = 0
Private Const ARR_AMOUNT                As Integer = 1
Private Const ARR_STOP_DATE             As Integer = 2

Private Sub psLoadArray()
    ReDim mvArray(2, 0)
    mvArray(ARR_START_DATE, 0) = "20030213"
    mvArray(ARR_AMOUNT, 0) = 100
    mvArray(ARR_STOP_DATE, 0) = "20030301"

    ReDim Preserve mvArray(2, 1)		' note the preserve
							' don't mess up 
prior contents
    mvArray(ARR_START_DATE, 1) = "20030214"
    mvArray(ARR_AMOUNT, 1) = 200
    mvArray(ARR_STOP_DATE, 1) = "20030302"

    ReDim Preserve mvArray(2, 2)
    mvArray(ARR_START_DATE, 2) = "20030215"
    mvArray(ARR_AMOUNT, 2) = 300
    mvArray(ARR_STOP_DATE, 2) = "20030303"

    '...etc. -- this is obviously a pretty dumb load...
End Sub

Private Sub psDisplayArray()
Dim i                                   As Integer

    For i = LBound(mvArray) To UBound(mvArray)
        MsgBox "Occurrence " & i & ":" & vbCrLf & vbCrLf & _
               "  Start Date     " & mvArray(ARR_START_DATE, i) & vbCrLf & 
_
               "  Amount         " & mvArray(ARR_AMOUNT, i) & vbCrLf & _
               "  Stop Date      " & mvArray(ARR_STOP_DATE, i)
    Next i
End Sub

Private Sub Form_Load()
    Call psLoadArray
    Call psDisplayArray
End Sub


-----Original Message-----
From: Ian Bambury - JASWW [mailto:email.address@v...]
Sent: Thursday, February 13, 2003 12:50 PM
To: professional vb
Subject: [pro_vb] Re: Help with Multidimensional "Variable" Arrays


You can declare one two-dimensional array of variants, or three arrays of
the correct type, or a single-dimension array of UDT's (user defined types)
e.g.

    Type MyType
        a As Date
        b As Integer
        c As Date
    End Type

    Dim x(200) As MyType

I wouldn't think that an array is necessarily the best way to go. It will
depend on the situation. What are you trying to do?

Ian
  ----- Original Message -----
  From: jleung@m...
  To: professional vb
  Sent: Thursday, February 13, 2003 5:22 PM
  Subject: [pro_vb] Help with Multidimensional "Variable" Arrays


  Dear all,

  Does anyone know how to declare Multidimensional "Variable" Arrays? And
how
  to sort them after you put data in them?

  i.e.
  3 fields to store in multidimensional arrays:

  Start Date  Amount            Stop Date
  20030213    100         20030301
  20030214    200         20030302
  20030215    300         20030303

  Thanks,
  Jason


  ---
  Change your mail options at http://p2p.wrox.com/manager.asp or
  to unsubscribe send a blank email to 


---
Change your mail options at http://p2p.wrox.com/manager.asp or
to unsubscribe send a blank email to 


  Return to Index