Solved

Initialize Two-Dimension Array

Posted on 2002-04-30
6
158 Views
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:
CodeArray(750,6).
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

John
0
Comment
Question by:jtrapat1
6 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 50 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.

0
 
LVL 44

Expert Comment

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

What kind of values will you store in CodeArray?

if

Dim CodeArray(750,6) as Integer

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

if

Dim CodeArray(750,6) as String

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

if

Dim CodeArray(750,6) as Variant

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

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6981842
Erase CodeArray

Anthony
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 75

Expert Comment

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

<quote>
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.

</quote>

Anthony
0
 
LVL 15

Expert Comment

by:ameba
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.  ;-)
0
 
LVL 3

Expert Comment

by:Bahnass
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

830 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