[Webinar] Streamline your web hosting managementRegister Today


Initialize Two-Dimension Array

Posted on 2002-04-30
Medium Priority
Last Modified: 2012-05-04
I'm using VB6 against an SQL Server7 database.
I'm trying to find the best way to clear out or initialize a two dimensional array.

The array is declared as:
Is there an easy way to initialize this array?
Or do I have to do a nested for loop with i,j as indexes?

Thanks in Advance

Question by:jtrapat1
LVL 22

Accepted Solution

rspahitz earned 200 total points
ID: 6981621
You could do it this way:

Dim CodeArray() as string ' create a dynamic array

ReDim CodeArray(750,6) ' sets bounds and loses all data if any previously existed.

LVL 44

Expert Comment

ID: 6981810
what do you want to "initialize" the array to?

What kind of values will you store in CodeArray?


Dim CodeArray(750,6) as Integer

then all entries are AUTOMATICALLY created with the initial value 0.


Dim CodeArray(750,6) as String

then all entries are AUTOMATICALLY created with the initial value "". ( a zero-length string)


Dim CodeArray(750,6) as Variant

then all entries are AUTOMATICALLY created with the initial value Null.

LVL 75

Expert Comment

by:Anthony Perkins
ID: 6981842
Erase CodeArray

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

LVL 75

Expert Comment

by:Anthony Perkins
ID: 6981848
Here is an example from MSDN using Erase:

Erase Statement Example
This example uses the Erase statement to reinitialize the elements of fixed-size arrays and deallocate dynamic-array storage space.

' Declare array variables.
Dim NumArray(10) As Integer   ' Integer array.
Dim StrVarArray(10) As String   ' Variable-string array.
Dim StrFixArray(10) As String * 10   ' Fixed-string array.
Dim VarArray(10) As Variant   ' Variant array.
Dim DynamicArray() As Integer   ' Dynamic array.
ReDim DynamicArray(10)   ' Allocate storage space.
Erase NumArray   ' Each element set to 0.
Erase StrVarArray   ' Each element set to zero-length
   ' string ("").  
Erase StrFixArray   ' Each element set to 0.
Erase VarArray   ' Each element set to Empty.
Erase DynamicArray   ' Free memory used by array.


LVL 15

Expert Comment

ID: 6982340
>Or do I have to do a nested for loop with i,j as indexes?

No, to initialize array to some value, you can also do a loop with m,n as indexes.  ;-)

Expert Comment

ID: 6982403
Or I think array can be saved on DBase as one binary field
(Using append  chunk)

if U mean By Initialization filling by values from DB

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question