[v2.0a] Multi-line content/formatting with Join Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

[v2.0a] Multi-line content/formatting with Join

27 Aug 2017, 18:28

Unsure if topic name is accurate, so let me explain and show code example:
In current main release You can use Join to make multi-line variable/array/object or MsgBox content, but the same method doesn't work anymore in 2.0-a081-cad307c. See this:

Code: Select all

; AHK 1.1
TestVar :=
(Join
{
	"key":
	{
		"one": "1",
		"two": "2"
	}
}
)
MsgBox % TestVar.key.two



; AHK 2.0a
TestVar :=
(Join
{
	"key":
	{
		"one": "1",
		"two": "2"
	}
}
)
MsgBox(TestVar.key.two)

/*
Line Text: "key":	{		"one": "1",		"two": "2"	}}
Error: Missing close-quote
*/
Is it or similar effect doable in 2.0a? This is mostly about visual aspect in the code.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
Helgef
Posts: 4461
Joined: 17 Jul 2016, 01:02
Contact:

Re: [v2.0a] Multi-line content/formatting with Join

28 Aug 2017, 04:14

Hello SirRFI, I know nothing about this, there is a (possibly) related note here, search for Join. AlsoJoin.

Cheers.
Edit:
obeeb wrote:You need to add the Q option(short for Quotes):
Cheers :thumbup:
Last edited by Helgef on 28 Aug 2017, 05:11, edited 1 time in total.
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: [v2.0a] Multi-line content/formatting with Join  Topic is solved

28 Aug 2017, 04:41

You need to add the Q option(short for Quotes):

Code: Select all

TestVar :=
(Join Q
{
	"key":
	{
		"one": "1",
		"two": "2"
	}
}
)
MsgBox(TestVar.key.two)
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: [v2.0a] Multi-line content/formatting with Join

28 Aug 2017, 06:14

Didn't see that one, thus more there's also a C for comments - wonderful! Thanks.

I also used Join for MsgBoxes - is it doable for 2.0a as well? Using the same/similar strategy, which means different from:

Code: Select all

MsgBox(TestVar[1]	"`n"
.	TestVar[2]	"`n"
.	TestVar[3]	"`n"
.	TestVar[4]	"`n")
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: [v2.0a] Multi-line content/formatting with Join

29 Aug 2017, 06:45

obeeb wrote:How did you do it in v1?

Code: Select all

some_var := "for test"
MsgBox %
(Join
	"text`n"
	some_var
)
Tried using the newly learned Q and C parameters for Join, but all variations I tried failed.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [v2.0a] Multi-line content/formatting with Join

29 Aug 2017, 11:42

I actually find all this continuation section stuff quite confusing, I'm not clear on all the details yet. However I do have some working code for this:

Code: Select all

some_var := "for test"
MsgBox
(Join Q

	"text`n"
	some_var
)

some_var := "for test"
MsgBox
(Join`s Q

"text`n"
some_var
)

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

some_var := "for test"
MsgBox(
(Q
"text`n"
some_var
))

some_var := "for test"
MsgBox(
(Join Q

	"text`n"
	some_var
))

some_var := "for test"
MsgBox(
(Join`s Q
"text`n"
some_var
))
The thing to be aware of is that a leading space or tab in a continuation section is ignored. I.e., roughly speaking, as though LTrim was applied to the continuation section.
Last edited by jeeswg on 30 Aug 2017, 05:35, edited 2 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
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: [v2.0a] Multi-line content/formatting with Join

30 Aug 2017, 04:22

jeeswg wrote:I actually find all this continuation section stuff quite confusing
So do I. Every attempt I made was using double parenthesis - one for the MsgBox function itself, other for Join. With your working code it's even weirder that it takes an extra empty line to work. Guess we better share our opinion on this matter before it's set on stone.


jeeswg wrote:The thing to be aware of is that a leading space or tab in a continuation section is ignored. I.e., roughly speaking, as though LTrim was applied to the continuation section.
That's actually desired and intended, because this is supposed to be treated as expression and string parts are in quotes.



Since obeeb answered the original question (which I thought would be enough for cases like MsgBox), I'll mark their post as "answered", but thanks everyone for contribution.
Last edited by SirRFI on 30 Aug 2017, 10:45, edited 1 time in total.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [v2.0a] Multi-line content/formatting with Join

30 Aug 2017, 05:47

This makes some of the changes clearer, see the section called 'Continuation Sections':
v2-changes
https://autohotkey.com/v2/v2-changes.htm

I now feel more clear about what the situation is. Although because of the multiple possibilities in each of AHK v1 and AHK v2, and the differences between AHK v1 and AHK v2, there's quite a lot to take in, so it would be a good idea to collect some examples. I might add something to my strings tutorial or start a new thread.

In making certain changes to the syntax in AHK v2, certain consequences of this made continuation sections potentially less useful, which Lexikos and/or others anticipated, hence making changes to continuation sections, including resolving that blank line issue (I've added more examples above) and this is mentioned in the 'changes' link that I've placed just above.

So in conclusion I think that continuation sections can be fiddly and yet they have been implemented well. Generally I say: imagine the contents of a continuation section 'unwrapped', i.e. as normal code combined into one line, with the round brackets at the beginning and end removed.

Funnily enough I intend to avoid using continuation sections and do things like this:

Code: Select all

q::
vText := "a"
. "`r`n" "b"
. "`r`n" "c"
MsgBox, % vText
return
For two reasons: for two-way compatibility, and ease of parsing lines when checking scripts, i.e. knowing whether a line is code or part of a continuation section.

[EDIT:][1800th post]
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 “Ask For Help”

Who is online

Users browsing this forum: electrone77, keylo, mikeyww, william_ahk and 55 guests