Jump to content
Sign in to follow this  
Jfish

Phantom syntax error - going crazy!

Recommended Posts

Jfish

Hello. Okay, I may be a super-newbie but something is very strange here and I am going absolutely mental trying to figure it out. Arrgggghhh. :lmao:

Glad I got that off my chest. :)

I created a little script that grabs the code from the au3 recorder window and inserts a bunch of user defined stuff and then saves it to a file. I am reluctantly posting this spaghetti code which is not done yet (I need to add a lot to it), not clean, and highly repetitive - in other words all around newbie. It is meant to work with the au3 exe that comes with AutoIt. It almost does what I need it to do. This is the code that generates the file that is the problem:

CODE
#include <ButtonConstants.au3>

#include <ComboConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Include <string.au3>; need to add this one

#Include <Date.au3>;need to add this one too

#Region ### START Koda GUI section ### Form=c:\documents and settings\rc01712\desktop\scriptrunner1.3.2\scrubber_form.kxf

$Form1_1 = GUICreate("AU3 Recorder Scrub", 679, 491, 183, 125)

$record = GUICtrlCreateButton("Launch Au3Record.exe", 24, 64, 145, 33, 0)

$scrub = GUICtrlCreateButton("Scrub", 24, 408, 65, 49, 0)

$save = GUICtrlCreateButton("Save", 200, 408, 65, 49, 0)

$editControl= GUICtrlCreateEdit("", 272, 80, 377, 377)

$clear = GUICtrlCreateButton("Clear", 112, 408, 65, 49, 0)

$delaysGroup = GUICtrlCreateGroup("Add Delays After:", 24, 104, 241, 105)

$delayInput=GUICtrlCreateInput("", 133, 177, 97, 21)

$Label1 = GUICtrlCreateLabel("Delay to add (in milsecs):", 133, 137, 121, 17)

$mouseMoveCB = GUICtrlCreateCheckbox("MouseMove", 37, 129, 81, 25)

$mouseDownCB = GUICtrlCreateCheckbox("MouseDown", 37, 153, 81, 25)

$mouseUpCB = GUICtrlCreateCheckbox("MouseUp", 37, 177, 81, 25)

$Label2 = GUICtrlCreateLabel("(1000 = 1 second)", 133, 153, 90, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$optionsGroup = GUICtrlCreateGroup("Set Options", 24, 224, 241, 73)

$winTitleMatchLabel = GUICtrlCreateLabel("WinTitleMatch Mode:", 32, 240, 106, 17)

$SELECT_MODE = GUICtrlCreateCombo("SELECT_MODE", 144, 232, 113, 25)

GUICtrlSetData(-1, "From Start|Any Substring|Exact Match|Advanced")

$Checkbox1 = GUICtrlCreateCheckbox("Add Window Timeout", 32, 256, 121, 25)

$windowsTimeout = GUICtrlCreateInput("", 160, 256, 97, 21)

GUICtrlSetState(-1, $GUI_SHOW)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$groupLogic = GUICtrlCreateGroup("Logic Builder", 24, 312, 241, 81)

$logicLabel = GUICtrlCreateLabel("IF window timeout THEN:", 32, 336, 125, 17)

$CHOOSE_LOGIC_RESULT = GUICtrlCreateCombo("CHOOSE_LOGIC_RESULT", 32, 360, 225, 25)

GUICtrlSetData(-1, "Stop script (exit)|If in loop, skip to next item|custom (freehand script)")

GUICtrlCreateGroup("", -99, -99, 1, 1)

$help = GUICtrlCreateButton("help", 200, 64, 57, 33, 0)

$editBoxLabel = GUICtrlCreateLabel("Script from AU3 recorder", 360, 48, 180, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

dim $Ttl = "AU3Record 3.1 - ( Made for AutoIt v3 )";window for au3 recorder

dim $Timeout = 5;timout used to insert into winwait and winactive lines

dim $Txt = ""

dim $au3Text = WinGetText($Ttl) ; gets text from au3Recorder

$au3Text=StringTrimLeft($au3Text,132);trims out other text from the window

dim $scrubDelay ;used for mousedowm,up,and move delays

dim $winTo ;used for windows timeout feature

dim $variables

func _addSleeps($scrubDelay);not presently used by GUI

$scrubDelay = guictrlread($delayInput)

;dim $au3Text = WinGetText($Ttl)

$au3Text=StringTrimLeft($au3Text,132)

if $au3Text="" then

MsgBox("","ERROR!","You have not recorded anything yet")

else

WinWait($Ttl, $Txt, 1)

If Not WinActive($Ttl, $Txt) Then WinActivate($Ttl, $Txt)

dim $errorHandle = WinWaitActive($Ttl, $Txt, 1)

if $errorHandle =0 then

MsgBox("","ERROR!","You don't have the recorder open")

else

local $textToInsert = @CRLF&"sleep("&$scrubDelay&")"&@CRLF

$au3Text = StringReplace($au3Text,@CRLF,$textToInsert,0,0)

GUICtrlSetData($editControl,$au3Text)

EndIf

EndIf

;Return $au3Text

EndFunc

func _addMouseDownSleeps($scrubDelay)

$scrubDelay = guictrlread($delayInput)

local $num = 1

local $substring = "MouseDown"

do

local $substringPosition = StringInStr($au3Text,$substring,"",$num)

local $occurence = StringInStr($au3Text,@CRLF,"",1,$substringPosition)

$au3Text = _stringInsert($au3Text,"sleep("&$scrubDelay&")",$occurence)

$num +=1

until $substringPosition=0

local $trimLength = StringLen($scrubDelay)+7

$au3Text=StringTrimLeft($au3Text,$trimLength)

GUICtrlSetData($editControl,$au3Text)

EndFunc

func _addMouseUpSleeps($scrubDelay)

$scrubDelay = guictrlread($delayInput)

local $substring2 = "MouseUp"

local $num2 = 1

do

local $substringPosition2 = StringInStr($au3Text,$substring2,"",$num2)

local $occurence2 = StringInStr($au3Text,@CRLF,"",1,$substringPosition2)

$au3Text = _stringInsert($au3Text,"sleep("&$scrubDelay&")",$occurence2)

$num2 +=1

until $substringPosition2=0

local $trimLength = StringLen($scrubDelay)+7

$au3Text=StringTrimLeft($au3Text,$trimLength)

GUICtrlSetData($editControl,$au3Text)

EndFunc

func _addMouseMoveSleeps($scrubDelay)

$scrubDelay = guictrlread($delayInput)

local $substring3 = "MouseMove"

local $num3 = 1

do

local $substringPosition3 = StringInStr($au3Text,$substring3,"",$num3)

local $occurence3 = StringInStr($au3Text,@CRLF,"",1,$substringPosition3)

$au3Text = _stringInsert($au3Text,"sleep("&$scrubDelay&")",$occurence3)

$num3 +=1

until $substringPosition3=0

local $trimLength = StringLen($scrubDelay)+7

$au3Text=StringTrimLeft($au3Text,$trimLength)

;$au3Text= stringtrimleft($au3Text,10)

GUICtrlSetData($editControl,$au3Text)

EndFunc

func _saveScript($au3Text)

local $saveLocation =FileSaveDialog("Save Script Runner Script",@ScriptDir&"\scripts\","AU3(*.au3)")

If @error Then

MsgBox(4096,"","Save cancelled.")

else

local $locationStringSize = StringLen(@WorkingDir)+1

local $fileName = StringTrimleft($saveLocation,$locationStringSize)&".au3"

;local $fileNameHandle = FileOpen($fileName,2)

FileWriteLine($fileName,$au3Text)

FileClose ($fileName)

;FileWrite($fileNameHandle,guictrlread($editControl))

;FileClose ($fileNameHandle)

EndIf

EndFunc

func _addDelayToWinwait($winTo)

$substring = "WinWait("

local $num = 1

do

local $substringPosition = StringInStr($au3Text,$substring,"",$num)

;Msgbox("","This is the substring position",$substringPosition)

local $occurence = StringInStr($au3Text,@CRLF,"",1,$substringPosition)

;MsgBox("","This is the first occurence of the @crlf after winwait:","Substring location: " & $occurence)

local $endParens = StringInStr($au3Text,")","",1,($occurence-5))

;MsgBox("","This is the last close parens after winwait:","location: " & $endParens)

$au3Text = _stringInsert($au3Text,","&$winTO,($endParens-1))

;MsgBox("","This is the new string with the delay",$au3Text)

$num +=1

until $substringPosition=0

local $trimLength = StringLen($winTo)+2

$au3Text=StringTrimRight($au3Text,$trimLength)

GUICtrlSetData($editControl,$au3Text)

return $au3Text

EndFunc

func _addDelayAndVarToWinWaitActive($winTO)

If guictrlread($CHOOSE_LOGIC_RESULT) = 'custom (freehand script)' Then;this just kills it if custom is selected since can't do that yet

return 0

EndIf

$variables = 1

do

local $winWaitActivePos = StringInStr($au3Text,"WinWaitActive(","",$variables)

;MsgBox("","This is the position of the string we are searching in this loop",$winWaitActivePos)

local $textToInsert = "dim $var"&$variables&" = "

local $delayToInsert = ","&$winTO

;MsgBox("","This is the text we will insert",$textToInsert)

$au3Text = _stringInsert($au3Text,$textToInsert,($winWaitActivePos-1))

local $endOfWinWaitActivePos = StringInStr($au3Text,@CRLF,"",1,$winWaitActivePos)

local $endParens =StringInStr($au3Text,")","",1,($endOfWinWaitActivePos))

$au3Text = _StringInsert($au3Text,$delayToInsert,$endOfWinWaitActivePos-2)

;$au3Text = _StringInsert($au3Text,@crlf,$endOfWinWaitActivePos+1)

$variables +=1

until $winWaitActivePos=0

local $trimSize = StringLen($textToInsert) + (StringLen($delayToInsert)+1)

$au3Text=StringTrimRight($au3Text,$trimSize)

GUICtrlSetData($editControl,$au3Text)

return $variables

EndFunc

;($CHOOSE_LOGIC_RESULT) = 'Stop script (exit)' or guictrlread($CHOOSE_LOGIC_RESULT) = 'If in loop, skip to next item' or guictrlread($CHOOSE_LOGIC_RESULT) ='custom (freehand script)' then

func _handleTimeOut($variables)

local $substring4 = "dim"

local $num4 = 1

local $counter=1

dim $a

dim $handleTOInsert; = 'if $var'&$counter&'=0 then'&@CRLF&'msgbox("","Error","window not found")'&@CRLF&"EndIf"

do

$handleTOInsert = 'if $var'&$counter&'=0 then'&@CRLF&'_logError()'&@CRLF&"EndIf"

if guictrlread($CHOOSE_LOGIC_RESULT) = 'Stop script (exit)' Then

$handleTOInsert = 'if $var'&$counter&'=0 then'&@CRLF&'_logError()'&@crlf&"EndIf";returns error code of 1 upon exit (means window not found)

ElseIf guictrlread($CHOOSE_LOGIC_RESULT) = 'custom (freehand script)' Then

MsgBox("","Custom module selected during scrub","custom module coming soon!")

$handleTOInsert=""

return 0

EndIf

local $substringPosition4 = StringInStr($au3Text,$substring4,"",$num4)

;MsgBox("","This is the position of dim",$substringPosition4)

local $occurence4 = StringInStr($au3Text,@CRLF,"",1,$substringPosition4)

$au3Text = _stringInsert($au3Text,$handleTOInsert,$occurence4)

$num4 +=1

$counter+=1

until $substringPosition4=0

local $lengthOfInsert = StringLen($handleTOInsert)

$au3Text=StringTrimLeft($au3Text,$lengthOfInsert)

$au3Text=$au3Text

GUICtrlSetData($editControl,$au3Text)

return $au3Text

EndFunc

Func _setOptions($au3Text)

;MsgBox("","","Set options activated")

local $modeOption = GUICtrlRead($SELECT_MODE)

;MsgBox("","This is what has been selected",$modeOption)

local $winMatchString = 'Opt("WinTitleMatchMode",4)'

;MsgBox("","match string is",$winMatchString)

local $winMatch1 = 'Opt("WinTitleMatchMode",1)'

local $winMatch2 = 'Opt("WinTitleMatchMode",2)'

local $winMatch3 = 'Opt("WinTitleMatchMode",3)'

local $winMatch4 = 'Opt("WinTitleMatchMode",4)'

local $lookForOption = StringInStr($au3Text,$winMatchString)

;MsgBox("","Look for option is",$lookForOption)

if $lookForOption > 0 Then

if $modeOption = "From Start" then

$au3Text=StringReplace($au3Text,$winMatchString,$winMatch1)

GUICtrlSetData($editControl,$au3Text)

elseif $modeOption = "Any Substring" then

$au3Text=StringReplace($au3Text,$winMatchString,$winMatch2)

GUICtrlSetData($editControl,$au3Text)

elseif $modeOption = "Exact Match" then

$au3Text=StringReplace($au3Text,$winMatchString,$winMatch3)

GUICtrlSetData($editControl,$au3Text)

EndIf

EndIf

Return $au3Text

EndFunc

func _insertErrorLogFunction()

dim $errorFuncInsert = @crlf&'func _logError()'&@crlf&'local $textToSend = "failure"'&@CRLF&'local $msgHandle = ControlGetHandle("Receiver","","[CLASS:Static; INSTANCE:1]")'&@crlf&'ControlSetText("Receiver","",$msgHandle,$textToSend)'&@CRLF&'dim $errorLog = FileOpen ( "ScriptRunner Error Log.txt",1)'&@crlf&'dim $errorMessage = "Error during scriptrunner useage."'&'&'&'@crlf'&'&'&'"Window not found in "'&'&'&"@ScriptName"&'&'&'" script"'&@CRLF&'dim $sysTime =_Date_Time_GetSystemTime()'&@crlf&'dim $timeStamp =_Date_Time_SystemTimeToDateTimeStr($sysTime)'&@crlf&'FileWrite("ScriptRunner Error Log.txt",$timeStamp)'&@CRLF&'FileWrite("ScriptRunner Error Log.txt",$errorMessage)'&@crlf&'FileClose($errorLog)'&@crlf&"Exit"&@crlf&'EndFunc'

$au3Text=_StringInsert($au3Text, $errorFuncInsert, -1)

dim $includeInsert = '#Include "..\resources\1Date.au3"'&@CRLF

$au3Text=_StringInsert($au3Text, $includeInsert, 0)

GUICtrlSetData($editControl,$au3Text)

EndFunc

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

case $record

ShellExecute(@ScriptDir&"\AU3Record.exe")

Case $scrub

dim $au3Text = WinGetText($Ttl)

$au3Text=StringTrimLeft($au3Text,132)

$scrubDelay = guictrlread($delayInput)

if (guictrlread($delayInput)="" AND GUICtrlRead($mouseDownCB) = $GUI_CHECKED) or (guictrlread($delayInput)="" AND GUICtrlRead($mouseUpCB) = $GUI_CHECKED) or (guictrlread($delayInput)="" and GUICtrlRead($mouseMoveCB) = $GUI_CHECKED) Then

MsgBox("","Error, must input delay","Please select a delay time")

else

if GUICtrlRead($mouseDownCB) = $GUI_CHECKED then

_addMouseDownSleeps($scrubDelay)

EndIf

if GUICtrlRead($mouseUpCB) = $GUI_CHECKED then

_addMouseUpSleeps($scrubDelay)

EndIf

if GUICtrlRead($mouseMoveCB) = $GUI_CHECKED then

_addMouseMoveSleeps($scrubDelay)

EndIf

EndIf

$winTO = guictrlread($windowsTimeout)

$winTo = round(($winTO/1000),0)

if GUICtrlRead($Checkbox1) = $GUI_CHECKED then

_addDelayToWinwait($winTo)

EndIf

if guictrlread($CHOOSE_LOGIC_RESULT) = 'Stop script (exit)' or guictrlread($CHOOSE_LOGIC_RESULT) = 'If in loop, skip to next item' or guictrlread($CHOOSE_LOGIC_RESULT) ='custom (freehand script)' then

_addDelayAndVarToWinWaitActive($winTO)

EndIf

_handleTimeOut($variables)

_insertErrorLogFunction()

_setOptions($au3Text)

Case $clear

GUICtrlSetData($editControl,"")

case $save

_saveScript($au3Text)

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

Enter the problem: The file that I create appears to be 100% fine. However, a strange "illegal character" always comes up at the end of a line - not always the same line (depends on options selected in the GUI), but always at the end after a close parens (will be the same location if options are the same). I thought @CRLF or @CR so I tried to replace them in the string etc. No help. I checked my fileWrite() was using name/name not name/handle - no help.

Here is the weird part: make a copy of this file (attached) in Scite and the copy works. Rename the file - and it does not work. Paste it into Notepad then into Scite from Notepad - does not work. HELP!!! I am attaching the end product of my convoluted script in the hopes that somebody can tell me what the illegal character is so I can figure out a way to zap it. Any help would be greatly appreciated.

As a special prize you will get a thank you in my source code (just kidding - that would probably be more of a punishment).

Thanks in advance for any help you could offer.

JFish

bugFromYouKnowWhere1.au3


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Spiff59

I get those error sometimes when an attempt at execution fails due to syntax.

There's always a preceding error that once resolved causes the "illegal character" complaint to disappear.

I don't think you can always trust the errors displayed beyond the first one.

Have you been ignoring an earlier error in the script as an "I know what that is, I'll fix it later" ?

Edited by Spiff59

Share this post


Link to post
Share on other sites
Jfish

I get those error sometimes when an attempt at execution fails due to syntax.

There's always a preceding error that once resolved causes the "illegal character" complaint to disappear.

I don't think you can always trust the errors displayed beyond the first one.

Have you been ignoring an earlier error in the script as an "I know what that is, I'll fix it later" ?

Good thought but not as far as I can tell. That is the first error that Scite shows. Also, when you compile, if you ignore errors, it works as an exe. In addition, if you delete the CR at the end of the line that says there is an error and then hit "enter" (i.e. put the CR back in) it works. Also, an exact copy works fine with no syntax errors.

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Spiff59

I downloaded your generated script, scanned it quickly for anything akin to "Format C:" <wink> then pounded F5.

Blew with a notfind on your custom include in line 1, and the only other error was at line 12, column 48, the "ERROR: syntax error (illegal character)" you mentioned. I cleared up the include to "#Include<date.au3>" and the script ran fine.

Share this post


Link to post
Share on other sites
Jfish

I downloaded your generated script, scanned it quickly for anything akin to "Format C:" <wink> then pounded F5.

Blew with a notfind on your custom include in line 1, and the only other error was at line 12, column 48, the "ERROR: syntax error (illegal character)" you mentioned. I cleared up the include to "#Include<date.au3>" and the script ran fine.

Well, here is a bit of weirdness.... I tried commenting out that line ";" and then I hit syntax check - and got an error. I removed the semicolon and did it again - no error. Do you think that could be related to what you saw in your scan? The reference to the include seems to be legit (on my machine - because it works with those functions) - and you can fix it on line 12 column 48 by hitting delete and then enter. Thoughts?

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Spiff59

Interesting...

But I have something for you.

I'm guessing some of the wierdness results from the fact that SciTE resaves your source every time you hit F5 to execute it.

I had to redownload your generated script to get it in a pristine state.

I loaded it up in WinHex and sure enough...

Every line is terminated with an 0D0A (CRLF) combination, except for line 12.

It ends with 0D 0D 0A.

EDIT: So, the script as initially generated, does have a bogus byte, but it apparently gets discarded after a save or two. Looks like you have to chase down where the extra carriage-return is coming from. You're not treating the 2-character CRLF as a single-byte anywhere are you? (Without indentation, your main script is too tough for me to read)

Edited by Spiff59

Share this post


Link to post
Share on other sites
Jfish

Interesting...

But I have something for you.

I'm guessing some of the wierdness results from the fact that SciTE resaves your source every time you hit F5 to execute it.

I had to redownload your generated script to get it in a pristine state.

I loaded it up in WinHex and sure enough...

Every line is terminated with an 0D0A (CRLF) combination, except for line 12.

It ends with 0D 0D 0A.

EDIT: So, the script as initially generated, does have a bogus byte, but it apparently gets discarded after a save or two. Looks like you have to chase down where the extra carriage-return is coming from. You're not treating the 2-character CRLF as a single-byte anywhere are you? (Without indentation, your main script is too tough for me to read)

That is interesting - and by the way, thanks very much for trying to help me figure this out. At first, I was using fiewrite() and got the same error and switched to filewriteline() to see if I could clear it up. It is hard for me to find the exact spot of the added characters because if I run the app that generate the script and don't select the last drop down - but do add a delay - it will cause the error to appear on a completely differnt line ... one that I did not alter using the script. And, it will also appear at the end just as this one has done. I am not familiar enough with hex editors but it looks like it is adding {SPACE}{CR}{SPACE} in the middle of the CRLF. Is that an accurate read from your post? That info may help me zero in on it.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Jfish

One more note to add to all this ... when I ShellWaitExecute("AutoIt3.exe","problemScript.au3") it works fine. Open that script up in Scite without altering it and it will say you have a syntax error. Alter it any number of ways that don't seem to be connected, check it again, and it will say it is fine.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

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
Sign in to follow this  

×