Go Back   Access World Forums > Microsoft Access Reference > Access FAQs

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 06-20-2010, 04:57 PM   #1
ajetrumpet
Banned
 
Join Date: Jun 2007
Location: Universe - Local Group - Milky Way Galaxy - Orion Arm
Posts: 5,640
Thanks: 0
Thanked 100 Times in 47 Posts
ajetrumpet has a spectacular aura about ajetrumpet has a spectacular aura about
Send a message via MSN to ajetrumpet Send a message via Yahoo to ajetrumpet
VBA Create Array

Static / Fixed Arrays

These are manually dimensionalized. Dimensions and number of elements are defined manually when arrays are declared. Short example:

Code:
    Dim myarray(6) As Variant
These have to be populated from their declaration specs. For example:

Code:
dim i as long

   for i = 0 to 5
      myarray(i) = i
   next i
Dynamic Arrays

These are unspecified in terms of dimensions and number of elements. Example:

Code:
    Dim myarray() As Variant
These have to be redimensionalized everytime an element or a dimension is added. The ReDim statement is used for this. Using ReDim alone will empty the area everytime it is redimensionalized so you have to populate it afterwards. Use this on arrays with more than one dimension. Example:

Code:
dim i as long
dim j as long

   for i = 0 to 5
      for j = 0 to 10
         ReDim(i, j)
      next j
   next i
Using ReDim Preserve saves the values that are already in the array and also redimensionalizes it. It saves time for one-dimensionals, like:

Code:
dim i as long

   for i = 0 to 5
      ReDim Preserve myarray(i)
      myarray(i) = i
   next i
More than one dimension usually does not work with Preserve because the last dimension must not be manipulated when using the key word.

ajetrumpet is offline  
The Following 2 Users Say Thank You to ajetrumpet For This Useful Post:
hassanogaibi (06-28-2016), Tango (07-19-2012)
 

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a SQL statement in VBA xzmilan Modules & VBA 7 03-12-2010 07:09 AM
Create a new .mdb with vba Somebody General 1 07-07-2008 09:17 AM
A control array in VBA like in VB6 is that possible? Guus2005 Modules & VBA 4 06-13-2008 05:16 AM
[Access 2007] How do i create table in VBA dibangdit Modules & VBA 2 05-21-2008 08:32 PM
Formatting Error with VBA Array? M_S_Jones Modules & VBA 3 03-07-2008 05:55 AM




All times are GMT -8. The time now is 04:33 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World