Jump to content
Reizvoller

FileWriteLine error in expression

Recommended Posts

Reizvoller

Howdy!

I am trying to do something a little whacky but here's the function that's kicking back an error.

I am fairly sure I am overlooking a simple error but I am not seeing it.

Func mouseSpot ()
   Global $mouseSpot = MouseGetPos()
   ConsoleWrite ($mouseSpot[0] & ", " & $mouseSpot[1] & @CRLF)
   FileWriteLine ("mouseGrabs.txt" , "MouseClick ('"'primary'"' , $mouseSpot[0] , $mouseSpot[1], 1, 10)" )
EndFunc

The error displays as this 

Quote

FileWriteLine ("mouseGrabs.txt" , "MouseClick ('"'primary'"' , $mouseSpot[0] , $mouseSpot[1], 1, 10)" )
FileWriteLine ("mouseGrabs.txt" , ^ ERROR

Any thoughts?

Thanks!

-Reiz

Share this post


Link to post
Share on other sites
Reizvoller

Had a moment of "Ah-ha!' and got rid of the quotes around "Primary" , it now writes to the file appropriately but I am still not sure why I am erroring when I have the quotes.

Share this post


Link to post
Share on other sites
Jos

The doublequote between the single quotes will end the literal string started with the double quote before mouseclick.

so this line

"MouseClick ('"'primary'"' , $mouseSpot[0] , $mouseSpot[1], 1, 10)"

is really 3 strings connected together giving the error  
String1: "MouseClick ('"  
String2: 'primary'
String3: "' , $mouseSpot[0] , $mouseSpot[1], 1, 10)"

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Reizvoller

Howdy,

Ahh I see! 

So this is more for future reference than immediate need

If I want to use FileWriteLine and the string I want to write has quotes in it, how do I go about having said quotes be printed? Some languages call for a \ before characters and what-not to designate them to just be written rather than interpreted. 

Thanks!

-Reiz

Share this post


Link to post
Share on other sites
Jos

That is quite easy. You have 2 options when you want to convert this command to a string: 

MouseClick ("primary" , $mouseSpot[0] , $mouseSpot[1], 1, 10)

 Opt1

"MouseClick (""primary"" , $mouseSpot[0] , $mouseSpot[1], 1, 10)"

Opt2

'MouseClick ("primary" , $mouseSpot[0] , $mouseSpot[1], 1, 10)'

The helpfile explains more on how this all works.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Reizvoller

Howdy,

Hmm I did delve into the helpfile, I suppose I missed it. 

Thank you for your replies and time.

-Reiz

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

    • Spartan117
      By Spartan117
      Hi everyone,
      I am wondering if is there any autoit function that make the program ignore errors and move on and resume correct lines?
      Thank you
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a question please
      Can we customize error messages in autoit script?
      I mean internal error messages
      for example
      AutoIt Error
      Line 4  (File "D:\my projects\NVDA Manager\New AutoIt v3
      Script.au3"):
      $script[1] = 1
      $script^ ERROR
      Error: Subscript used on non-accessible variable.
      For example, I want to customize this message
      Is this possible?
      am waiting for your answers
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to make a program that can look at a folder directory, find all the CSV files, and then add the data from CSV's to an array. 
      The problem I seem to be running into is on the 2nd iteration (2nd file) when the script will not create an array. Could someone please help? Thanks in advance
       
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> Global $MasterArray RefineData() Func RefineData() Local $i, $filenum, $file, $csvArray, $sFilePath = @ScriptDir $fileList = _FileListToArrayRec($sFilePath, "*.csv", 1) ;Create and array of all .csv files within folder ;=====Loop through the .csv files within the folder====== For $filenum = 1 To UBound($fileList) - 1 Step 1 $file = $fileList[$filenum] $sFilePath = $sFilePath & "\" & $file ;=====Create array based on csv file===== _FileReadToArray($sFilePath, $csvArray, $FRTA_NOCOUNT, ",") _ArrayDisplay($csvArray,"File: " & $filenum) If $filenum = 1 Then $MasterArray = $csvArray _ArrayDisplay($MasterArray, "Master") Else $MasterArray = _ArrayColInsert($MasterArray, UBound($MasterArray)) ;want column added at end For $i = 0 To UBound($MasterArray)-1 Step 1 $MasterArray[$i][UBound($MasterArray) - 1] = $csvArray[$i][4] Next _ArrayDisplay($MasterArray, "Master") EndIf Next EndFunc ;==>RefineData  
    • ahha
      By ahha
      It took a month of cutting down a big program to find it and here's the code to illustrate "Error allocating memory".
      The first while using the filename in the fileopen, etc. shows the error.  The second while example does not have the problem (so I switched to using it).
      ;shows "Error allocating memory" ;Autoit v3.3.14.5 #AutoIt3Wrapper_run_debug_mode=Y ; use this to debug in console window <--- LOOK #include <FileConstants.au3> ;--- shows error allocating memory - is it Autoit or SciTE ? Try compiling <-- makes no difference so probably not SciTE. Normally error at index 50K-100K $fnINDEX = @ScriptDir & "\__index.txt" $i = 0 ;#cs While 1 $i = $i + 1 FileOpen($fnINDEX, $FO_OVERWRITE) ;overwrite as we just need last one processed FileWriteLine($fnINDEX, $i) FileClose($fnINDEX) If $i/1000 = Int($i/1000) Then MsgBox(0, "count", "$i = " & $i, 1) ;give indication of count, hangs when memory allocation error imminent WEnd ;#ce ;comment out the above loop and this works without an allocation error - looks like the above code leaking memory? While 1 $i = $i + 1 $fh = FileOpen($fnINDEX, $FO_OVERWRITE) ;overwrite as we just need last one processed FileWriteLine($fh, $i) FileClose($fh) If $i/1000 = Int($i/1000) Then MsgBox(0, "count", "$i = " & $i, 1) ;give indication of count WEnd Exit ;program  
    • ur
      By ur
      In the autoit file, if we add multiple libraries (both internal and custom created one)
       
      When we compile the code and run the exe, some time we are getting runtime errors.
      But the line number of error is not showing the exact line number, might be it is including the line number count of libraries also.
      Can you please suggest how to get the exact error line number.
      So, it will be useful for debugging.
×