Jump to content

Parsing multiline (& _) string concatenation results in error


Recommended Posts

Hi,

I get an error when trying to build a multiline concatenated string with comments inbetween. I think it's more like a minor bug than a real problem, but since I saw bug report forums are closed/archived and I don't know if it's a kown thing or not, I'm gonna post it here to be sure if this needs to be reported as a bug or it's not.

 

This example I made for this purpose works:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Form1 = GUICreate("Test", 150, 168, 392, 362)
Global $Input1 = GUICtrlCreateInput("1", 3, 10, 130, 21)
Global $Input2 = GUICtrlCreateInput("11", 3, 43, 130, 21)
Global $Input3 = GUICtrlCreateInput("123", 4, 76, 130, 21)
Global $Input4 = GUICtrlCreateInput("1234", 4, 108, 130, 21)
Global $BtnTest = GUICtrlCreateButton("Test", 3, 136, 130, 25)
GUISetState(@SW_SHOW)

$TestString = "Test values: " & _
GUICtrlRead($Input1) & "," & _
GUICtrlRead($Input2) & "," & _
GUICtrlRead($Input3) & "," & _
GUICtrlRead($Input4)

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $BtnTest
            MsgBox(0,"test",$TestString)
    EndSwitch
WEnd

 

But this throws errors during compilation:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Form1 = GUICreate("Test", 150, 168, 392, 362)
Global $Input1 = GUICtrlCreateInput("1", 3, 10, 130, 21)
Global $Input2 = GUICtrlCreateInput("11", 3, 43, 130, 21)
Global $Input3 = GUICtrlCreateInput("123", 4, 76, 130, 21)
Global $Input4 = GUICtrlCreateInput("1234", 4, 108, 130, 21)
Global $BtnTest = GUICtrlCreateButton("Test", 3, 136, 130, 25)
GUISetState(@SW_SHOW)

$TestString = "Test values: " & _
GUICtrlRead($Input1) & "," & _
GUICtrlRead($Input2) & "," & _
;Crash my building here pls!
GUICtrlRead($Input3) & "," & _
GUICtrlRead($Input4)

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $BtnTest
            MsgBox(0,"test",$TestString)
    EndSwitch
WEnd

Did one more test and found that this is true also for code and not only for string concatenations. The code gets evaluated as actual code even if it's a comment. Look at the If statement:

This works:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Form1 = GUICreate("Test", 150, 168, 392, 362)
Global $Input1 = GUICtrlCreateInput("1", 3, 10, 130, 21)
Global $Input2 = GUICtrlCreateInput("11", 3, 43, 130, 21)
Global $Input3 = GUICtrlCreateInput("123", 4, 76, 130, 21)
Global $Input4 = GUICtrlCreateInput("1234", 4, 108, 130, 21)
Global $BtnTest = GUICtrlCreateButton("Test", 3, 136, 130, 25)
GUISetState(@SW_SHOW)

Global $ShowMessage = True

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $BtnTest
            $TestString = "Test values: " & _
                    GUICtrlRead($Input1) & "," & _
                    GUICtrlRead($Input2) & "," & _
                    GUICtrlRead($Input3) & "," & _
                    GUICtrlRead($Input4)
            If (StringLen($TestString) > 25 And _
                    $ShowMessage) Then
                MsgBox(0, "test", $TestString)
            Else
                MsgBox(0, "test", "Oh noes!")
            EndIf
    EndSwitch
WEnd

And this won't:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Form1 = GUICreate("Test", 150, 168, 392, 362)
Global $Input1 = GUICtrlCreateInput("1", 3, 10, 130, 21)
Global $Input2 = GUICtrlCreateInput("11", 3, 43, 130, 21)
Global $Input3 = GUICtrlCreateInput("123", 4, 76, 130, 21)
Global $Input4 = GUICtrlCreateInput("1234", 4, 108, 130, 21)
Global $BtnTest = GUICtrlCreateButton("Test", 3, 136, 130, 25)
GUISetState(@SW_SHOW)

Global $ShowMessage = True

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $BtnTest
            $TestString = "Test values: " & _
                    GUICtrlRead($Input1) & "," & _
                    GUICtrlRead($Input2) & "," & _
                    GUICtrlRead($Input3) & "," & _
                    GUICtrlRead($Input4)
            If (StringLen($TestString) > 25 And _
                ;Crash me plz!
                    $ShowMessage) Then
                MsgBox(0, "test", $TestString)
            Else
                MsgBox(0, "test", "Oh noes!")
            EndIf
    EndSwitch
WEnd

 

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Link to comment
Share on other sites

  • Moderators

Newb,

I am not in the least surprised that you get a syntax error when you stick a comment in the middle of a line - would you expect this to work?

$TestString = "Test values: " & GUICtrlRead($Input1) & "," & GUICtrlRead($Input2) & "," & ;Crash my building here pls! GUICtrlRead($Input3) & "," & GUICtrlRead($Input4)

If you must have a comment in the middle of a continued string, just put it at the end of a line where it gets ignored:

$TestString = "Test values: " & _
GUICtrlRead($Input1) & "," & _
GUICtrlRead($Input2) & "," & _ ;Crash my building here pls!
GUICtrlRead($Input3) & "," & _
GUICtrlRead($Input4)

M23

P.S. And you report bugs at https://www.autoitscript.com/trac/autoit - there is a "Bug Tracker" link in the menu bar at the top of the page.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Well I won't expect that to work since you put it all inline, but my comment was on the next line and wasn't including the actual code.

From my point of view, there is no much difference between

$TestString = "Test values: " & _
GUICtrlRead($Input1) & "," & _
GUICtrlRead($Input2) & "," & _ ;Crash my building here pls!
GUICtrlRead($Input3) & "," & _
GUICtrlRead($Input4)

and

$TestString = "Test values: " & _
GUICtrlRead($Input1) & "," & _
GUICtrlRead($Input2) & "," & _ 
;Crash my building here pls!
GUICtrlRead($Input3) & "," & _
GUICtrlRead($Input4)

expecially when the syntax highlighter colors hints me that autoit will read that comment line as a comment (green) and the code as code (other colors).
In your inline example

$TestString = "Test values: " & GUICtrlRead($Input1) & "," & GUICtrlRead($Input2) & "," & ;Crash my building here pls! GUICtrlRead($Input3) & "," & GUICtrlRead($Input4)

the syntax highlighter hints me that everything after the semicolon is read as a comment so I'm expecting  that to not work of course.

Anyway I didn't reported it as a bug because I wanted a second opinion about this and wanted to know if this it's worth reporting.

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Link to comment
Share on other sites

Though the help file doesn't explicitly say it, Melba's demonstration is a good explanation of why breaking the multiline with a comment won't work. However the help file does show how to, "combine underscore and semicolon to put comments on lines and still have a long statement span on next line." (also demonstrated by Melba).

Edited by spudw2k
grammar
Link to comment
Share on other sites

  • Moderators

Newb,

From my point of view, there is no much difference

But from the point of view of the interpreter there most certainly is - it expects the next line after a continuation character to be the next part of the string.

 I wanted a second opinion about this and wanted to know if this it's worth reporting

You have one and it is not.

M23 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ok guys, thanks for the clarification!

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Link to comment
Share on other sites

Just prefix the commentline with:  "" & _ ; 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Form1 = GUICreate("Test", 150, 168, 392, 362)
Global $Input1 = GUICtrlCreateInput("1", 3, 10, 130, 21)
Global $Input2 = GUICtrlCreateInput("11", 3, 43, 130, 21)
Global $Input3 = GUICtrlCreateInput("123", 4, 76, 130, 21)
Global $Input4 = GUICtrlCreateInput("1234", 4, 108, 130, 21)
Global $BtnTest = GUICtrlCreateButton("Test", 3, 136, 130, 25)
GUISetState(@SW_SHOW)

$TestString = "Test values: " & _
GUICtrlRead($Input1) & "," & _
GUICtrlRead($Input2) & "," & _
"" & _ ;  Do NOT crash my building here pls!
GUICtrlRead($Input3) & "," & _
GUICtrlRead($Input4)

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit
        Case $BtnTest

            MsgBox(0,"test",$TestString)
    EndSwitch
WEnd

 

 

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Hello all one quick silly question if u dnt mind, this is kinda off topic dnt wnt to start another thread for small issue. Whats the use of underscore ? What does it do? Is it like a @CRLF or break?, or something else?

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...