Help with assigning a number to variables in loop Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DataLife
Posts: 458
Joined: 29 Sep 2013, 19:52

Help with assigning a number to variables in loop

23 Jan 2024, 10:14

Would someone be able to help me write this shorter?

Seems like there has to be a better way.

This needs to work if I change the number of loops. Right now it is 5, later it maybe 9 and then I may change it again. Depending on my needs per script.
numA and numB needs to equal 1 and 2 on the first loop, then numA and numB needs to equal 3 and 4 on the next loop and so on.

Code: Select all

loop 5 
 {
  if a_index = 1
   {
    numA = 1
    numB = 2
   }
  if a_index = 2
   {
    numA = 3
    numB = 4
   }
  if a_index = 3
   {
    numA = 5
    numB = 6
   }
  if a_index = 4
   {
    numA = 7
    numB = 8
   }
  if a_index = 5
   {
    numA = 9
    numB = 10
   }
 }
thanks
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
mikeyww
Posts: 26982
Joined: 09 Sep 2014, 18:38

Re: Help with assigning a number to variables in loop  Topic is solved

23 Jan 2024, 10:20

Are you trying to say that

Code: Select all

 numB := 2 * A_Index
 numA := numB - 1
:?:
User avatar
DataLife
Posts: 458
Joined: 29 Sep 2013, 19:52

Re: Help with assigning a number to variables in loop

23 Jan 2024, 10:28

mikeyww wrote:
23 Jan 2024, 10:20
Are you trying to say that

Code: Select all

 numB := 2 * A_Index
 numA := numB - 1
:?:
Fantastic, exactly what I meant. 2 lines of code that work no matter how many loops.
thank you
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 171 guests