Parsing a label Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
blad4
Posts: 222
Joined: 07 Oct 2015, 11:06

Parsing a label

11 Dec 2019, 07:36

Instead of writing

Code: Select all

If InpurVar=1NE
gosub 2NE
Can I achieve

Code: Select all

gosub InpurVar=(%1%+1)NE
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Parsing a label

11 Dec 2019, 09:23

Code: Select all

InpurVar := "1NE"
gosub, % SubStr(InpurVar,1,1)+1 "NE"
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Parsing a label

11 Dec 2019, 09:27

Code: Select all

#SingleInstance, Force

Try, GoSub, % (InpurVar = "1NE" ? "2NE" : "")
return

2NE:
	MsgBox, Test
return
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Parsing a label

11 Dec 2019, 09:30

In case you need it more generic, this will add 1 to whatever the number is (even if it's double digits) and follows it with whatever the letters are in case they're not "NE".

Code: Select all

InpurVar := "1NE"
Gosub, % (RegExReplace(InpurVar, "([A-Z]+)")+1) . RegExReplace(InpurVar, "(\d+)")
return

2NE:
	MsgBox, Hello
return
blad4
Posts: 222
Joined: 07 Oct 2015, 11:06

Re: Parsing a label

11 Dec 2019, 09:56

Thank you Odlanir, substr is now easier for me to understand. Dewd that also makes a lot of sense due to your guidance in the past.
boiler wrote:
11 Dec 2019, 09:30
In case you need it more generic, this will add 1 to whatever the number is (even if it's double digits) and follows it with whatever the letters are in case they're not "NE".

Code: Select all

InpurVar := "1NE"
Gosub, % (RegExReplace(InpurVar, "([A-Z]+)")+1) . RegExReplace(InpurVar, "(\d+)")
return

2NE:
	MsgBox, Hello
return
boiler you predicted correct in that I need it generic. RegExReplace looks so useful. I would also need a fit of

Code: Select all

"([A-Z]+)")+1) (But if>3, then -=2 to give one)
This will allow me to loop this operation on auto
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Parsing a label

11 Dec 2019, 10:09

Sounds like you want it when it's >=3 (greater or equal to 3)

Code: Select all

Gosub, % ((n:=RegExReplace(InpurVar, "([A-Z]+)"))+(n>=3?-2:1)) . RegExReplace(InpurVar, "(\d+)")
blad4
Posts: 222
Joined: 07 Oct 2015, 11:06

Re: Parsing a label

11 Dec 2019, 10:29

boiler wrote:
11 Dec 2019, 10:09
Sounds like you want it when it's >=3 (greater or equal to 3)

Code: Select all

Gosub, % ((n:=RegExReplace(InpurVar, "([A-Z]+)"))+(n>=3?-2:1)) . RegExReplace(InpurVar, "(\d+)")
Thank you. Yes, mistake with arithmetic. Should have wrote if>3 then -3

Code: Select all

f2::
InpurVar := "1NFE"
Gosub, % ((n:=RegExReplace(InpurVar, "([A-Z]+)"))+(n>3?-3:1)) . RegExReplace(InpurVar, "(\d+)")
To press F2 giving 2NFE, 3NFE, 1NFE on loop,is the smartest way to store the result from the

Code: Select all

Gosub, % ((n:=RegExReplace...
line back as InpurVar?
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Parsing a label

11 Dec 2019, 10:50

What is it that you really want to do? Because it's getting much more convoluted than it needs to be. Do you just want it to change from 1NE to 2NE and 3NE then back to 1NE again every time you press F2?
blad4
Posts: 222
Joined: 07 Oct 2015, 11:06

Re: Parsing a label

11 Dec 2019, 13:00

Hi boiler, I want it to do exactly this and you are exactly right, just change inpurvar to match the change. So if 1ab turned to 2ab, 3ab, 1ab and so on. Same thing if 1xy or 1ne. Sorry should hve been clear from the start
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Parsing a label

11 Dec 2019, 13:36

Try this:

Code: Select all

InpurVar := "1NE"

F2::
	RegExMatch(InpurVar, "(\d+)(.+)", Match)
	Gosub, % (InpurVar := Match1 . Match2)
	InpurVar := (++Match1 = 4 ? 1 : Match1) . Match2
return

1NE:
	ToolTip, This is the 1NE subroutine
return

2NE:
	ToolTip, This is the 2NE subroutine
return

3NE:
	ToolTip, This is the 3NE subroutine
return

Esc::ExitApp
blad4
Posts: 222
Joined: 07 Oct 2015, 11:06

Re: Parsing a label

11 Dec 2019, 14:22

Thank you, but getting an error: Target label does not exist at the Gosub line
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Parsing a label

11 Dec 2019, 14:24

Can you post the code that is producing that error? If it's the code I posted, did you copy the whole thing? It works here. Notice that you have to scroll to see all of the code in my last post.
blad4
Posts: 222
Joined: 07 Oct 2015, 11:06

Re: Parsing a label

11 Dec 2019, 14:48

Here was the problem. The highlighted "return" below

Code: Select all

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
;~ #Persistent ; ~~~not required because this script has hotkeys
#SingleInstance Force
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetBatchLines, -1
SetControlDelay -1
SetTitleMatchMode, REGEX
DetectHiddenWindows, On
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, Mouse, Screen
SetNumLockState, On
#InstallKeybdHook
#InstallMouseHook
ActiveHwnd := WinExist("A")
Winactivate 102
3Set=1HG
Sleep 1000
;gosub ActivateMenu
; return <-------------------------------- this one

InpurVar:="1NE"

F2::
	RegExMatch(InpurVar, "(\d+)(.+)", Match)
	Gosub, % (InpurVar := Match1 . Match2)
	InpurVar := (++Match1 = 4 ? 1 : Match1) . Match2
return

1NE:
	ToolTip, This is the 1NE subroutine
return

2NE:
	ToolTip, This is the 2NE subroutine
return

3NE:
	ToolTip, This is the 3NE subroutine
return
Thank you so much, I will now try and implement but quite confident it will be fine
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Parsing a label  Topic is solved

11 Dec 2019, 14:54

It's a good idea to have the return there to mark the end of the auto-execute section of the script as a best practice. Just move the initial assignment of the InpurVar before the return or it won't ever execute that line.

Return to “Ask For Help”

Who is online

Users browsing this forum: artur1884, Bing [Bot], Rohwedder, zavf and 38 guests