AHK v2 and strings

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

AHK v2 and strings

09 Sep 2017, 01:07

==================================================

AHK V2 AND STRINGS:

==================================================

INTRODUCTION:

suggestions:
- 'CdLn' custom function for preparing command-line parameters [EDIT: and/or pass an array to Run]
- Deref function restored as a built-in function or as a custom function [EDIT: or perhaps not]
- one-line 'continuation sections' (AHK v1/v2 compatible), code name 'Verbatim' [EDIT: 'var `= value' (for AHK v1-style assignment)]
- Format function to accept variable names inside the FormatStr parameter

[EDIT:] Summary of main ideas:

Code: Select all

vPathExe := "C:\Program Files\AutoHotkey\AutoHotkey.exe"
vPath := "C:\Program Files\AutoHotkey\AutoHotkey.ahk"

;ideally, allow AHK v1-style assignments, perhaps via an `= operator:
;note: use `s and/or `t for leading/trailing whitespace
vTarget = "%vPathExe%" "%vPath%"
MsgBox, % vTarget
vTarget = %A_ComSpec% "/c" "%vTarget%"
MsgBox, % vTarget

;a A_DQ variable could be useful:
A_DQ := Chr(34)
MsgBox, % vTarget := A_DQ vPathExe A_DQ " " A_DQ vPath A_DQ
MsgBox, % vTarget := A_ComSpec " /c " A_DQ vTarget A_DQ

;another useful approach that could also be added:
MsgBox, % vTarget := JEE_CdLn(vPathExe, vPath)
MsgBox, % vTarget := JEE_CdLn(A_ComSpec, "/c", vTarget)

;possibly also, Run to accept an array parameter:
;all 3 equivalent:
;vTarget := JEE_CdLn(vPathExe, vPath)
;Run(vTarget)

;Run(JEE_CdLn(vPathExe, vPath))

;Run([vPathExe, vPath])
return

;==================================================

;AHK v2 and strings - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=36833

JEE_CdLn(oArray*)
{
	vOutput := ""
	for _, vValue in oArray
	{
		if InStr(vValue, " ")
			vOutput .= (A_Index=1?"":" ") Chr(34) vValue Chr(34)
		else
			vOutput .= (A_Index=1?"":" ") vValue
	}
	return vOutput
}

;==================================================
issues to address:
- Format doesn't handle variable names
- handling paths with hardcoded 'A_'/environment variables: e.g. '%AppData%\MyDir'
- improved readability gained in certain circumstances by using %%
- inconvenience of 4-line continuation sections for assigning 1 line of text
- a custom Deref function cannot identify escaped (i.e. literal) % signs
- a custom Deref function cannot distinguish between local/global variables
- a Deref function could support objects as well as variables
- %% is not just an AHK thing, it's a Windows thing

characters:
- " - paths use double quotes a lot
- % - paths use percent signs a lot (environment variables)
- {} - Send/SendInput use curly braces a lot
- () - functions use parentheses a lot
- " - functions use double quotes a lot
- , - functions use commas a lot
- " and ' - handling strings that contain both " and '

==================================================

BENEFITS OF %%:

- %% is not just an AHK thing, it's a Windows thing, people are tempted to keep it not just because they're used to it, but because it's a common notation used by Windows for paths.

- %% can be used to improve readability:

Code: Select all

text2 := "text2", text4 := "text4"
vPath := Deref("%dir%\text1 %text2% text3 %text4%.%ext%")
;versus:
vPath := dir "\text1 " text2 " text3 " text4 "." ext

vPath := A_ScriptFullPath
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
vText := Deref("
(
path: %vPath%
name: %vName%
dir: %vDir%
ext: %vExt%
name no ext: %vNameNoExt%
drive: %vDrive%
)")
- %% may appear in path names in selected text, and can be useful for storing paths in ini files:

Code: Select all

%A_Desktop%\MyFile.txt
%A_ScriptDir%\MyFile.txt
%vDirLogs%\MyFile.txt
%A_ScriptDir%\MyLog %A_YYYY%-%A_MM%.txt
C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Recent
This highlights the importance of having a Deref function that can handle % signs.

- Although for simple paths, environment variables do not always aid readability particularly:
vPath := Deref("%A_Desktop%\MyFile.txt")
versus:
vPath := A_Desktop "\MyFile.txt"

It is better, in an ini file, to store:
'%A_Desktop%\MyFile.txt'
versus:
'A_Desktop "\MyFile.txt"'
And it is easier to copy/paste/modify strings back and forth between Explorer and the AHK editor, if they are stored in a form that is closer to the original paths. It is also easier to manipulate and perform text operations on the environment variable form.

- The %% notation doesn't just have to be used for variables:
var := Deref("text%var%text")
it could be extended to handle objects e.g.:
var := Deref("text%obj.key%text")

- When considering notation for dereferencing:
{} - Send/SendInput use curly braces a lot
() - functions use parentheses a lot
% - % is a character that is used very rarely and is quite bold and easy to identify

==================================================

BENEFITS OF AN (AMENDED) DEREF FUNCTION:

- The Deref function traditionally used `% to specify a literal percent sign, I am not necessarily against that, but my instinct is to not use such special handling, I would rather just do this:

Code: Select all

vNum := 20, vPct := "%"
MsgBox, % Deref("roughly %vNum%%vPct% of AutoHotkey users")
Note: if there was no built-in Deref function, I would have to use such a workaround anyhow.

- The Deref function could be made to handle objects:

Code: Select all

obj := {key:20}, vPct := "%"
MsgBox, % Deref("roughly %obj.key%%vPct% of AutoHotkey users")
Note: a custom Deref couldn't distinguish between local/global variables. I would have to use a workaround such as this:

Code: Select all

obj := {num:20, pct:"%"}
MsgBox, % Deref("roughly %obj.num%%obj.pct% of AutoHotkey users", obj)
- There is the option that %% could return a literal %, but I would be careful before settling on what %% could be used for, if anything.

- A Deref function could have a parameter with special options, e.g. to prefer environment variables where they exist, to use environment variables as a backup if no variable is found, and to change which character is used to do the dereferencing.

==================================================

ISSUES WITH COMMAND LINE PARAMETERS AND DOUBLE QUOTES:

I had thought that maybe bringing `" into AHK v1, if possible, could be a fix for string issues relating to double quotes in AHK v1/v2, but after considering many possible solutions for this issue, I don't think it would be a good solution ...

Examples of some of the possibilities re. command line parameters:

Code: Select all

;good:
Run, "%vPathExe%" "%vPath%" ;AHK v1

;all of these options are horrible:
vPathExe := "notepad.exe", vPath := A_ScriptFullPath
Run(Chr(34) vPathExe Chr(34) " " Chr(34) vPath Chr(34)) ;AHK v1/v2
Run("""" vPathExe """ """ vPath """") ;AHK v1
Run("`"" vPathExe "`" `"" vPath "`"") ;AHK v2
Run('"' vPathExe '" "' vPath '"') ;AHK v2 ;the single/double quotes merge together in certain fonts
Run(Format("`"{}`" `"{}`"", vPathExe, vPath)) ;AHK v2
Run(Format('"{}" "{}"', vPathExe, vPath)) ;AHK v2
;note: the Deref function was removed from AHK v2:
vDQ := Chr(34)
Run(Deref("%vDQ%%vPathExe%%vDQ% %vDQ%%vPath%%vDQ%")) ;AHK v1/v2
Run(Deref("""%vPathExe%"" ""%vPath%""")) ;AHK v1
Run(Deref("`"%vPathExe%`" `"%vPath%`"")) ;AHK v2

;this is the least bad option, although I won't use it
;because I want a two-way compatible option, plus
;there is no Deref function in AHK v2 at present:
Run(Deref('"%vPathExe%" "%vPath%"')) ;AHK v2

Code: Select all

;workaround:
vPathExe := "notepad.exe", vPath := A_ScriptFullPath
Run(JEE_CdLn(vPathExe,vPath))
JEE_CdLn(oArray*)
{
	vOutput := ""
	for _, vValue in oArray
	{
		if InStr(vValue, " ")
			vOutput .= (A_Index=1?"":" ") Chr(34) vValue Chr(34)
		else
			vOutput .= (A_Index=1?"":" ") vValue
	}
	return vOutput
}

Code: Select all

;suggestion:
Verbatim, vOpt, vTarget, "%vPathExe%" "%vPath%" ;AHK v1/v2
Run(vTarget)
- [EDIT:] Here I mentioned that you could let Run accept an array:
Reconsideration request? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=39778&p=182026#p182026

Code: Select all

vPathExe := "C:\Windows\System32\notepad.exe"
vPath := "C:\MyDir\MyFile.txt"
MsgBox(JEE_CdLn(vPathExe,vPath)) ;"C:\Windows\System32\notepad.exe" "C:\MyDir\MyFile.txt"
Run(JEE_CdLn(vPathExe,vPath))

Run([vPathExe,vPath]) ;perhaps Run could accept an array to achieve the same thing
==================================================

BENEFITS OF A ONE-LINE CONTINUATION SECTION:

i.e. a special 'Verbatim' command:

- the inconvenience of 4-line continuation sections for assigning 1 line of text

- the avoidance of extra quote or escape characters that make text less readable
" - paths use double quotes a lot
" - functions use double quotes a lot
" and ' - single/double quotes can merge together appearance-wise, i.e. they can look unclear in many fonts, making it hard to distinguish between the characters

- text can be maintained in its original form, which is useful for copy and paste

- the convenience of special options such as an environment variable mode, so you could just use %username% instead of %A_UserName% etc

- useful for AHK v1 forwards compatibility to AHK v2, if the command was to have the same behaviour in both versions

==================================================

FORMAT FUNCTION:

- Format doesn't handle variable names (at present)

- Send/SendInput use curly braces a lot, but so does Format, this again suggests the potential usefulness of the Deref function.

- Here's how I might use Format to do a particular task from earlier. Also, if Format could handle variable names, or objects/keys, one idea might be:

Code: Select all

vNum := 20, obj := {key:20}
MsgBox, % Format("roughly {}% of AutoHotkey users", vNum)
MsgBox, % Format("roughly {1:i}% of AutoHotkey users", vNum)
MsgBox, % Format("roughly {vNum:i}% of AutoHotkey users")
MsgBox, % Format("roughly {obj.key:i}% of AutoHotkey users")

;if there was the potential for any number versus variable name clashes, unlikely since in AHK v2, variable names can't begin with a digit, you could put the variable name in brackets:
MsgBox, % Format("roughly {(vNum):i}% of AutoHotkey users")
Thanks for reading.
Last edited by jeeswg on 27 Sep 2019, 17:34, edited 6 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: AHK v2 and strings

09 Sep 2017, 02:48

With regards to deref function, take a look at macro functions in AHK_H v2:

Code: Select all

text2 := "text2", text4 := "text4"
vPath1 := Deref("%dir%\text1 %text2% text3 %text4%.%ext%")
;versus:
vPath2 := dir "\text1 " text2 " text3 " text4 "." ext
MsgBox vpath1 "`n" vpath2
vPath := A_ScriptFullPath
SplitPath vPath, vName, vDir, vExt, vNameNoExt, vDrive
vText := Deref("
(
path: %vPath%
name: %vName%
dir: %vDir%
ext: %vExt%
name no ext: %vNameNoExt%
drive: %vDrive%
)")
MsgBox vtext
; same works inside a function
fun()
fun(){
	text2 := "text2", text4 := "text4"
	vPath1 := Deref("%dir%\text1 %text2% text3 %text4%.%ext%")
	;versus:
	vPath2 := dir "\text1 " text2 " text3 " text4 "." ext
	MsgBox vpath1 "`n" vpath2
	vPath := A_ScriptFullPath
	SplitPath vPath, vName, vDir, vExt, vNameNoExt, vDrive
	vText := Deref("
	(
	path: %vPath%
	name: %vName%
	dir: %vDir%
	ext: %vExt%
	name no ext: %vNameNoExt%
	drive: %vDrive%
	)")
	MsgBox vtext
}

macro deref(__deref__,__out__:="",__set__:=""){
	Loop Parse, __deref__, "%"
		If __set__&&!__set__:=false
			__out__.=%A_LoopField%
		else if SubStr(A_LoopField,-1)="``"
			__out__.=SubStr(A_LoopField,1,-1) "%"
		else __out__.=A_LoopField,__set__:=true
	return __out__
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AHK v2 and strings

09 Sep 2017, 03:04

Thank you HotKeyIt, I'm not quite sure how a macro function differs from a normal function, or if this addresses any of the issues where I said that a built-in Deref function could have capabilities that a custom Deref function couldn't have e.g. escaped % and local/global variable handling. I will check the AHK_H help.

Re. attempts at a custom Deref function, I've found three variations from searching txt file backups of my posts:
objects: define succinctly, retrieve dynamically - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 19#p155519
objects: define succinctly, retrieve dynamically - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 75#p156575
Re: v2.0-a079-be5df98 - Loop statements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 49#p153249
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: AHK v2 and strings

09 Sep 2017, 04:08

Correct, macro function will use callers scope except for parameters, those will be local, see: Macro functions
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AHK v2 and strings

09 Sep 2017, 20:08

I searched here for 'macro', and it turns out they're very new (09 Jul 2017, 2 months ago):
AutoHotkey Community - Search
https://autohotkey.com/boards/search.ph ... thor_id=60
[AHK_H v2] Macro functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 65&t=34227

Functions
https://hotkeyit.github.io/v2/docs/Functions.htm#Macro
Macro will use caller's scope for all variables except for parameters, function parameters will be resolved to local variables.
Dynamic variable references will also use caller's scope.

Global and static variables are not supported in macros.
This is very interesting, and I had been wondering which commands/functions can't be recreated via standard functions due to scope issues (and for any other reasons generally). I can think of:
- Deref
- RegExMatch: variable mode
- StringSplit
- SysGet: Monitor subcommand
- WinGet: ControlList/ControlListHwnd/List subcommands

Also, I think SubStr has to be a variadic function for example.

Also, I'm curious as to whether you had any particular need to pursue the macro function functionality, interestingly you cite Deref itself as an example at the webpage. Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: AHK v2 and strings

10 Sep 2017, 03:46

Probably this is for ahk_h not for v2 due to v2 now havent deref and macro.
AHKv2.0 alpha forever.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: AHK v2 and strings

10 Sep 2017, 04:16

I had the idea long ago when I reused same code in various places in a script. Gosub and functions were not very convenient because you would need to use global variables or pass a lot of variables to the function.
When deref was removed in v2, I thought it is now time to build such macro feature.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AHK v2 and strings

10 Sep 2017, 04:44

@_3D_: AHK v1 has Transform's Deref subcommand, and initially AHK v2 did have a Deref function. Although my instinct would be that escaping `% be removed, I could probably work around it whether it was kept or removed.

If possible I would recreate the Deref function myself, but in this case an effective cloned custom function is not possible due to scope issues.

In temporary and permanent scripts in AHK v1 I like to present paths like this:
vPath = %A_Desktop%\MyFile %A_Now%.txt
For AHK v2 I would like to do this, which used to be possible:
vPath := Deref("%A_Desktop%\MyFile %A_Now%.txt")

I do not like this, even though it's shorter:
vPath := A_Desktop "\MyFile " A_Now ".txt"

@HotKeyIt: Interesting, cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: AHK v2 and strings

10 Sep 2017, 09:04

Changes sins 2.079 https://autohotkey.com/boards/search.ph ... 7&sr=posts
Yep sintax:= "`% variable + 1000" removed from v2
still valid val:= var "string" / val:= %var%
not valid val:= "%var%" / % var "string"
In other words v2 can`t transfer variables inside the strings more.
Deref https://autohotkey.com/boards/viewtopic ... 37&t=36434
AHKv2.0 alpha forever.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AHK v2 and strings

30 Sep 2017, 05:55

For a Verbatim 'command', some options would be:
- e1: dereference any environment variables before other variables
- e2: dereference any normal variables first, if the contents are blank, check if an environment variable exists
- d%: use % as the dereference character for variables and obj.key, you can specify any character e.g. d| to use pipe, perhaps d by itself would default to d%
- d{}, d(), d[], d`s, d`t, d09, d32: some special delimiter options for brackets/spaces/tabs
- note: e1 and e2 would assume a delimiter of % if not specified
- `: to make ` literal (in this sense Verbatim is not literal by default)
- C: to allow semicolon comments
- % / , / Q / Join: wouldn't be necessary (cf. continuation sections)
- LTrim / LTrim0 / RTrim0: wouldn't be necessary, the string starts at the first non-whitespace character, and ends at the last non-whitespace character: use `s / `t / A_Space / A_Tab for leading/trailing whitespace

Verbatim would be a good substitute for 'var = value', which is one relic of AHK v1 that I believe had some advantages, including for handling command line parameters and text with single and/or double quotes. I also like to be able to create literal comma-separated lists that don't end with a ".

AutoHotkey Scripts and Macros
https://autohotkey.com/docs/Scripts.htm#continuation
AutoHotkey Scripts and Macros
https://lexikos.github.io/v2/docs/Scrip ... ntinuation

==================================================

For double quotes "" is quite good, and adds compatibility with Excel (and AHK v1) and possibly other languages. I'm not sure if it's possible to have both "" and `" in AHK v2.

Code: Select all

MsgBox, % StrLen("a""a") ;AHK v1
;=LEN("a""a") ;Excel
return

;MsgBox(StrLen("a`"a")) ;AHK v2
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AHK v2 and strings

10 Apr 2018, 18:45

- I was thinking about simpler alternatives to some of these ideas that might be popular.
- I decided that two things were really important: maintaining 'var = value' in some form, and maintaining the equivalent of %var% in continuation sections.

VAR = VALUE / VERBATIM TEXT
- For 'var = value':

Code: Select all

var `= value
;or a different operator, or:
Verbatim var, value
;or Verbatim/Assign/Literal/Text/another name:
Verbatim var, options, value ;where options is hardcoded
;or something quite different
- I've removed the options parameter. For anything fancy, a continuation section could be used.
- I know that having both single and double quotes to mark the start/end of a string gets us pretty close to having verbatim one-liners. However, I think it's worth it to know that you can simply paste the text in, and it will work without problems. E.g. when writing quick code. Also, you have the advantage of not needing to add trailing/leading quotes. And you can define variables 'lazily' initially, but then use a parser to tidy up the definitions later. I think that convenience/ease-of-use is a key principle of AutoHotkey.
- Also, sometimes text contains both single quotes and double quotes. And sometimes the quotes blur with the start/end text, making it less readable. E.g. to specify a single/double quote by itself you need: "'" or '"', which aren't great. Neither are Chr(39) or Chr(34).
- Also, IMO it's the mark of a good programming language to have good verbatim text support. And if *all* languages could be relied upon to support this, that would be greatly beneficial.
- And yes, two-way compatibility is a good reason.
- Note: I would suppose that since such text would be interpreted literally, and if no options parameter were allowed, you could not write comments on such a line, i.e. ' ;', would be interpreted literally. Which I'm OK with. It's possible that the 'command' would be sufficiently useful, or perhaps better, without the options parameter. Continuation sections would still be available for anything fancy.

'DEREFERENCE' TEXT
- E.g. it's been mentioned before that something like this would be useful:
vText := "Hello {Name}"
- I do not think that the syntax of AutoHotkey should be changed. However, having a function that can parse text like this would be a good thing.
- The Format function could accept an associative array for example:
MsgBox, % Format("Hello {Name}", {Name: "My Name"})
- Also, the Format function by default uses { and }, I think it would be good to be able to change these characters temporarily. Perhaps via an 'A_' variable, that takes a string 2 characters in length, either that must be different, or possibly where they can be the same.
- Potentially you could have {1.key1} and {2.key1}, the first would get 'key1' from the object in the first parameter, and the second would get 'key1' from the object in the second parameter. ('key1' by itself/any non-integer might mean get 'key1' from the object in the first parameter, and '1'/any integer might mean get the text of the string in the first/nth parameter, as it does now.)

A_COMMA
As AutoHotkey becomes more function-y, with the move to all expression-style parameters. At least A_Comma could be useful, I know that I would use it occasionally. Other candidate characters are parentheses and single/double quotes (A_SQ/A_DQ).

Code: Select all

vText := StrReplace(vText, ", ", ",")
vText := StrReplace(vText, A_Comma " ", A_Comma)
vText := StrReplace(vText, A_Comma A_Space, A_Comma)
CONTINUATION SECTIONS
- I think it would be good to have a two-way compatible way to write multi-line verbatim text in both AHK v1/v2. Potential obstacles are AHK v1 handling ", and the choice of a letter to indicate the setting (perhaps V).

OTHER POINTS
- The CdLn function is nice, although if it wasn't built-in, I wouldn't mind.
- I've accepted that Deref might not be added in, and I can create my own custom function, that is almost as good.
- I do think that something like DerefEnv would be useful for lines like vPath := "C:\Users\%username%", to prepare the sort of text that the Run dialog supports, however, I could create my own function for this also.

Thanks for reading.

[EDIT:] Being able to switch code from var = value to var `= value (with possibly a few edits being required), or having a Format function that can handle %% instead of {}, and that can take an object (associative array), are very useful for simple manual conversions of old files, and avoiding suddenly adding new bugs to scripts.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AHK v2 and strings

06 May 2018, 09:47

VAR = VALUE (NOT VERBATIM)

Code: Select all

var = value ;AHK v1
var `= value ;AHK v1/v2 ;same as 'var = value' except that perhaps %var% is not dereferenced
`s could be made available in AHK v1 for var `= value
'var `= value' would be verbatim apart from `, and comment handling

CONTINUATION SECTIONS (AND VERBATIM)
For verbatim text perhaps a two-way compatible V verbatim mode e.g. '(V Join`r`n':
This works in AHK v2 at the moment, but % and " are problems in AHK v1.

Code: Select all

;ANSI (CP-1252) 32-255 verbatim
Clipboard := " ;continuation section
(` Join`r`n
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~
€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ
 ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
)"
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AHK v2 and strings

14 May 2018, 18:47

I wanted to create a quick list of paths in a continuation section, where the paths were written in expression style. It took me a little while to figure out.

Code: Select all

/*
;AHK v1
vList = ;continuation section
(
%A_ScriptDir%\File1.txt
%A_ScriptDir%\File2.txt
%A_ScriptDir%\File3.txt
%A_ScriptDir%\File4.txt
%A_ScriptDir%\File5.txt
)
MsgBox, % "[" vList "]"
*/

;AHK v1/v2 two-way compatible
vList2 := ""
. A_ScriptDir "\File1.txt"
. "`n" A_ScriptDir "\File2.txt"
. "`n" A_ScriptDir "\File3.txt"
. "`n" A_ScriptDir "\File4.txt"
. "`n" A_ScriptDir "\File5.txt"

;AHK v1/v2 two-way compatible
vList :=
(Join`s"`n"`s
A_ScriptDir "\File1.txt"
A_ScriptDir "\File2.txt"
A_ScriptDir "\File3.txt"
A_ScriptDir "\File4.txt"
A_ScriptDir "\File5.txt"
)
MsgBox("[" vList "]")
MsgBox("[" vList2 "]")
MsgBox(vList = vList2)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 38 guests