#147692 - 2005-09-13 03:41 PM
First Shot at dynamic multi-dim arrays
|
burnsc
Starting to like KiXtart
Registered: 2004-04-14
Posts: 171
|
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
|
Top
|
|
|
|
#147694 - 2005-09-13 03:51 PM
Re: First Shot at dynamic multi-dim arrays
|
burnsc
Starting to like KiXtart
Registered: 2004-04-14
Posts: 171
|
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
|
Top
|
|
|
|
#147696 - 2005-09-13 04:09 PM
Re: First Shot at dynamic multi-dim arrays
|
burnsc
Starting to like KiXtart
Registered: 2004-04-14
Posts: 171
|
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
|
Top
|
|
|
|
#147698 - 2005-09-13 04:25 PM
Re: First Shot at dynamic multi-dim arrays
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Are you sure that you are returning the correct array here: Code:
$ArrayEnumValues = $Names
Shouldn't that be: Code:
$ArrayEnumValues = $ValArray
|
Top
|
|
|
|
#147699 - 2005-09-13 04:39 PM
Re: First Shot at dynamic multi-dim arrays
|
burnsc
Starting to like KiXtart
Registered: 2004-04-14
Posts: 171
|
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
|
Top
|
|
|
|
#147700 - 2005-09-13 04:46 PM
Re: First Shot at dynamic multi-dim arrays
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
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
|
Top
|
|
|
|
#147701 - 2005-09-13 06:33 PM
Re: First Shot at dynamic multi-dim arrays
|
burnsc
Starting to like KiXtart
Registered: 2004-04-14
Posts: 171
|
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
|
Top
|
|
|
|
#147703 - 2005-09-20 10:33 PM
Re: First Shot at dynamic multi-dim arrays
|
burnsc
Starting to like KiXtart
Registered: 2004-04-14
Posts: 171
|
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?
|
Top
|
|
|
|
#147704 - 2005-09-22 02:42 PM
Re: First Shot at dynamic multi-dim arrays
|
burnsc
Starting to like KiXtart
Registered: 2004-04-14
Posts: 171
|
Anyone have any ideas here?
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 259 anonymous users online.
|
|
|