Big Chemical Encyclopedia

Chemical substances, components, reactions, process design ...

Articles Figures Tables About

Dynamic Arrays in VBA

It is often the case that it is not known ahead of time how large an array s dimensions need to be. It is wasteful of memory (and poor programming practice) to simply make the dimensions arbitrarily large. To circumvent this problem, VBA provides the ReDim statement so that the dimensions of an array do not have to be hard coded in the program. [Pg.42]

To illustrate the use of ReDim, one more version of the example program is shown. The input data format is changed so that the very first number in the list is not one of the numbers to be averaged, but it indicates how many numbers there are (and thus the required size of the array that holds the numbers). In this version, the dimension of InputNumbers is left blank (note the empty parentheses), and then the following statement makes the dimension what it needs to be  [Pg.42]

Another approach that does not require the number of data items known in advance is to again use a While loop to detect a zero or sentinel value and put a ReDim statement within the While loop. When designing a program, it is wise to think of different ways in which to accomplish the same task. [Pg.42]

Dim ANunber As Double A number obtained frcm the spreadsheet [Pg.42]

Dim InputNumbers ( As Double array of numbers the Enpty parentheses) [Pg.42]


Numerical Methods for Chemical Engineers Using Excel , VBA, and MATLAB 2.13.2 Dynamic Arrays in VBA... [Pg.42]




SEARCH



Arrays in VBA

Arrays, dynamic

VBA array

© 2024 chempedia.info