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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redim Preserve mulipleDimArray

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
0
0
US
I am having a problem rediming my array. Here is my code:

Dim Region, strComputer, oshell
Set oshell = CreateObject("wscript.shell")
strComputer = Array("ereplandemoas5")
const HKEY_LOCAL_MACHINE = &H80000002
Region = Array(0,1)
For p = 0 To UBound(strComputer)
wscript.echo strcomputer(p)
Computer = strcomputer(p)
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&Computer&"\root\default:StdRegProv")
if oReg.EnumKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI",arrKeys) = 0 Then
i=0
For Each strKey In arrKeys
If Left(strKey,17) = "ersys0dataaccess_" Then
i=i+1
ReDim Preserve Region(i,1)
Region(i,0) = replace(strKey,"ersys0dataaccess_","")
If left(ucase(oshell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\"&strKey&"\Driver")),8) = "C:\WINNT" Then dbms = "MSSQL"
If left(ucase(oshell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\"&strKey&"\Driver")),9) = "C:\SYBASE" Then dbms = "SYBASE"
Region(i,1) = dmbs
End If
Next
End If

call expandArray()

If Err.Number <> 0 Then
getError(Err.Number)
End if

Next

Here is the error:
Subscript out of range Line 16

I know what that means, but I am not sure why I am getting that.

Any help?
 
ralphtrent,
Try just Redim'ming the first index:

Redim Preserve Region(i)

The reminaing dimension(s) should follow, so you should then be able to set Region(i, 0) and Region(i, 1).

Zy
 
Hello ralphtrent,

[1] It is declared
Region=Array(0,1)
It is something very different from
Dim Region(0,1)

[2] I see it shaky in err.number placing so far back from the lines which might cause trouble. But, if it works for you, that's fine.

[3] With your true intention, even with [1] corrected, your region(0,0) and region(0,1) are still unsettled. If you use later only starting from region(1,.), that's fine. Just in case,...

[4] A slight typo at the end
region(i,1)=dmbs (should be =dbms)

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top