Link to home
Start Free TrialLog in
Avatar of indyng
indyng

asked on

Why am I getting this error?

Hi Experts,

I have:

Set rs=Server.CreateObject("ADODB.Recordset")

' Query InitializMonths from "FMA Tracker Manager" table
strSQL = "SELECT [FMA Tracker Manager].InitializMonths FROM [FMA Tracker Manager]"
rs.Open strSQL,conn

InitMonths = rs("InitializMonths")

Dim data0(InitMonths)
Dim data1(InitMonths)
Dim labels(InitMonths)


The error is:

Error Type:
Microsoft VBScript compilation (0x800A0402)
Expected integer constant
/intermodal/load_record/AllowancesByEmitter.asp, line 64, column 10
Dim data0(InitMonths)
---------^

How can I fix this?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of indyng
indyng

ASKER

This is what I have:

Dim i
Dim data0()
Dim data1()
Dim labels()

Dim arrMonth(12)

Set rs=Server.CreateObject("ADODB.Recordset")

' Query InitializMonths from "FMA Tracker Manager" table
strSQL = "SELECT [FMA Tracker Manager].InitializMonths FROM [FMA Tracker Manager]"
rs.Open strSQL,conn

i = rs("InitializMonths").Value

ReDim data0(i)
ReDim data1(i)
ReDim labels(i)

Response.Write "InitializMonths:" & rs("InitializMonths") & "<br>"

Still doesn't work

I now get the following error:

Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '13'
/intermodal/load_record/Graph_AllowUsage_RTM_All.asp, line 41

Line 41 is:

  data0(i) = rs("SumOfThisMonthsCalcAllwnce")
Avatar of indyng

ASKER

I think I know why
what is the value of   rs("InitializMonths").Value ?

the subscript out of range means that the array data0 is not size to 13 items.
How about this ?

Dim data0(CInt(InitMonths))
And this:

data0(i -1) = rs("SumOfThisMonthsCalcAllwnce")
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can't use a variable for an array size in a Dim statement.

You have to do

Dim data0()

{...code...}

Redim data0(InitMonths)
Um isn't that what I just said int he previous post?
I see no reason to close and refund.

The question was:

"The error is:

Error Type:
Microsoft VBScript compilation (0x800A0402)
Expected integer constant
/intermodal/load_record/AllowancesByEmitter.asp, line 64, column 10
Dim data0(InitMonths)
---------^

How can I fix this?
"

My answer was that you can't use a variable to size the array if you use Dim you have to use ReDim.

Here are two links with source to prove the answer:

http://lonecrow.net/VariableSizeArray.asp
http://lonecrow.net/VariableSizeArraywitherror.asp


The questioner then moved on to the next issue which is that the value he wanted to use was larger then the size of the array he created.  Someone was helping him with his next issue and now he wants it closed?

I think people would still be willing to continue to help if he left it open. Or they can select an answer and close it.

Not trying to be petty or anything but their first question was answered and then they moved onto another question and now wants a refund? Sounds a bit off to me.
point split: angelIIII , chisholmd
agree
well, ee_ai_construct, that is not the point split I suggestion, or what? 8-)