Asp array questions

Status
Not open for further replies.

glenthas

Ars Tribunus Angusticlavius
6,979
Subscriptor++
I have two questions.

First why does this generate an error:
Code:
<%
dim arrayVar(5)
redim arrayVar(7)
%>
Code:
Error Type:
Microsoft VBScript runtime (0x800A000A)
This array is fixed or temporarily locked
/etab/menusections.asp, line 28

Second, why does this:
Code:
<%
dim arrayIndex
arrayIndex = 0
dim arrayVar(arrayIndex)
%>

Code:
Error Type:
Microsoft VBScript compilation (0x800A0402)
Expected integer constant
/etab/menusections.asp, line 27, column 13
dim arrayVar(iSectionCount)

It looks like I can't declare an array using a variable for the index range. Is there any way around this?

Thanks for your help.

Brian[
Code:
 

temp

Seniorius Lurkius
44
First problem:
Code:
<%dim arrayVar
redim arrayVar(7)%>
works. Vbscript doesn't like it if you redim the array when you have set the size in the original statement, but you can redim it if the size was left unspecified. IIRC it's because the array can be optimized a bit when the array size is set in stone.

Second problem:
Code:
dim arrayIndex
arrayIndex = 0
dim arrayVar
ReDim arrayVar(arrayIndex)
works. It's a slight variant of the same issue.
 
Status
Not open for further replies.