Sign in to follow this  
Followers 0
LurchMan

[Solved]Simple 2D Array question

3 posts in this topic

#1 ·  Posted (edited)

Hey everyone -

I'm working on a small function that basically enumerates a section of the registry then stores the info in a 2D array (Key Name, Value) but I can't seem to get it to work right...

Func:

Func _EnumVals ($sPath)
    Local $aKeys[1][1]
    For $n = 1 To 1000
        $Temp = RegEnumVal ($sPath, $n)
        If Not @error = -1 Then
            If UBound ($aKeys) - 1 < $n Then ReDim $aKeys[$n+1][$n+1]
            $aKeys[$n][0] = $Temp
            $aKeys[0][$n] = RegRead ($sPath, $aKeys[$n][0]) ;;;Can't seem to get it to store it right $aKeys[1][0] = Key Name, $aKeys[0][1] should hold value
        Else
            ExitLoop
        EndIf
    Next
    Return $aKeys
EndFunc

Edit - Sorry guys, I looked over the wiki for arrays again and it clicked finally, it needs to be:

$aKeys[$n][1] = RegRead ($sPath, $aKeys[$n][0])
Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites



also may want to

Then ReDim $aKeys[$n+1][2]

so as to not create another column for every row (reg key)


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

An empty array with 2000 elements is so small you could just remove that whole ReDim thing. ReDim is slow.

Edit: Open task manager and run this:

MsgBox(0, "", "")
Local $array[1000][2]
MsgBox(0, "", "")
Notice how the ram-usage increased by only 12-16 K?

Of course, if you do that you should do a ReDim at the end so there isn't any long-term waste lying around. And to make the array easier to handle.

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0