Jump to content
Newb

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.

Share this post


Link to post
Share on other sites

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

 

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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

 

Share this post


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

 

 


UDF: _SingleScript()                                        If you like my post, just click the like button :)        here -->

Share this post


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

Share this post


Link to post
Share on other sites

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

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

    • By nooneclose
      Good morning, I am trying to figure out if it is possible to check if these invoice lines exist or not. 
      Here are the table and column name: INVOICELINE.INVOICELINENUM (a required field if created)
      Here is a picture of what I am talking about. (Do not worry about security. the picture is from a demo test site so all information is fake)
       
      is there any way to check if these fields exist or not? (they do not exist unless the user clicks on "New Row")
      Example: line 11 does not exist right now. How would I go about to see if it did or not? 
      This is what I have so far:
      SELECT DISTINCT iv.invoicenum, iv.description FROM invoice AS iv JOIN invoiceline AS ivl ON iv.invoicenum = ivl.invoicenum AND iv.siteid = ivl.siteid /* = 'nothing' and yet somehow not null? */ WHERE iv.invoicenum NOT IN (SELECT invoicelinenum FROM invoiceline WHERE invoicelinenum IS NOT NULL) I get 0 results where I should get more than 0. 
    • By Kruxe
      Hello Everyone,
      I am very green when it comes to AutoIT, I have recently started using it to automate a job that i perform using MS Excel and that is working great. Recently I have been faced with a challenge I which i need to copy a specific set of lines from one .txt file and past them, overwriting a specific set of lines in a different .txt file. I honestly have no clue how I can copy the specified lines and transfer them. What functions / commands could I use and how could I lay them out I AutoIT? Any and all help will be appreciated. 
      Thanks!
      Kruxe
    • By Saravanan2213
      Hi everyone,
      i just need your help. i have script for cleaning browsing history and other unwanted file but the problem is i don't want to see the GUI i have attached below. It should not show anything on the screen. is it possible to do it in autoit. thanks in advance.
       
      So for i have tried flag
      Run("rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 255", "", @SW_HIDE)
      @SW_DISABLE
       
      Looking forward your help.........

    • By cptHark
      Hello I want to conect to a Network with DriveMapAdd.
      This worked just fine but when you restart the Computer the Mapped drive is gone.
      So i used the persistent mapping flag and that seemed to work, too.
      However when the Computer is restarted I cant connect to the Network because it doesnt remember the Username and password I ave it the first time.
      How do I fix this?
      My Code:Func
      setdrivem()
          DriveMapAdd("M:", GUICtrlRead($driveM),1, GUICtrlRead($netzuser),GUICtrlRead($netzpassword) )
      EndFunc
      $netzuser and $netzpassword are set earlier in the gui and it works right after executing the script but i want it to stay connected
    • By nooneclose
      Morning, I am wondering is there is a way to prevent a script from ending/crashing when a "Subscript used on non-accessible variable" error occurs? 
      Here is some of my code:
      $aItems = _OL_ItemFind($oOutlook, $mFolder[1], $olMail, "[UnRead]=True", "Subject", "Maintenance Request", "EntryID,Subject", "", 0) If @error Then Sleep(2000) LoopUnreadEmails() ;Exit MsgBox(48, "", "@error = " & @error & ", @extended: " & @extended & " at line: " & @ScriptLineNumber) EndIf Error Msg:
      (371) : ==> Subscript used on non-accessible variable.: $aItems = _OL_ItemFind($oOutlook, $mFolder[1], $olMail, "[UnRead]=True", "Subject", "Maintenance Request", "EntryID,Subject", "", 0) $aItems = _OL_ItemFind($oOutlook, $mFolder^ ERROR I know that error occurs very rarely and at random. But like with most errors "in this case" I can use recursion to fix it. 
      I just recall the function and it will and has fixed itself. But this "Subscript used on non-accessible variable" just ends the script.
      Like I said before, is there a way to allow the script to keep running or call a function when this error occurs instead of just ending?   
×
×
  • Create New...