burnsc
(Starting to like KiXtart)
2005-09-13 03:41 PM
First Shot at dynamic multi-dim arrays

Can someone give me a hand with this function to tell me where I am going wrong. It is erroring on the redim of the array. At first I thought it was because I was not specifying the second dimension in the original dim, but I fixed that and it is still not working. I cant think of another problem that may be hitting this.
Code:

Function ArrayEnumValues($RegSubKey)
Dim $ValArray[0,1], $VANdx
$VANdx = 0
$Names = ArrayEnumValueNames($RegSubKey)
For $VANdx = 0 to UBound($Names)
ReDim Preserve $ValArray[$VANdx, 1]
? $Names[$VANdx]
; $ValArray[$VANdx,0] = $Names[$VANndx]
; $ValArray[$VANdx,1] = ReadValue($RegSubKey, $Name)
Next
$ArrayEnumValues = $Names
EndFunction



Many thanks


Les
(KiX Master)
2005-09-13 03:44 PM
Re: First Shot at dynamic multi-dim arrays

IIRC, multi-dim arrays cannot be redimmed.

burnsc
(Starting to like KiXtart)
2005-09-13 03:51 PM
Re: First Shot at dynamic multi-dim arrays

ARRRGGGHHHHH, I did not want to hear that. That is going to make this even more fun. (We need a crying emotiocon )

That means I have to size up what I need before I originally dim the array.

Thanks for the information


Richard H.Administrator
(KiX Supporter)
2005-09-13 03:53 PM
Re: First Shot at dynamic multi-dim arrays

You may redim multi-vectored arrays, but you may only redim the right-hand index when you are using the PRESERVE keyword.

In other words,
"ReDim Preserve $ValArray[$VANdx, 1]" will not work, but "ReDim Preserve $ValArray[1,$VANdx]" is fine.


burnsc
(Starting to like KiXtart)
2005-09-13 04:09 PM
Re: First Shot at dynamic multi-dim arrays

I finally got this working. Once my mind got going I thought about declaring the var when I had enough info to do it. That way I don't have to redim. My problem now is testing the multi dim array outside of its function. Here is my full code . Can I get a pointer on this?

If I treat the result as a 1 dim array (? $Vals[$Ndx1]) it goes fine, but as soon as I let it show it is a multidim, I ge the error that kix expects ']'. As I provided this I am perplexed.

Code:

$Vals = ArrayEnumValues("HKEY_Local_Machine\Software\Clients\IM\Windows Messenger\InstallInfo")
For $Ndx1 = 0 to UBound($Vals)
? $Vals[$Ndx1,0]+ " = " + $Vals[$Ndx1,1]
Next
Get $x

Function ArrayEnumValues($RegSubKey)
$VANdx = 0
$Names = ArrayEnumValueNames($RegSubKey)
Dim $ValArray[UBound($Names),1], $VANdx
For $VANdx = 0 to UBound($Names)
$ValArray[$VANdx,0] = $Names[$VANndx]
$ValArray[$VANdx,1] = ReadValue($RegSubKey, $Name)
Next
$ArrayEnumValues = $Names
EndFunction



Richard H.Administrator
(KiX Supporter)
2005-09-13 04:20 PM
Re: First Shot at dynamic multi-dim arrays

Read my post or look up the manual page for ReDim where the action of the PRESERVE keyword on multi-dimension arrays is explained.

Richard H.Administrator
(KiX Supporter)
2005-09-13 04:25 PM
Re: First Shot at dynamic multi-dim arrays

Are you sure that you are returning the correct array here:
Code:
  $ArrayEnumValues = $Names



Shouldn't that be:
Code:
  $ArrayEnumValues = $ValArray



burnsc
(Starting to like KiXtart)
2005-09-13 04:39 PM
Re: First Shot at dynamic multi-dim arrays

OOOPS... Thanks(that makes 2 times today I have missed a proper return array var). Almost time to kick myself

I read your reply about the rediming. I will probably try a test on that soon, but since I already had the info needed to dim properly, it will take less processor cycles this way, so I will use what I had at this point for the 'formal' diming.

That and I found another error too. I missed a character in a var name. Here is the final function for those of you interested. I will try to work up a header and submit this more formally in the coming week.

Code:

Function ArrayEnumValues($RegSubKey)
$VANdx = 0
$Names = ArrayEnumValueNames($RegSubKey)
Dim $ValArray[UBound($Names),1], $VANdx
For $VANdx = 0 to UBound($Names)
$ValArray[$VANdx,0] = $Names[$VANdx]
$ValArray[$VANdx,1] = ReadValue($RegSubKey, $Names[$VANdx])
Next
$ArrayEnumValues = $ValArray
EndFunction



Richard H.Administrator
(KiX Supporter)
2005-09-13 04:46 PM
Re: First Shot at dynamic multi-dim arrays

Use SetOption("Explicit","ON") - it will save you a lot of aggravation.

BTW, you are implicitly declaring $VANdx by assigning a value to it, then you are explicitly declaring it in a DIM statement a couple of lines later on.

Code:
  $VANdx = 0
$Names = ArrayEnumValueNames($RegSubKey)
Dim $ValArray[UBound($Names),1], $VANdx



burnsc
(Starting to like KiXtart)
2005-09-13 06:33 PM
Re: First Shot at dynamic multi-dim arrays

Completed. Here is the adjusted code:
Code:

Function ArrayEnumValues($RegSubKey)
$OldOp = SetOption("Explicit", "ON")
$Names = ArrayEnumValueNames($RegSubKey)
Dim $ValArray[UBound($Names),1]
$VANdx = 0
For $VANdx = 0 to UBound($Names)
$ValArray[$VANdx,0] = $Names[$VANdx]
$ValArray[$VANdx,1] = ReadValue($RegSubKey, $Names[$VANdx])
Next
$ArrayEnumValues = $ValArray
$ = SetOption("Explicit", $OldOp)
EndFunction


Many thanks for the pointers


Sealeopard
(KiX Master)
2005-09-18 07:04 PM
Re: First Shot at dynamic multi-dim arrays

Please make sure you're adhering to our UDF requirements as the SETOPTION=ON is a pre-requisite for posting this UDF.

Also, as you've decided to post this UDF, I will repeat what I already told you in our PM conversations, nonwithstanding your dislike of the KiXtart function names.

This UDF can cause confusion with the already existing UDF ArrayEnumValue() and thus (in accordance with the KiXtart nomenclatura) should rather be called ArrayEnumValuesData() or ArrayEnumValuesNames() or similar.

The nomenclatura, as set forth by Microsoft, is documented in http://support.microsoft.com/default.aspx?scid=kb;EN-US;256986 . Registry hives contain registry keys (subkeys). Keys contain one or more values, htere is alwasy a default value. A value contains data.


burnsc
(Starting to like KiXtart)
2005-09-20 10:33 PM
Re: First Shot at dynamic multi-dim arrays

I found some more error locations and had to update this code. However in this update I have run into further problems. For some reason(of which I don't understand) I am losing the value in my array.
The Current incarnation of this function is as follows:
Code:

Function ArrayEnumValuesAndData($RegSubKey)
Dim $Names, $OldOp, $NamesCount, $ValArray, $
$OldOp = SetOption("Explicit", "On")
$Names = ArrayEnumValueNames($RegSubKey)
$NamesCount = UBound($Names)
? "NamesCount " + $NamesCount
Get $
If $NamesCount > -1
Dim $ValArray[$NamesCount,1], $VANdx
$VANdx = 0
For $VANdx = 0 to UBound($Names)
? "Namesndx = " + $VANdx + " Names = " + $Names[$VANdx] + " Value = " + ReadValue($RegSubKey, $Names[$VANdx])
$ValArray[$VANdx,0] = $Names[$VANdx]
$ValArray[$VANdx,1] = ReadValue($RegSubKey, $Names[$VANdx])
Next
? "ValArray Ubound = " UBound($ValArray)
; Array Value is good here
Else
Exit 100
EndIf
; Here the array has lost its members(UBound reports -1)
? "ValArray Ubound = " UBound($ValArray)
$ArrayEnumValuesAndData = $ValArray
? "ValArray Ubound = " UBound($ValArray)
$OldOp = SetOption("Explicit", $OldOp)
EndFunction



Anyone have any ideas on this?


burnsc
(Starting to like KiXtart)
2005-09-22 02:42 PM
Re: First Shot at dynamic multi-dim arrays

Anyone have any ideas here?