Jump to content

Multi Monitor Info In Multidimensional Array


MicZ
 Share

Recommended Posts

Hello everybody,

I'm new to this forum and pretty new to AutoIt too...

I am trying to do something quite simple : "Get all info from all monitors"

I found all the Registry keys and values and wrote the following code :

$VideoDevice = RegRead("HKLM\HARDWARE\DEVICEMAP\VIDEO","\Device\Video0")
$VideoDevKey = StringRegExp($VideoDevice,"(\{.*\})",1)
$MonitorList = "HKCC\System\CurrentControlSet\Control\VIDEO\" & $VideoDevKey[0]

$i = 1
Dim $test[1]
While 1
  $MonNr = RegEnumKey($MonitorList, $i)
  If @error Then ExitLoop
  $MonInfo = $MonitorList & "\" & $MonNr

  ReDim $test[$i][6]
  $test[$i][0] = RegRead($MonInfo, "DefaultSettings.XResolution")
  $test[$i][1] = RegRead($MonInfo, "DefaultSettings.YResolution")
  $test[$i][2] = RegRead($MonInfo, "DefaultSettings.VRefresh")
  $test[$i][3] = RegRead($MonInfo, "Attach.ToDesktop")
  $test[$i][4] = RegRead($MonInfo, "Attach.RelativeX")
  $test[$i][5] = RegRead($MonInfo, "Attach.RelativeY")
  $i += 1
WEnd

I'm quite used to working with arrays in PHP, Javascript etc., but obviously AutoIt has a quite different way of handeling arrays :think:

If I just do the ReDim-part and don't assign values, the array is formed in the way I want it, but it doesn't want to assign the values (doesn't take the $i)...

I tried searching the forum(s) and reading the help-file, but especially in the help-file there is a concerning lack of documentation on how to work with arrays "the Autoit way" :(

Hopefully somebody here can enlighten me ?!

Link to comment
Share on other sites

http://www.autoitscript.com/forum/index.php?showtopic=18211

RandallC wrote some great 2darray functions.

I'm guessing you want:

_Array2DCreateFromArray()

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Dim $test[1][6]

ReDim $test[uBound($test) + 1][6]

$test[uBound($test) - 1][0] = "value"

$test[uBound($test) - 1][1] = "value"

$test[uBound($test) - 1][2] = "value"

$test[uBound($test) - 1][3] = "value"

$test[uBound($test) - 1][4] = "value"

$test[uBound($test) - 1][5] = "value"

Link to comment
Share on other sites

Dim $test[1][6]

ReDim $test[uBound($test) + 1][6]

$test[uBound($test) - 1][0] = "value"

$test[uBound($test) - 1][1] = "value"

$test[uBound($test) - 1][2] = "value"

$test[uBound($test) - 1][3] = "value"

$test[uBound($test) - 1][4] = "value"

$test[uBound($test) - 1][5] = "value"

Ok, this seems to work (although $test[0] is completely empty obviously)... thanks ChrisL

But for me this raises the question : "Why the $%&(@ should I do it this way ?" :(

It doesn't seem logical at all, and I've seen some simple examples like :

Dim $MyArr[4][2][2]
For $d_1 = 0 To 3
   For $d_2 = 0 To 1
      For $d_3 = 0 To 1
         $MyArr[$d_1][$d_2][$d_3] = 'value: $MyArr[' & $d_1 & '][' & $d_2 & '][' & $d_3 & ']'
      Next
   Next
Next

This seems a lot like my code... difference is that this works and mine doesn't :think:

Link to comment
Share on other sites

Arrays are 0 based, so when you ReDim $test[$i][6] to store you need to use $i-1 pointer like:

$test[$i-1][0] = RegRead($MonInfo, "DefaultSettings.XResolution")

True, but is it really necessary to declare it ?

If I use :

Dim $test[2][2]
$test[1][0] = "hello"

I can recall the $test[1][0]... actually, after the "Dim" the array is already created with empty values.

So in my previous code, it wouldn't really explain why I couldn't use $test[$i][0], or am I wrong ?

(as I did a "Dim" for $test[1], and a "ReDim" for $test[1][6] afterwards...)

Edited by MicZ
Link to comment
Share on other sites

True, but is it really necessary to declare it ?

If I use :

Dim $test[2][2]
$test[1][0] = "hello"

I can recall the $test[1][0]... actually, after the "Dim" the array is already created with empty values.

So in my previous code, it wouldn't really explain why I couldn't use $test[$i][0], or am I wrong ?

(as I did a "Dim" for $test[1], and a "ReDim" for $test[1][6] afterwards...)

Straight from Help file:

The ReDim keyword is similar to Dim, except that ReDim preserves the values in the array instead of removing the values while resizing an array. The number of dimensions must remain the same, or the old array will be forgotten during the ReDim. The array will retain the scope (Global or Local) that it had prior to resizing.

So you can Dim the array singlre dimemsion or multi dimensio. When you redim and change number of dimensions array is cleared.

But your problem in original code was accessing the elements of the array.

When you Redim $test[$i][6] and $i=1 array has only 6 elements with proper addressing:

$test[0][0], $test[0][1], ... $test[0][5]

So doing:

$test[$i][0] = RegRead($MonInfo, "DefaultSettings.XResolution")

Should give you an error because $test[1][0] does not exist.

Have you tried to change your code to $test[$i-1][0] and does it give you what you want?

Link to comment
Share on other sites

Hi,

Yes, I was wrong... redim works;

I don't know if you can then "redim" a 2D array with the same name which does not already exist?

Have you tried to change your code to $test[$i-1][0] and does it give you what you want?

This works as you say;

;try2arrayDim.au3

#include"Array2D.au3"

;$VideoDevice = RegRead("HKLM\HARDWARE\DEVICEMAP\VIDEO","\Device\Video0")

;$VideoDevKey = StringRegExp($VideoDevice,"(\{.*\})",1)

;$MonitorList = "HKCC\System\CurrentControlSet\Control\VIDEO\" & $VideoDevKey[0]$i = 1

Dim $test[1]

While 1

;$MonNr = RegEnumKey($MonitorList, $i)

$MonInfo = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE" , $i)

If @error Then ExitLoop

;$MonInfo = $MonitorList & "\" & $MonNr

ReDim $test[$i][6]

$test[$i-1][0] = $MonInfo

$test[$i-1][1] = $MonInfo

$test[$i-1][2] = $MonInfo

$test[$i-1][3] = $MonInfo

$test[$i-1][4] = $MonInfo

$test[$i-1][5] = $MonInfo

$i += 1

WEnd

_ArrayViewText($test, '$test');#include"Array2Ds.au3" ; better 2D array viewer; try it!

OR so does this as the only change in your original script;

ReDim $test[$i+1][6]

Best, Randall

Best, randall

Edited by randallc
Link to comment
Share on other sites

Thanks is8591 and randallc ... it works like this, but even better : it makes sense !

I was just too confused, as I am really used to working with arrays in PHP...

Still seems a bit easier in PHP though, in which you can just do :

$test[0] = "hello";
$test[1][0] = "hello again";

So then it only becomes multidimensional after $test[0]

Other thing that kinda bugs me is that you have to declare an array beforehand, but if it really keeps bugging me, I guess I'll have to write my own UDF :think:

I'm off coding again, thanks again people...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...