Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Initialize Two-Dimension Array

Posted on 2002-04-30
6
Medium Priority
?
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 22

Accepted Solution

by:
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.

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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

705 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