Page 1 of 1 1
Topic Options
#147692 - 2005-09-13 03:41 PM First Shot at dynamic multi-dim arrays
burnsc Offline
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
#147693 - 2005-09-13 03:44 PM Re: First Shot at dynamic multi-dim arrays
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
IIRC, multi-dim arrays cannot be redimmed.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#147694 - 2005-09-13 03:51 PM Re: First Shot at dynamic multi-dim arrays
burnsc Offline
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
#147695 - 2005-09-13 03:53 PM Re: First Shot at dynamic multi-dim arrays
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.


Edited by Richard H. (2005-09-13 04:00 PM)

Top
#147696 - 2005-09-13 04:09 PM Re: First Shot at dynamic multi-dim arrays
burnsc Offline
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
#147697 - 2005-09-13 04:20 PM Re: First Shot at dynamic multi-dim arrays
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Read my post or look up the manual page for ReDim where the action of the PRESERVE keyword on multi-dimension arrays is explained.
Top
#147698 - 2005-09-13 04:25 PM Re: First Shot at dynamic multi-dim arrays
Richard H. Administrator Offline
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 Offline
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 Offline
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 Offline
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
#147702 - 2005-09-18 07:04 PM Re: First Shot at dynamic multi-dim arrays
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#147703 - 2005-09-20 10:33 PM Re: First Shot at dynamic multi-dim arrays
burnsc Offline
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 Offline
Starting to like KiXtart

Registered: 2004-04-14
Posts: 171
Anyone have any ideas here?
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.039 seconds in which 0.013 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org