v2: How to assign the continuation section with "variable b" to "variable a"? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

v2: How to assign the continuation section with "variable b" to "variable a"?

27 Dec 2022, 04:10

Hi friends,
I'm new to v2. I'm in some trouble and I hope I can get help.
Maybe the title is a little hard to understand, but let me use the code to clarify what I want to ask. This should be clear enough.

In v1.1, I can get the variable "var3" like this:

Code: Select all

var1 := "text1"
var2 := "text2"
var3 := "
( LTrim
    line1:  " var1 "
    line2: " var2 "
)"
; Explain that I want the variable "var3", not just to display a text in a message box. 
; This is just to check whether "var3" is the result I want.
MsgBox %var3%  ; I know this is the writing method in v1.1.
MsgBox(var3)  ; This is v2.
But the same writing method does not work in v2. I read the script and variable help, and tried many writing methods, but I failed.
I still need to work hard for a long time in v2. Can someone help me?


[Mod edit: Topic moved to v2 help.]
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: v2: How to assign the continuation section with "variable b" to "variable a"?  Topic is solved

27 Dec 2022, 06:31

Hi 6Tom,
your whole continuation area is just text. Your inner quotation marks do not separate variables, but are also just text.
This one works:

Code: Select all

var1 := "text1"
var2 := "text2"
var3 :=
( LTrim
    "line1:  " var1
    "`nline2: " var2
)
MsgBox(var3)
User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: v2: How to assign the continuation section with "variable b" to "variable a"?

27 Dec 2022, 07:23

@haichen
Thank you, haichen. This is really helpful. It solved my problem.

I have another question. Is there a way to write without "`n"? Just ask, if not, I will write it like this in the future.
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: v2: How to assign the continuation section with "variable b" to "variable a"?

27 Dec 2022, 09:46

Code: Select all

var3 :=
( LTrim
    "line1:  " var1
	"
	line2: " var2
)

Code: Select all

var3 :=
( LTrim
    "line1:  " var1
	"
	"
	"line2: " var2
)

Code: Select all

p:="`n"
var3 :=
( LTrim
    "line1:  " var1
	p
     "line2: " var2
)
or

Code: Select all

var1 := "text1`n"
User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: v2: How to assign the continuation section with "variable b" to "variable a"?

27 Dec 2022, 09:56

haichen wrote:
27 Dec 2022, 09:46

Code: Select all

var3 :=
( LTrim
    "line1:  " var1
	"
	line2: " var2
)

Code: Select all

var3 :=
( LTrim
    "line1:  " var1
	"
	"
	"line2: " var2
)

Code: Select all

p:="`n"
var3 :=
( LTrim
    "line1:  " var1
	p
     "line2: " var2
)
or

Code: Select all

var1 := "text1`n"
Amazing. Thanks a lot for sharing.
lexikos
Posts: 9635
Joined: 30 Sep 2013, 04:07
Contact:

Re: v2: How to assign the continuation section with "variable b" to "variable a"?

27 Dec 2022, 19:48

Also

Code: Select all

var1 := "text1"
var2 := "text2"
var3 :=
( LTrim
    "line1:  " var1 "
    line2: " var2
)
MsgBox(var3)
The point is that line breaks are permitted inside quoted strings in a continuation section (but they are replaced with `n or whatever the Join option set).
User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: v2: How to assign the continuation section with "variable b" to "variable a"?

28 Dec 2022, 00:39

lexikos wrote:
27 Dec 2022, 19:48
Also

Code: Select all

var1 := "text1"
var2 := "text2"
var3 :=
( LTrim
    "line1:  " var1 "
    line2: " var2
)
MsgBox(var3)
The point is that line breaks are permitted inside quoted strings in a continuation section (but they are replaced with `n or whatever the Join option set).
This looks very clear. Now I can probably understand this principle. Thank you lexikos.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: thqby, wilkster and 94 guests