Can't calculation of Clipboard, how to let Autohotkey know ( arr1, arr2, arr3, arr4) are the number?

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

Can't calculation of Clipboard, how to let Autohotkey know ( arr1, arr2, arr3, arr4) are the number?

Post by Lo4438 » 24 Jun 2022, 10:02

Code: Select all

app = C:\Users\j\Capture2Text\Capture2Text_CLI.exe


+6::

RunWait, %app% -s "1222 149 1457 164" --clipboard,, Hide
sleep % 100

If ( InStr(Clipboard,"0] 171"))
{
MsgBox, % ReExReplace(%Clipboard%, "0] 171", "1171")
}
Else MsgBox, %ClipBoard%

Return
[Mod edit: [code][/code] tags added.]
Attachments
Screenshot_2022-06-24-23-00-57-11_6012fa4d4ddec268fc5c7112cbb265e7.jpg
Screenshot_2022-06-24-23-00-57-11_6012fa4d4ddec268fc5c7112cbb265e7.jpg (32.81 KiB) Viewed 1223 times
Last edited by Lo4438 on 24 Jun 2022, 21:51, edited 2 times in total.

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Can't replace one part of clipboard. Please help to correct the script

Post by flyingDman » 24 Jun 2022, 10:53

You do not have to check if it's there. If it is not there, nothing will be replaced:

Code: Select all

var := "0] 171 22.850 1,664 22.750"
MsgBox, % strreplace(var, "] ")
14.3 & 1.3.7

User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Can't replace one part of clipboard. Please help to correct the script

Post by AlphaBravo » 24 Jun 2022, 11:00

in addition to what @flyingDman wrote, there are other issues
1 - you misspelled "RegExReplace"
2 - you don't need "%" inside a function
3 - when you use RegExReplace you need to escape square brackets from "]" to "\]"

Code: Select all

Clipboard := "0] 171 22.850 1,644 22.750"

;~ Clipboard := RegExReplace(Clipboard, "0\] 171", "1171")
Clipboard := StrReplace(Clipboard, "0] 171", "1171")   ; or just use StrReplace

MsgBox, %ClipBoard%

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

Re: Can't replace one part of clipboard. Please help to correct the script

Post by Lo4438 » 24 Jun 2022, 11:29

Thank you. now i use your code, the message is correct. :superhappy:

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

Re: Can't replace one part of clipboard…

Post by Lo4438 » 24 Jun 2022, 12:30

More one question, why the answer is empty?
How to calculation?

Code: Select all

;b is 22.85
;c is 1664
;d is 22.75

StringSplit, arr, clipboard, %a_space%   		
a :=arr1
b :=arr2
c :=arr3
d :=arr4

f :=(b*0.9965- d*1.0034772)*c

MsgBox %f%
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 24 Jun 2022, 12:36, edited 1 time in total.
Reason: Please use code tags. Thank you!

braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Can't replace one part of clipboard…

Post by braunbaer » 24 Jun 2022, 12:50

Use msgbox to check if the variables really contain what you expect. I suppose at least one of the variables is null (empty string), then the result of such a calculation also becomes null.

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

Re: Can't replace one part of clipboard…

Post by Lo4438 » 24 Jun 2022, 20:54

Msg is empty, what's error, please help.

Code: Select all

+6::
Clipboard :=
RunWait, %app% -s "569 154 828 170" --clipboard,, Hide
sleep % 100
ClipBoard :=StrReplace(ClipBoard, "0117]", "1171")
ClipBoard :=StrReplace(ClipBoard, ",", "")

Stringreplace, Clipboard, Clipboard, `...All
StringSplit, arr, clipboard, %a_space% 

; MsgBox, % Clipboard 
		
a :=arr1
b :=arr2
c :=arr3
d :=arr4

f :=(b*0.9965- d*1.0034772)*c

MsgBox %f%
[Mod edit: [code][/code] tags added.]
Attachments
Screenshot_2022-06-25-09-52-25-24_6012fa4d4ddec268fc5c7112cbb265e7.jpg
Screenshot_2022-06-25-09-52-25-24_6012fa4d4ddec268fc5c7112cbb265e7.jpg (49.78 KiB) Viewed 836 times
Last edited by gregster on 24 Jun 2022, 21:01, edited 1 time in total.
Reason: Please use code tags around your code. Thank you!

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

Re: Can't replace one part of clipboard…

Post by Lo4438 » 24 Jun 2022, 21:48

Lo4438 wrote:
24 Jun 2022, 20:54
Msg is empty, what's error, please help.

Code: Select all

+6::
Clipboard :=
RunWait, %app% -s "569 154 828 170" --clipboard,, Hide
sleep % 100
ClipBoard :=StrReplace(ClipBoard, "0117]", "1171")
ClipBoard :=StrReplace(ClipBoard, ",", "")

Stringreplace, Clipboard, Clipboard, `...All
StringSplit, arr, clipboard, %a_space% 

; MsgBox, % Clipboard 
		
a :=arr1
b :=arr2
c :=arr3
d :=arr4

f :=(b*0.9965- d*1.0034772)*c

MsgBox %f%
[Mod edit: [code][/code] tags added.]
How to let Autohotkey know the (arr1-4 ) are the numbers?
arr1 arr2 arr3 arr4

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Can't calculation of Clipboard, how to let Autohotkey know ( arr1, arr2, arr3, arr4) are the number?

Post by BoBo » 25 Jun 2022, 00:21

Stringreplace, Clipboard, Clipboard, `...All
a) why you're using the deprecated StringReplace-command instead of the StrReplace()-function (same with StringSplit! vs StrSplit()) ???
b) why you’re using . characters to separate your command parameters within StringReplace???
c) if you go on ignoring to set [code][/code]-tags on your own (you've been advised about that within this thread a record 5th time!!!) I'd discuss with our fellow moderators to lock your thread (for an increasing number of time). So PLEASE use code-tags if posting code at the forum. It will help your supporters to support you.
Thx for listening :)

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Can't calculation of Clipboard, how to let Autohotkey know ( arr1, arr2, arr3, arr4) are the number?

Post by flyingDman » 25 Jun 2022, 00:24

20220624_222313.jpg
20220624_222313.jpg (38.51 KiB) Viewed 624 times
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”