If i want to use 2 variable to calculation, How to write the correct code???? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lo4438
Posts: 53
Joined: 18 May 2022, 10:00

If i want to use 2 variable to calculation, How to write the correct code????

Post by Lo4438 » 22 Jul 2022, 12:54

Code: Select all

x1 := v1 - v2
; v1 is 74
;v2 is 80
MsgBox, % x1
[Mod edit: Fixed [code][/code] tags.]



;the Message box is empty.

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: If i want to use 2 variable to calculation, How to write the correct code????

Post by Xtra » 22 Jul 2022, 13:03

Code: Select all

v1 := 74
v2 := 80
x1 := v1 - v2

MsgBox, % x1

Lo4438
Posts: 53
Joined: 18 May 2022, 10:00

Re: If i want to use 2 variable to calculation, How to write the correct code????

Post by Lo4438 » 22 Jul 2022, 17:29

Code: Select all

#Include uia.ahk
$u:=new IUIAutomation
$e:=new IUIAutomationElement
$c:=new IUIAutomationCondition
$r:=new IUIAutomationCacheRequest
$t:=new IUIAutomationTreeWalker

^t::
Loop 1
{
Element1 := $u.ElementFromPoint(586|255<<32)
v1 := $e.(Element1).CurrentName() . "`n"  ;v1 is a number 

Element2 := $u.ElementFromPoint(599|255<<32)
v2 := $e.(Element2).CurrentName() . "`n"  ;v2 is a number 
x1 := v1 - v2
MsgBox, %x1%
}
Return 
MsgBox is empty

gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: If i want to use 2 variable to calculation, How to write the correct code????

Post by gregster » 22 Jul 2022, 17:48

Numbers don't have newline `n-characters at their end. If you need those for something different later, how about you concatenate them after doing the calculation, for eg with .= :

Code: Select all

v1 := 74 
v2 := 80 
x1 := v1 - v2
msgbox % x1
v1 .= "`n"
v2 .= "`n"
msgbox % v1 v2 "third line"

Lo4438
Posts: 53
Joined: 18 May 2022, 10:00

Re: If i want to use 2 variable to calculation, How to write the correct code????

Post by Lo4438 » 22 Jul 2022, 17:55

Thanks for your help. :dance:
I'm the beginner for ahk

v1 & v2,they will change to other numbers ever second
How to write the correct code?

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: If i want to use 2 variable to calculation, How to write the correct code????  Topic is solved

Post by neovis » 22 Jul 2022, 19:54

It seems to contain non-numeric characters. Try to remove white spaces.

Code: Select all

v1 := " 74 "
v2 := " 80 "

; strip white spaces
v1 := Trim(v1, " `t`r`n") 
v2 := Trim(v2, " `t`r`n")

x1 := v1-v2
MsgBox % x1
or

Code: Select all

v1 := RegExReplace(v1, "\D")
v2 := RegExReplace(v2, "\D")


Post Reply

Return to “Ask for Help (v1)”