Total sum of variable%A_index% from edit boxes Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fuglen
Posts: 24
Joined: 05 Mar 2020, 09:44

Total sum of variable%A_index% from edit boxes

Post by fuglen » 02 Dec 2022, 06:39

Part of my script is a GUI with a number of edit controls where you can write a number. The total sum of the numbers should then be written in a Readonly edit control. The number of edit controls can change from each use and is based on the variable "muscle_number". In my code below I know there will be 3 Edit controls to write data into so writing "Total1 = % n1 + n2 + n3" works in my code. How would I go about getting the sum of all n%A_index%?

Code: Select all

Gui, Add, Edit, x10 y%TestH% w250 h45 ReadOnly vtotalsum -Vscroll, % "Total units injected will be written here"

Loop, %muscle_number%
	{
     if (A_Index = 1)
      Continue
     gui, Add, Edit, Limit3 Center x+80 w40 gTotal   vn%A_Index%,   ;Unit injected edit control
	}

Total:
Gui, Submit, NoHide
Loop, %muscle_number%
{
 if (n%A_Index% = "")
 {
  n%A_Index% := 0
 }
}

Total1 = % n1 + n2 + n3
GuiControl,, totalsum, Units injected equals  %Total1%
Return

User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Total sum of variable%A_index% from edit boxes  Topic is solved

Post by mikeyww » 02 Dec 2022, 06:47

Code: Select all

muscle_number = 3
Gui, Font, s10
Loop, %muscle_number%
 Gui, Add, Edit, vn%A_Index% gSum
Gui, Add, Edit, ReadOnly vsum
Gui, Show, w230, Sum
Return

Sum:
Gui, Submit, NoHide
sum := 0
Loop, %muscle_number%
 sum += n%A_Index%
GuiControl,, sum, %sum%
Return

fuglen
Posts: 24
Joined: 05 Mar 2020, 09:44

Re: Total sum of variable%A_index% from edit boxes

Post by fuglen » 02 Dec 2022, 07:47

Great, thank you mikey! Think I messed up trying to put both the sum part and n%A_Index% = "" into the same loop

Post Reply

Return to “Ask for Help (v1)”