Jump to content
Newb

Parsing multiline (& _) string concatenation results in error

Recommended Posts

Newb

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.

Share this post


Link to post
Share on other sites
Melba23

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.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Newb

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.

Share this post


Link to post
Share on other sites
spudw2k

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
  • Like 1

Share this post


Link to post
Share on other sites
Melba23

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 

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Newb

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.

Share this post


Link to post
Share on other sites
Exit

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

 

 


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
232showtime

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.

Share this post


Link to post
Share on other sites
iamtheky
  • Like 1

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

Share this post


Link to post
Share on other sites
232showtime

@boththose many thanks... ;)


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.

Share this post


Link to post
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

  • Similar Content

    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
    • Zein
      By Zein
      #include "..\Include\Array.au3" #include "..\Include\File.au3" #include "..\Include\AutoItConstants.au3" Local $aRetArray Local $sFilePath = "n.csv" _FileReadToArray($sFilePath, $aRetArray, ",") ; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",") _ArrayDisplay($aRetArray, "Original", Default, 8) The above code shows two versions of _FileReadToArray and both don't work as expected.
      The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

      I looked again at the documentation:
       
      #include <File.au3> _FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )
      And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
      I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

       
    • nooneclose
      By nooneclose
      I need to perform a subtotal in excel and I would like to automate this process using Autoit if possible like always any and all help will be greatly appreciated. 
      I can not find a good example but the two from Microsoft. Here is one of the two from msdn.microsoft.com/en-us/vba/excel-vba/articles/range-subtotal-method-excel
      I do not really understand how to translate this into AutoIt, but I gave it a try and here is what I have.
      $OpenRange      = "A1:E200" $xlSum          = -4157 $Added_Array[2] = [2, 3] $OpenRange.Subtotal("B1", $xlSum, $Added_Array, True, False, True) I just need to perform a subtotal on a range based on a header called department, and then perform a sum on the results.
    • nooneclose
      By nooneclose
      How to use _Excel_RangeSort to sort my excel file by three different headers Column A1, B1, and C1 have headers on which I want to sort by. The headers on which I want to sort are department, employee type, and name.
      I still really new to AutoIt so I do not actually know how to properly start this line or lines of code, to be honest. The example code is the best I can do.
      _Excel_RangeSort($OpenWorkbook, Default, "A1:C1", "1:1", $xlDescending, Default, $xlYes, Default, $xlSortRows) I just need to sort by those three headers in that order of department, employee type, and name, plus in descending order.
       
      any and all help would be greatly appreciated.  Thank you!
×