Problems assigning variables from SysGet to array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Problems assigning variables from SysGet to array

Post by wetware05 » 01 Jun 2023, 13:46

Hi.

Why doesn't this work:

Code: Select all

SizeMon := object()
SysGet, numDisplays, MonitorCount

Loop %numDisplays%
 {
  SysGet, Mon, Monitor, %A_Index%
  SizeMon.Push(Monleft, MonRight)
 }
I tried with SizeMon.Push(%Monleft%, %MonRight%) or:

Code: Select all

LMon:= %Monleft%
RMon:= %MonRight%
SizeMon.Push(LMon, RMon)
...and this yes (you have to resort to the artifice of saving the variables in a file and then reading it):

Code: Select all

SizeMon := object()
SysGet, numDisplays, MonitorCount

Loop %numDisplays%
 {
  SysGet, Mon, Monitor, %A_Index%
  TempSize:= % MonLeft . ", " . MonRight
  FileAppend, %TempSize%`n, MonSize.csv
 }

Loop, Read, MonSize.csv
 {
  SizeMon.Push(StrSplit(A_LoopReadLine, ","))
 }

User avatar
Datapoint
Posts: 295
Joined: 18 Mar 2018, 17:06

Re: Problems assigning variables from SysGet to array  Topic is solved

Post by Datapoint » 01 Jun 2023, 14:08

Your first code "works" but maybe not in the way you expect:

Code: Select all

SizeMon := []
SysGet, numDisplays, MonitorCount

Loop % numDisplays {
	SysGet, Mon, Monitor, %A_Index%
	SizeMon.Push(Monleft, MonRight)
}

for i, v in SizeMon
	MsgBox % ">" i "`n>" v
If you are trying to push an array into SizeMon, like you are doing with StrSplit, then you need to create the array. Otherwise you are not pushing an array into SizeMon, you are pushing variables into SizeMon. This will create an array - notice the [...] around [Monleft, MonRight].

Code: Select all

SizeMon := []
SysGet, numDisplays, MonitorCount

Loop % numDisplays {
	SysGet, Mon, Monitor, %A_Index%
	SizeMon.Push( [Monleft, MonRight] )
}

for i, m in SizeMon
	MsgBox % ">" i "`n>" m.1 "`n>" m.2`
Or with an associative array:

Code: Select all

SizeMon := []
SysGet, numDisplays, MonitorCount

Loop % numDisplays {
	SysGet, Mon, Monitor, %A_Index%
	SizeMon.Push( {Monleft: Monleft, MonRight: MonRight} )
}

for i, m in SizeMon
	MsgBox % ">" i "`n>" m.Monleft "`n>" m.MonRight

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Problems assigning variables from SysGet to array

Post by wetware05 » 01 Jun 2023, 14:32

Thank you @Datapoint. :thumbup:

I tried several methods, reading the help and looking for examples, but nothing worked. In no case did I see examples with the double braces ({---}) or ([...]), perhaps because it did not apply in those other cases, but I don't know where the information is in the help for when to use the double keys Not here... https://www.autohotkey.com/docs/v1/Objects.htm#Usage I know it will say it somewhere! But for someone who doesn't know programming, it's not easy to distinguish these tricks in which you have to know the concepts of programming, and without them it's like not having the keys to open the doors. Everything remains closed, hermetic, like the hermetic sciences.

I have opted for the first method:

Code: Select all

SizeMon := []
SysGet, numDisplays, MonitorCount

Loop % numDisplays {
	SysGet, Mon, Monitor, %A_Index%
	SizeMon.Push( [Monleft, MonRight] )
}
; Call the 4 variables, in the case of two monitors.
MsgBox % SizeMon[1,1] " - " SizeMon[1,2]
MsgBox % SizeMon[2,1] " - " SizeMon[2,2]
Now that I know about these options I will surely think about them on other occasions.

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Problems assigning variables from SysGet to array

Post by wetware05 » 02 Jun 2023, 08:32

@Datapoint and others...

Would this be correct?

Image
Did I forget that an associative array can also be simple (not 3D)? (Sorry about the size, I forgot about the 4k monitor, if the moderator requests it, I can change the size).

In the help at https://www.autohotkey.com/docs/v1/Objects.htm#Usage they have omitted how to retrieve data from a cell of an associative array. How is it? In the example of the image, how retrieve the top left box. I like the associative one better, because it is clearer to look at.

User avatar
Datapoint
Posts: 295
Joined: 18 Mar 2018, 17:06

Re: Problems assigning variables from SysGet to array

Post by Datapoint » 02 Jun 2023, 10:51

Like this?

Code: Select all

SizeMon := []
SysGet, numDisplays, MonitorCount
Loop % numDisplays {
	SysGet, Mon, Monitor, %A_Index%
	SizeMon.Push( [Monleft, MonRight] )
}
Var1 := 1
Var2 := 1
MsgBox % SizeMon.1.1 "`n" SizeMon[Var1, Var2] "`n" SizeMon.1[Var2] "`n" SizeMon[Var1].1



SizeMon := []
SysGet, numDisplays, MonitorCount
Loop % numDisplays {
	SysGet, Mon, Monitor, %A_Index%
	SizeMon.Push(Monleft, MonRight)
}
Var := 1
MsgBox % SizeMon[Var] "`n" SizeMon.1



SizeMon := []
SysGet, numDisplays, MonitorCount
Loop % numDisplays {
	SysGet, Mon, Monitor, %A_Index%
	SizeMon.Push( {Monleft: Monleft, MonRight: MonRight} )
}
Var1 := 1
Var2 := "Monleft"
MsgBox % SizeMon.1.Monleft "`n" SizeMon[Var1, Var2] "`n" SizeMon.1[Var2] "`n" SizeMon[Var1].Monleft



SizeMon := {}
SysGet, numDisplays, MonitorCount
Loop % numDisplays {
	SysGet, Mon, Monitor, %A_Index%
	SizeMon["Mon" A_Index] :=  {Monleft: Monleft, MonRight: MonRight}
}
Var1 := "Mon1"
Var2 := "Monleft"
MsgBox % SizeMon.Mon1.Monleft "`n" SizeMon[Var1, Var2] "`n" SizeMon.Mon1[Var2] "`n" SizeMon[Var1].Monleft

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Problems assigning variables from SysGet to array

Post by wetware05 » 02 Jun 2023, 11:21

Hi, @Datapoint, your script returns me at all 0 in all fields.
The issue was already resolved in your previous post.

I'm going to explain.

My "fight" in the forum is that there are people with different learning problems, such as dyslexia, hyperactivity, or having a more developed visual brain than the word brain, who do not learn easily from how the aid is presented. official, or even for something so simple that they don't speak English (and where if the google automatic translator is used it "destroys" the comprehension of almost all the text).

(Nor should we ignore the level of intelligence, and the fact that a certain language that is used is technical, and not everyone wants to learn programming. Although it is clear that if you want to reach a certain level, you have to learn about such language and technicalities. This This issue can be understood through an analogy: if you try to teach someone a language, you teach them easy words and phrases like "Grandpa is home", but you don't do it through a complex phrase from Kant, that you don't understand it in your own language.)

My graph is a visual development of arrays (as I have tried to understand it). And my question to people with knowledge of AutoHotkey is if my graph (and understanding) is correct. Also there is a specific question... in the example of the image, over an associative array, how retrieve the top left box

Post Reply

Return to “Ask for Help (v1)”