Calculation with Mode Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Calculation with Mode

Post by hasantr » 10 Jun 2022, 06:02

Code: Select all

Loop,16
	MsgBox % 5553 + A_Index + !Mod(A_Index,2)
In this process
"5554,5556,5558,5560,5562,5564,5566,5568,5570"
I'm waiting for a result. But why doesn't this happen?

garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Calculation with Mode

Post by garry » 10 Jun 2022, 06:24

tried this

Code: Select all

Loop,16
  {
  aa:=5553 + A_Index 
  if (Mod(A_Index,2))
  e .= aa . "`r`n"
  }
msgbox,%e%
exitapp

RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: Calculation with Mode

Post by RussF » 10 Jun 2022, 06:32

hasantr wrote:
10 Jun 2022, 06:02

Code: Select all

Loop,16
	MsgBox % 5553 + A_Index + !Mod(A_Index,2)
In this process
"5554,5556,5558,5560,5562,5564,5566,5568,5570"
I'm waiting for a result. But why doesn't this happen?
Your code works for me, however the sequence I get is not what you are apparently expecting. I get:

5554, 5556, 5556, 5558, 5558, 5560, 5560, 5562, 5562...

which is correct, based on the logic of your code.

What are you expecting and not getting?

Russ

hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Calculation with Mode

Post by hasantr » 10 Jun 2022, 06:33

Thank you. But I wonder why it's not working. I prefer a one line solution.

hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Calculation with Mode

Post by hasantr » 10 Jun 2022, 06:36

RussF wrote:
10 Jun 2022, 06:32
hasantr wrote:
10 Jun 2022, 06:02

Code: Select all

Loop,16
	MsgBox % 5553 + A_Index + !Mod(A_Index,2)
In this process
"5554,5556,5558,5560,5562,5564,5566,5568,5570"
I'm waiting for a result. But why doesn't this happen?
Your code works for me, however the sequence I get is not what you are apparently expecting. I get:

5554, 5556, 5556, 5558, 5558, 5560, 5560, 5562, 5562...

which is correct, based on the logic of your code.

What are you expecting and not getting?

Russ
I don't want to get these pairs. I want to get each result individually. I could do it the other way, but I guess I'm stuck. I want to get 16 results and they must have increased by twos. It would be great to be able to solve it in one line.

RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: Calculation with Mode

Post by RussF » 10 Jun 2022, 06:37

What is not working? Exactly what do you expect to appear in your MsgBox?

Russ

hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Calculation with Mode

Post by hasantr » 10 Jun 2022, 06:44

RussF wrote:
10 Jun 2022, 06:37
What is not working? Exactly what do you expect to appear in your MsgBox?

Russ
I expect two increments per loop starting with 5554. 5556 when A_index is 2, 5558 when A_index is 3

I realize that my logic is wrong.

RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: Calculation with Mode  Topic is solved

Post by RussF » 10 Jun 2022, 07:39

Try:

Code: Select all

MyVar := 5552
Loop, 16
   MsgBox % MyVar += 2
Or:

Code: Select all

Loop, 16
   MsgBox % 5552 + A_Index * 2
Russ

hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Calculation with Mode

Post by hasantr » 25 Jun 2022, 15:29

Thank you. It was a very tired day, I was overlooking such a simple thing. I even missed your solution that day, then I figured it out and saw your message.

Post Reply

Return to “Ask for Help (v1)”