0

I'm attempting to create and fill in a two-dimensional array in VBScript, which resides in an ASP page. I have the following code:

Dim array(11, 6)

For record = 0 To 6
    array(6, record) = 8
    array(7, record) = "test"
Next

array(6, 3) = 8
array(7, 3) = "test"

The for loop doesn't work, though. Nothing gets filled in. If I do it explicitly, like the code after the loop, that works just fine.

I've hardly ever used VBScript before but this seems like it should work. Why is my loop not doing anything?

10
  • 1
    Don't you need to increment record in there somehwere? ;-) Commented Sep 6, 2011 at 14:20
  • 1
    That's what the FOR loop does, right? Commented Sep 6, 2011 at 14:21
  • It's a for loop; shouldn't that happen automatically? Even if not, the 0th element doesn't get filled in (and it doesn't loop forever). Commented Sep 6, 2011 at 14:21
  • Don't vbscript arrays start at 1? Commented Sep 6, 2011 at 14:22
  • 2
    @ghostdog74 - no, "Dim a(11,6)" creates a 12 x 7 FIXED array. Commented Sep 6, 2011 at 14:54

1 Answer 1

2

Your "doesn't work" doesn't work. You'll have to describe exactly what you expect and what happens instead. Otherwise -

Dim a(11,6)
For i = 0 To 6
    a(6,i) = i
    a(7,i) = "test"
Next
WScript.Echo a(6,0),a(7,0)
WScript.Echo a(6,6),a(7,6)

0 test
6 test

Is there an evil "On Error Resume Next" active?

WRT the OERN:

You could insert an "On Error GoTo 0" immediately before the critical/new code and continue driving with your eyes shut with an "On Error Resume Next" immediately after it.

Or: copy the new code into a clean/empty .vbs to be used by cscript.exe

Or: post the relevant part of the code completely.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, there is an On Error Resume Next. I can't really do a whole lot in the way of error checking because this is embedded in an ASP page (code which hasn't been touched in 10 years, too).
I used an On Error GoTo 0 and received a "Variable is undefined" error. I shouldn't have to explicitly define each element in the array, right?
I would imagine that it's because record is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.