Solved

Initialize Two-Dimension Array

Posted on 2002-04-30
6
162 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 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
Technology Partners: 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

739 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