Jump to content

Send Varables with spaces


Recommended Posts

I have some code cobbled together from various examples on the internet. The code reads a file names from a text input file - it then fills out the form using the lines from the text file. works great until it finds a filename with a space. I know you have to send spaces using the send("{SPACE}") command, but I need to get the code to automatically decide when the variable has a space and deal with it.

here is my code so far:

 

#include <Constants.au3>
#include <AutoItConstants.au3>
#include <ImageSearch2015.au3>
#include <MsgBoxConstants.au3>
#include <DateTimeConstants.au3>
#include <Date.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
HotKeySet("{ESC}","HotKeyPressed")


Local $mydate = InputBox("Question", "what is start date? ", "18/03/2020", "", _
             - 1, -1, 0, 0)
Local $mystarttime = InputBox("Question", "what is start time? ", "14:00:00", "", _
             - 1, -1, 0, 0)

Local $myenddate = InputBox("Question", "what is end date? ", "23/03/2020", "", _
             - 1, -1, 0, 0)

Local $myendtime = InputBox("Question", "what is finish time? ", "17:00:00", "", _
             - 1, -1, 0, 0)



$mydate = $mydate  & "{SPACE}" & $mystarttime
$myenddate = $myenddate  & "{SPACE}" & $myendtime

$ID=''
$out=''
global $mpos=MouseGetPos()
Opt("WinTitleMatchMode",2)
#Global $g_bPaused = False


#*** REMEBER: Set display font to 300% screen res to 100%***
local $strings=""

$strings = "Filepath"  & "{SPACE}" & "{-}"
Global $iX = 0, $iY = 0, $iSearch = 0
Global $SGx = 0, $SGy = 0, $hWnd, $t, $e

#handle the files

# filename to read
$file_to_read = "c:\input\changerequestinput.txt"
# open file to read and store the handle
$handle_read = FileOpen($file_to_read, 0)
# check the handle is valid
If $handle_read = -1 Then
    # show warning and exit with code 1
    MsgBox(0, @ScriptName, 'failed to open handle to read the file')
    Exit 1
EndIf

# filename to write
$file_to_write = "c:\input\changerequestoutput.txt"
# open file to read and store the handle
$handle_write = FileOpen($file_to_write, 2); erase mode
# check the handle is valid
If $handle_write = -1 Then
    # close read handle here as write handle is invalid
    FileClose($handle_read)
    # show warning and exit with code 2
    MsgBox(0, @ScriptName, 'failed to open handle to read the file')
    Exit 2
EndIf

#start the code

#--------------------------------------------------------------------------------------------------------------------------

 #loop through each line of the file
While 1
    # read each line from a file
    $line_read = FileReadLine($handle_read)

#set the text for the comments fields
#change request has been opened now we need to populate the fileds and grabd the ID

WinActivate("Find Knowledge | ServiceNow Production ‎- Microsoft Edge","")

ToolTip('                                                  "looking for ID | ESC=STOP"', 0, 0)

   Do
   sleep(100)
  $iSearch = _ImageSearchArea("id.png", 1,488,256,582,285, $iX, $iY, 50, 0)
      If $iSearch <> 1 Then Sleep(100)
      Until $iSearch = 1


   If $iSearch = 1 Then
      Sleep(500)
      MouseClick("left",($iX+60),$iY,1,1)
       MouseClick("left",($iX+60),$iY,1,2)
      sleep(500)
      Send("^c") ;Copy selected text.
      sleep(500)
      $ID=ClipGet() ;Retrieves text from clipboard.
      MsgBox(0, 'id', $ID)
   endif

ToolTip('                                                  "FormFill | ESC=STOP"', 0, 0)

WinActivate("Find Knowledge | ServiceNow Production ‎- Microsoft Edge","")
MouseClick("left",620,584,1,1)
   Sleep(500)
   #send($mydate & "{SPACE}" & $mystarttime)
   send($mydate)
   Sleep(500)
   #MouseClick("left",628,623,1,1)
   #send($myenddate & "{SPACE}" & $myendtime)
   send("{TAB}")
   Sleep(500)
   send($myenddate)
   Sleep(500)
   #MouseClick("left",1398,743,1,1)
   send("{TAB}")
   Sleep(500)
   send("{TAB}")
   Sleep(500)
   send("{TAB}")
   Sleep(500)
   send("{TAB}")
   Sleep(500)
   send("{TAB}")
   Sleep(500)
   send("{TAB}")
   Sleep(500)
   send("{TAB}")
   Sleep(500)
   send("{TAB}")
   Sleep(500)
   send("lewis" & "{SPACE}" & "Ward")
   Sleep(500)
   #MouseClick("left",1416,148,1,1)

   #MouseClick("left",1265,260,1,1)
   #sleep(1000)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
send("{TAB}")
Sleep(500)
Send($strings & "{SPACE}" & $line_read)

 MsgBox(0, 'press to continue', "")

   
WEnd


Func StopScript()
   exit
EndFunc


Func HotKeyPressed()
    Switch @HotKeyPressed ; The last hotkey pressed.
        #Case "{ESC}" ; String is the {space} hotkey.
         #   $g_bPaused = Not $g_bPaused
          #  While $g_bPaused
           #     Sleep(100)
            #    ToolTip('Script is "paused"', 0, 0)
            #WEnd
            #ToolTip("")


   #Case "{ }" #String is the {space} hotkey.
             #StopScript()


        Case "{ESC}" ; String is the {ESC} hotkey.
     StopScript()


    EndSwitch
EndFunc   #==>HotKeyPressed

 

Edited by JLogan3o13
Link to comment
Share on other sites

  • Moderators

@Loobyloo welcome to the forum. Please see the post below on how to post code, to make it easily readable. I have done if for you above as an example.

 

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

2 hours ago, Loobyloo said:

have to send spaces using the send("{SPACE}") command, but I need to get the code to automatically decide when the variable has a space and deal with it.

about $sString = StringReplace($sString, " ", "{space}") , would that work ?

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

3 hours ago, argumentum said:

about $sString = StringReplace($sString, " ", "{space}") , would that work ?

Thanks for looking at this so quickly, it almost worked , but it added the word space to my result, so I tried with single quotes but still didn't work

$newstring = StringReplace($line_read, " ", '"{space}"')

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...