Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dim array with variable initial index

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm coding an application to study some mathematical
functions.
It needs that a tridimesional matrix is initialized according to user's indications, CHANGING THE INITIAL AND FINAL RANGE OF THE FIRST INDEX.
IE
If user writes 2 values, initial and final, that are stored in variables START and END in my wishes code should be:

dim matrice (start to end , 500 to 1000, 1 to 100)
for x=start to end
for y= 500 to 100
for z= 1 to 100
.....
alfa (x,y,z)=something.....
next
next
next

But VB6 gives error message at dim matrice (start to end....
sayng that a constant is needed for initialization.
It works if code is
dim matrice (4000 to 5000, ....

but gives arror indicating variables.

I tried to give as initial index the difference between End and Start

delta=end-start
dim matrice (delta, 500 to 100, 1 to 100)
for x=start to end

and this is fine, but then the error comes when it goes to
create the alfa(x,y,z), sayng that index is not right: in my wishes the first index should be 4000, while VB6 expects 1.
I tried also a dynamic matrix but it gives same error.
Any help to override this problem would be greatly
appreciated.
Gipodiablo
 
John, thank u for your kind reply.
Unfortunately, as I said in my first message, I tried also the redim , but it gives the same error, u can see it if u try it.
Redim changes the dimensions of indexes, but NOT the initial and final mark of the indexes
Problem seems to be that, with either dim o redim functions, variables are not accepted as first and final marks of the index's range.
But it must be a solution.....
 
"but gives arror indicating variables."

What error? Expected Identifier?

End is not a valid identifier. You can not use TO when dimensioning in VBScript. All arrays are 0-based.

This the VBScript documentation for Dim.
"Arguments
varname
Name of the variable; follows standard variable naming conventions.
subscripts
Dimensions of an array variable; up to 60 multiple dimensions may be declared. The subscripts argument uses the following syntax:
upperbound [,upperbound] . . .
The lower bound of an array is always zero. "


Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thank u a lot John, u got it!
It works with redim
My error was to declare the dynamic matrix() in the wrong place, that is in the routine start, instead of the right place (General Declarations of the module).
Gipodiablo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top