Does VBScript create a multidimensional array and add to it?

This is crazy for me haha, I almost checked almost every page on Google Search, and I still don’t understand how to do this.

I want to create a multidimensional array in VB Script called data2. Having tried the examples that I saw, but I get the error "Subcategory out of range"

Dim data2()

sub grabdata
    SQL_query = "SELECT * FROM MSAccess_table"
    Set rsData = conn.Execute(SQL_query)
    Do Until rsData.EOF = True
        ReDim Preserve data2(UBound(data2) + 1)
        data2(UBound(data2)) = Array(rsData("id"),rsData("column_1"),rsData("column_2"),rsData("column_3"),rsData("column_4"))
    rsData.moveNext 
    Loop
end sub

Basically, I'm trying to learn how to create a multidimensional array in VB Script and add a loop to it. What are some basic examples that might work in my case?

+4
source share
3 answers

(1) ADO - GetRows. .

(2) VBScript . , UBounds:

Dim aFix(2, 3)

. ReDim [Preserve]. -

ReDim aDyn(2, 3)

Dim aDyn : aDyn = Array()

. 22: Preserve .

(3)

Dim data2()

- . , "" , , VBScript :

>> Dim data2()
>> WScript.Echo UBound(data2)
>>
Error Number:       9
Error Description:  Subscript out of range

Dim a() - , ReDim :

>> Dim data2() ' <-- abomination
>> ReDim data2(1,1) ' <-- overwritten by a dynamic array
>> data2(0,0) = 0
>> ReDim Preserve data2(1,5) ' last dimension increased; 'old' data preserved
>> data2(1,5) = 1
>> WScript.Echo data2(0,0), data2(1,5)
>>
0 1

wrt jmbpiano:

(1) , UBound dimmed with(), , . ( ), , () .

(2) , ReDim a(KnownUbound) "" , "Option Explicit" - . :

Option Explicit
ReDim a(4711)
ReDim b(4,7,1,1)
a(0) = "qed"
b(0,0,0,0) = "qed"
WScript.Echo b(0,0,0,0)

:

cscript 19888987.vbs
qed
+8

, , , ADO: GetRows()?

    sub grabdata
        SQL_query = "SELECT * FROM MSAccess_table"
        Set rsData = conn.Execute(SQL_query)
        If Not rsData.EOF Then aData = rsData.GetRows()         
    end sub

# , () - .

, , :

If IsArray(aData) Then
    For x = lBound(aData,2) to uBound(aData,2) 'loops through the rows
        Col1 = aData(0,x)
        Col2 = aData(1,x)
        Col3 = aData(2,x)
        Response.Write "Row #" & x+1 & "<br>"
        Response.Write "This is the data in Column1: " & Col1 & "<br>"
        Response.Write "This is the data in Column2: " & Col2 & "<br>"
        Response.Write "This is the data in Column3: " & Col3 & "<br>"
    Next
End If

* . ( ) 0 .

+1
set rs = conn.execute(strQry)

arrRAY = rs.GetRows()

if isarray(arrRAY) then
  do stuff
end if
-2
source

All Articles