Jump to content

gazzer82

Members
  • Posts

    6
  • Joined

  • Last visited

gazzer82's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. I have been working on my first AutoIt application, it is a background process that watches for changes to a file, if it detects a change it informs the user, parses the data, and outputs the data as keystrokes to a specific application. This seems to be working ok, the bit i am struggling with is how to quit the application. It has no GUI and should run in the background/system tray at all times, however i may need to manually quit it on occasion. I have tried the right-click exit on the icon in the dock but that doesn't work. Any help on this would be greatly appreciated, i have posted the script below. Thanks Gareth #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=Builds\Barcode Watcher Beta 1.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <array.au3> #include <file.au3> ;Setup the Variables Global $sFile = "C:\Barcode_Data\Data1.txt" Global $aLineArray[1], $aSecond[1], $aThird[1], $aThirdstripped[1], $aSplit[1], $aBarcode, $aQuantity, $ProcessName = "hirepnt.exe", $nFirstlook ;Setup WMI Event for File Watching $nFirstlook = 1 $file = "C:\Barcode_Data\Data2.txt" $sComputer = @ComputerName $oWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $sComputer & "\root\cimv2") $colMonitoredEvents = $oWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE " _ & "TargetInstance ISA 'CIM_DataFile' AND " _ & "TargetInstance.Name='" & StringReplace($file, '\', '\\') & "'") ;Start watching the files While 1 ; Reset timer to zero $time = TimerInit() ; Monitor file for event $oLatestEvent = $colMonitoredEvents.NextEvent ; Output if event older then 5 minutes If TimerDiff($time) > (3000) Then ; If this is the first loop then ignore the file change If $nFirstlook = 1 Then $nFirstlook = 0 ;Otherwise continue with the script Else ;Ask if we would like to read the barcode data and continue If MsgBox(4096+4, "Barcodes Detected", "Would you like to input Barcode Data?", 10) = 6 Then ;Check to see if the process we are targetting is running If ProcessExists($ProcessName) Then ;Read the File into an array _FileReadToArray($sFile, $aLineArray) If @error = 0 Then ;_ArrayDisplay($aLineArray, "Debug: Read File To Array") Else MsgBox(16, "Error", "Error reading file: " & $sFile) Exit EndIf ; Set array sizes to match data ReDim $aSecond[$aLineArray[0] + 1] ; Make array size match $aSecond[0] = $aLineArray[0] ReDim $aThird[$aLineArray[0] + 1] ; Make array size match $aThird[0] = $aLineArray[0] ReDim $aThirdstripped[$aLineArray[0] + 1] ; Make array size match $aThirdstripped[0] = $aLineArray[0] For $n = 1 To $aLineArray[0] ;Split each line of the file into an array $aSplit = StringSplit($aLineArray[$n], ",") ;Put parts in arrays If IsArray($aSplit) And $aSplit[0] >= 2 Then $aSecond[$n] = $aSplit[1] if $aSplit[2] = " " then $aThird[$n] = "1 " else $aThird[$n] = $aSplit[2] EndIf EndIf Next ;Remove trailing spaces on numbers For $n4 = 1 to $aThird[0] $aThirdstripped[$n4] = StringStripWS ($aThird[$n4], 2); strip trailing whitespace Next ;Display the arrays for debugging purposes ;_ArrayDisplay($aSecond, "Debug: $aSecond") ;_ArrayDisplay($aThirdstripped, "Debug: $aThird") ;Check to see if Rentalpoint is active, if not make it so If Not WinActive("Check out","") Then WinActivate("Check out","") ;If Not WinActive("Untitled","") Then WinActivate("Untitled","") ;Print the Barcodes out the quaitity of times indicated in the quanity array For $n2 = 1 To $aLineArray[0] $aBarcode = $aSecond[$n2] $aQuantity = $aThirdstripped[$n2] $n3 = 0 While $n3 < $aThirdstripped[$n2] $n3 += 1 Send ($aBarcode) sleep (100) WEnd Next MsgBox(0,"All Done","Data Input Complete") Else MsgBox(0,"Not Running",$ProcessName & " is not running.") EndIf EndIf EndIf EndIf WEnd
  2. Hi, Thanks for that, actually Notepad is just a testing app, the send() will eventually go to our rental system, it only accepts keystrokes as in input method so i don't think writing to a file is going to work. Loosing window focus i don't think will be a problem as this script will be run in specific situations when booking out a job. Could you explain why i am getting the error i mentioned above in my script, as far as i can tell the syntax for writing the array variable into the string variable is correct, but i keep getting the error. Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded. Here is the script as it stands. #include <array.au3> #include <file.au3> Global $sFile = "C:\Barcode_Data\Data1.txt" Global $aLineArray[1], $aSecond[1], $aThird[1], $aSplit[1], $sBarcode, $sQuantity ;Read the File into an array _FileReadToArray($sFile, $aLineArray) If @error = 0 Then ;_ArrayDisplay($aLineArray, "Debug: Read File To Array") Else MsgBox(16, "Error", "Error reading file: " & $sFile) Exit EndIf ReDim $aSecond[$aLineArray[0] + 1] ; Make array size match $aSecond[0] = $aLineArray[0] ReDim $aThird[$aLineArray[0] + 1] ; Make array size match $aThird[0] = $aLineArray[0] For $n = 1 To $aLineArray[0] ;Split each line of the file into an array $aSplit = StringSplit($aLineArray[$n], ",") ; Put parts in arrays If IsArray($aSplit) And $aSplit[0] >= 2 Then $aSecond[$n] = $aSplit[1] if $aSplit[2] = " " then $aThird[$n] = "100" else $aThird[$n] = $aSplit[2] EndIf EndIf Next ;_ArrayDisplay($aSecond, "Debug: $aSecond") ;_ArrayDisplay($aThird, "Debug: $aThird") If Not WinActive("RentalPoint","") Then WinActivate("RentalPoint","") Thanks Gareth For $n2 = 1 To $aLineArray[0] $sBarcode = $aSecond[$n2] $sQuantity = $aThird[$n2] Send ($sBarcode[1]) Send ($sQuantity[1]) Next Exit
  3. Ok thanks, it seems to be ok with the sample data i am using, now onto the next problem (would it be better if i started a new thread?) i am trying to print the list to screen, i have tried using the following code but i am getting the same error message as previously again. I know i am probably doing something very obviously wrong but i just can't work it out. #include <array.au3> #include <file.au3> Global $sFile = "C:\Barcode_Data\Data1.txt" Global $aLineArray[1], $aSecond[1], $aThird[1], $aSplit[1], $sBarcode, $sQuantity ;Read the File into an array _FileReadToArray($sFile, $aLineArray) If @error = 0 Then ;_ArrayDisplay($aLineArray, "Debug: Read File To Array") Else MsgBox(16, "Error", "Error reading file: " & $sFile) Exit EndIf ReDim $aSecond[$aLineArray[0] + 1] ; Make array size match $aSecond[0] = $aLineArray[0] ReDim $aThird[$aLineArray[0] + 1] ; Make array size match $aThird[0] = $aLineArray[0] For $n = 1 To $aLineArray[0] ;Split each line of the file into an array $aSplit = StringSplit($aLineArray[$n], ",") ; Put parts in arrays If IsArray($aSplit) And $aSplit[0] >= 2 Then $aSecond[$n] = $aSplit[1] if $aSplit[2] = " " then $aThird[$n] = "100" else $aThird[$n] = $aSplit[2] EndIf EndIf Next ;_ArrayDisplay($aSecond, "Debug: $aSecond") ;_ArrayDisplay($aThird, "Debug: $aThird") If Not WinActive("Untitled","") Then WinActivate("Untitled","") For $n = 1 To $aLineArray[0] $sBarcode = $aSecond[$n] $sQuantity = $aThird[$n] Send ($sBarcode[1]) Send ($sQuantity[1]) Next Exit Thanks Gareth
  4. Ah i see, sorry i am very new at this and having issues getting my head around the syntax. That seems to work, i have adjusted the script to look for blank fields and fill them in with a "0" does this look like the best way of doing it? #include <array.au3> #include <file.au3> Global $sFile = "C:\Barcode_Data\Data1.txt" Global $aLineArray[1], $aSecond[1], $aThird[1], $aSplit[1] ;Read the File into an array _FileReadToArray($sFile, $aLineArray) If @error = 0 Then _ArrayDisplay($aLineArray, "Debug: Read File To Array") Else MsgBox(16, "Error", "Error reading file: " & $sFile) Exit EndIf ReDim $aSecond[$aLineArray[0] + 1] ; Make array size match $aSecond[0] = $aLineArray[0] ReDim $aThird[$aLineArray[0] + 1] ; Make array size match $aThird[0] = $aLineArray[0] For $n = 1 To $aLineArray[0] ;Split each line of the file into an array $aSplit = StringSplit($aLineArray[$n], ",") ; Put parts in arrays If IsArray($aSplit) And $aSplit[0] >= 2 Then $aSecond[$n] = $aSplit[1] if $aSplit[2] = " " then $aThird[$n] = "100" else $aThird[$n] = $aSplit[2] EndIf EndIf Next _ArrayDisplay($aSecond, "Debug: $aSecond") _ArrayDisplay($aThird, "Debug: $aThird")
  5. Thanks for your reply, i have been trying to do as you suggested but with little success, i am able to successfully split everything up, but i can't seem to load it into the arrays correctly. I keep getting an error saying "Error = Subscript used with non-Array Variable". Here is what i have so far. #include <array.au3> #include <file.au3> Global $aFirst, $aLineArray, $aSecond, $aThird, $sString, $aSplit, $nCount, $nNunber, $avArray ;Read the File into a String $sString = FileRead("C:\Barcode_Data\Data1.txt") ;Split each line of the string into the array $aFirst = StringSplit(StringStripCR($sString), @LF) For $iCC = 1 To $aFirst[0] ;Split each line of file with delimeter into two arrays If StringInStr($aFirst[$iCC], ",") Then $nCount += 1 $aSplit = StringSplit($aFirst[$iCC], ",") $aSecond[$nCount] = $aSplit[1] $aThird[$nCount] = $aSplit[2] EndIf Next _ArrayDisplay($aSecond, "Barcodes Read") Exit Any help greatly appreciated!! Cheers Gareth
  6. Hi, Sorry to resurrect an old thread. I am completely new to Autoit, and have been trying to modify this script to fit my needs with no success, I am trying to get the script to read a CSV file into two arrays, the file is formatted as such. 22222222, 22222222,1 88888888,1 55555555,10 What i need it to do it read the two fields from each row and place them in an array. But i need it to detect when a field is empty such as in the first row above and insert a 1 by default. I then need to be able to output the numbers on the left using keystrokes the number of time stipulated on the right column. I hope that makes sense, i have spent quite a while playing with this, but i am lacking some of the fundamental knowledge of how to access certain fields in the script as an integer to allow it to be compared in an if statement. If you need any more info then let me know. Thanks in advance. Gareth
×
×
  • Create New...