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

UBound Problem 1

Status
Not open for further replies.

twooly

MIS
Feb 22, 2004
122
US
I am tring to enumerate values within a key in the registry. I am getting this error

Type mismatch: 'UBound' on line 12

Below is my code.

Thanks for the help


Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1

strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &

"\root\default:StdRegProv")
strMasterKeyPath = "SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"
objReg.EnumKey HKEY_LOCAL_MACHINE, strMasterKeyPath, arrSubKeys

For Each Subkey in arrSubKeys
strKeyPath = "SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\" & SubKey
objReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrEntryNames, arrValueTypes
For i=0 To UBound(arrEntryNames)
Select Case arrEntryNames(i)
Case DriverDate
Wscript.echo "Date"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, arrEntryNames(i), strValue
Wscript.echo strValue
Case DriverVersion
Wscript.echo "Version"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, arrEntryNames(i), strValue
Wscript.echo strValue
Case DriverDesc
Wscript.echo "Desc"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, arrEntryNames(i), strValue
Wscript.echo strValue
Case SpeedDuplex
Wscript.echo "Duplex"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, arrEntryNames(i), strValue
Wscript.echo strValue
End Select
Next
Next
 
For some reason it doesnt think that arrEntryNames is an array.
 
Try adding something like this:

If Not IsArray(arrEntryNames) Then
Msgbox "arrEntryNames is not an array!"
Else
For i=0 To UBound(arrEntryNames)
Select Case arrEntryNames(i)
Case DriverDate
Wscript.echo "Date"
objReg.GetStringValue HKEY

[...]

End Select
Next
End If
 
It was just the first entry it found that wasn't an array. I put in what Sheco said and now the script works great since it is testing first.

Thanks
 
twooly,

Check out the return of .enumvalues like this.
[tt]
iret=objReg.EnumValues(HKEY_LOCAL_MACHINE, strKeyPath, arrEntryNames, arrValueTypes)
wscript.echo iret
[/tt]
What do you get?

It is not normal to have to device an additional check isarray() on arrEntryNames. The check should be conducted on the iret. If it is non-zero, then you have problem to proceed further on that subkey. arrEntryNames would return null if error occurs---that's why ubound() is erroneous.

regards - tsuji
 
It was because the first subkey didn't have any values in it hence not creating an array. Just doing the test at the begining is working for me. Thanks for the help.
 
>It was because the first subkey didn't have any values in it hence not creating an array.
I don't think it's the reason. But, I won't argue... Just put a record for other readers.
- tsuji
 
To show you I did what you said and I get 0.
 
>To show you I did what you said and I get 0.
In that case, my guess is that it is winxp. It is a bug to winxp proper. A positive test of isnull() or a negative test of isarray() would do. The right thing is done then.
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top