Home > Software engineering >  For array assignment for many times, how to make the original assigned values are not overwrite, mas
For array assignment for many times, how to make the original assigned values are not overwrite, mas

Time:10-31

Below definition has an array, to array assignment for many times, how to make originally assigned values are not covered,
Dim xshu () As an Integer

1. Open "E: \ database TXT" For Input As # 1
Xshu1=XSH () "' ' ' ' ' ' ' ' ' ' ' ' 'function call
Open "E: \ database 2. TXT" For Input As # 1
Xshu1=XSH () "' ' ' ' ' ' ' ' ' ' ' ' 'function call
Open "E: \ database 2. TXT" For Input As # 1
Xshu1=XSH () "' ' ' ' ' ' ' ' ' ' ' ' 'function call

Illustrate the call () function returns an array of XSH () the value of the assigned to xshu1 array, behind the front covers as a result, how to make the front assigned values will not be at the back of the cover off. Please consult.

CodePudding user response:

"In front of the value of the assigned will not be at the back of the cover off", in front of the assigned values to save where to go?

CodePudding user response:

If in front of 100 number to an array of xshu1 (1) to xshu1 (100), at the back of the assigned value from xshu1 (101) to store, is that ok?

CodePudding user response:

Expand with redim array,

CodePudding user response:

refer to the second floor jiannanyanyu_26 response:
if in front of 100 number to an array of xshu1 (1) to xshu1 (100), at the back of the assigned value from xshu1 (101) to store, is that ok?


Can, of course, and the design method is commonly, you estimate the first xshu1 finally the actual capacity, to leave enough space from the start, such as redim xshu1 (1000).

CodePudding user response:

Use with Preserve keyword Redim statement,

Dim MyArray on () As an Integer 'dynamic array declaration,
Redim MyArray on (5) 'distribution of five elements,
For I=1 To 5 'cycle 5 times,
MyArray on (I)=I 'initialize array,
Next

The following statement redefine the size of the array, but did not remove the element,
Redim Preserve MyArray on (15) 'size weight as 15 element,

CodePudding user response:

Thank you for your help, I finally solved!

CodePudding user response:

reference 5 floor songyaowu reply:
with Preserve keyword Redim statement,

Dim MyArray on () As an Integer 'dynamic array declaration,
Redim MyArray on (5) 'distribution of five elements,
For I=1 To 5 'cycle 5 times,
MyArray on (I)=I 'initialize array,
Next

The following statement redefine the size of the array, but did not remove the element,
Redim Preserve MyArray on (15) 'size weight as 15 element,

Positive solution!
  • Related