Solved

Initialize Two-Dimension Array

Posted on 2002-04-30
6
168 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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 Month10 days, 7 hours left to enroll

628 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