Jump to content

jlandes

Active Members
  • Posts

    88
  • Joined

  • Last visited

About jlandes

  • Birthday 01/23/1977

Profile Information

  • Location
    Lewistown, Pennsylvania, USA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

jlandes's Achievements

Wayfarer

Wayfarer (2/7)

0

Reputation

  1. Hello all, I've been tasked at work with writing a small application that can call a so-called command file and execute the commands in the file. The first problem that I'm having is that I want to have the ability to add comments and have those comments omitted from the commands to be run. For example, I might setup a file like this: ; This is a comment C:\TEST\COMMAND.EXE ; This is another comment C:\TEST\COMMAND2.EXE ; This is a third comment ; This is a forth comment C:\TEST\COMMAND3.EXE ; This is a fifth comment As you can see, the ; will be used to designate a comment and that can appear at the beginning of a line or anywhere in the middle. The only thing my program should then see is: C:\TEST\COMMAND.EXE C:\TEST\COMMAND2.EXE C:\TEST\COMMAND3.EXE Heres the code that Ive come up with so far: $hFile = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $sLine = FileReadLine($hFile) If @error = -1 Then ExitLoop $iLocation = StringInStr($sLine, ";") If $iLocation > 0 Then $sLine = StringLeft($sLine, $iLocation - 1) EndIf If $sLine <> "" Then MsgBox(0, "Line read:", $sLine) EndIf Wend FileClose($hFile) Whats the best way to do this? The second thing I'd like to do is expand all the AutoIt macros, so that I can type in the command file @ProgramFilesDir or @WindowsDir and that will resolve to the actual directory. How can this be done? Thanks for any help.
  2. I think having the ability to execute applications on remote machines would be a great addition for AutoIt. What does everyone think?
  3. These have been added and submitted to Jon. Let me know if you see any problems. Thanks.Constants.au3
  4. I will add those two constants to the include file. Thanks.
  5. Do you mind if I include these functions of your in File.au3 in the standard library?
  6. Is there an equivalent function in AutoIt to VB's InStrRev() function? I want to conver the following VB code to AutoIt code for inclusion in the standard library: ' Get the filename Function GetFileName(strPath As String) GetFileName = Mid(strPath, InStrRev(strPath, "\") + 1) End Function ' Get the path Function GetFilePath(strPath As String) GetFilePath = Mid(strPath, 1, InStrRev(strPath, "\") - 1) End Function ' Get the file extension Function GetFileExt(strPath As String) GetFileExt = Mid(strPath, InStrRev(strPath, ".")) End Function ' Get the file drive Function GetFileDrive(strPath As String) GetFileDrive = Mid(strPath, 1, InStr(1, strPath, "\") - 1) End Function Any help would be greatly appreciated. Thanks.
  7. @Saunders: I just wanted to say that I think you did a very good job on writing this script. This is exactly the kind of script that will show people the capabilities of AutoIt. Good job!
  8. Hello all, I'm being tasked at work to write a script to automate some pieces to an application we have. The problem I'm having is, there's one piece where you must wait for a progress list to finish. It's much similar to a running log. I don't see any control IDs on any of the controls on the dialog box. In addition, the title bar's text does not change throughout the process. To further make it more complicated, the button that I want to click does not appear on the dialog until the process finishes. I don't see any way to know when the process has finished so that I can click the button to continue the rest of the script. Any ideas on where I might look to get some help on this one? I can provide any information you might need to help me out. Thanks and enjoy your day.
  9. Check out SyncBack. We use it here at work and it seems to work great! I think something like this could be accomplished in AutoIt; however, it would require some good programming knowledge to get it to work right.
  10. Do you mean _ArrayPush() or _ArrayPop() needs modified? You included _ArrayPop() in the code section, but mentioned _ArrayPush() in your description at the bottom of your post.
  11. This doesn't work. When I tried Ceil(2.1), I should have got 3 back, instead I got 2. The previous version that was posted seems to work well. Thanks.
  12. Please feel free to send some of your ideas my way.
  13. I have the following two functions for inclusion in the standard library. However, these functions do not work correctly. If I do _Ceil(2), the function should return 2, but it returns 3. I know why it's happening, but I don't know exactly how _Ceil() and _Floor() are really supposed to work and if there is a standard way of accomplishing these two functions. Can someone let me know what's wrong with them and how to fix it? ;============================================================================= ; ; Function Name: _Ceil() ; Description: Returns the smallest integer greater than or equal to the ; specified value. ; Author(s): Brian Keene <brian_keene@yahoo.com> ; ;============================================================================= Func _Ceil($nValue) If (Not IsNumber($nValue)) Then SetError(1) Return 0 EndIf SetError(0) Return(Int($nValue) + 1) EndFunc ;==> _Ceil() ;============================================================================= ; ; Function Name: _Floor() ; Description: Returns the greatest integer less than or equal to the ; specified value. ; Author(s): Brian Keene <brian_keene@yahoo.com> ; ;============================================================================= Func _Floor($nValue) If (Not IsNumber($nValue)) Then SetError(1) Return 0 EndIf Return(Int($nValue)) EndFunc ;==> _Floor()
  14. Here's what I have for the array functions, please let me know what needs changed: #include-once ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with array management. ; ; ------------------------------------------------------------------------------ #include <Math.au3> ;=============================================================================== ; ; Function Name: _ArrayAdd() ; Description: Adds a specified value at the end of an array, returning the ; adjusted array. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayAdd($avArray, $sValue) Local $avNewArray = $avArray Local $iUpper If IsArray($avArray) Then $iUpper = UBound($avNewArray) $avNewArray = _ArrayInsert($avNewArray, $iUpper) $avNewArray[$iUpper] = $sValue SetError(0) Else Local $avNewArray[1] $avNewArray[0] = $sValue SetError(1) EndIf Return $avNewArray EndFunc ;==> _ArrayAdd() ;=============================================================================== ; ; Function Name: _ArrayBinarySearch() ; Description: Uses the binary search algorithm to search through a ; 1-dimensional array. ; Author(s): Jos van der Zande <jvdzande@yahoo.com> ; ;=============================================================================== Func _ArrayBinarySearch(ByRef $avArray, ByRef $iKey) Local $iLwrLimit = 1 If (Not IsArray($avArray)) Then SetError(1) Return "" EndIf $iUprLimit = UBound($avArray) - 1 $iMidElement = Int(($iUprLimit + $iLwrLimit) / 2) If $avArray[$iLwrLimit] > $iKey Or $avArray[$iUprLimit] < $iKey Then SetError(2) Return "" EndIf While $iLwrLimit <= $iMidElement And $iKey <> $avArray[$iMidElement] If $iKey < $avArray[$iMidElement] Then $iUprLimit = $iMidElement - 1 Else $iLwrLimit = $iMidElement + 1 EndIf $iMidElement = Int(($iUprLimit + $iLwrLimit) / 2) Wend If $iLwrLimit > $iUprLimit Then SetError(3) Return "" Else SetError(0) Return $iMidElement EndIf EndFunc ;==> _ArrayBinarySearch() ;=============================================================================== ; ; Function Name: _ArrayDelete() ; Description: Deletes the specified element from the given array, returning ; the adjusted array. ; Author(s) Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayDelete($avArray, $iElement) Local $iCntr = 0, $iUpper = 0, $iNewSize = 0 If (Not IsArray($avArray)) Then SetError(1) Return "" EndIf ; We have to define this here so that we're sure that $avArray is an array ; before we get it's size. Local $iUpper = UBound($avArray) ; Size of original array ; If the array is only 1 element in size then we can't delete the 1 element. If $iUpper = 1 Then SetError(2) Return "" EndIf Local $avNewArray[$iUpper - 1] If $iElement < 0 Then $iElement = 0 EndIf If $iElement > ($iUpper - 1) Then $iElement = ($iUpper - 1) EndIf If $iElement > 0 Then For $iCntr = 0 To $iElement - 1 $avNewArray[$iCntr] = $avArray[$iCntr] Next EndIf If $iElement < ($iUpper - 1) Then For $iCntr = ($iElement + 1) To ($iUpper - 1) $avNewArray[$iCntr - 1] = $avArray[$iCntr] Next EndIf SetError(0) Return $avNewArray EndFunc ;==> _ArrayDelete() ;=============================================================================== ; ; Function Name: _ArrayDisplay() ; Description: Displays a 1-dimensional array in a message box. ; Author(s): Brian Keene <brian_keene@yahoo.com> ; ;=============================================================================== Func _ArrayDisplay(ByRef $avArray, $sTitle) Local $iCounter = 0, $sMsg = "" If (Not IsArray($avArray)) Then SetError(1) Return 0 EndIf For $iCounter = 0 To UBound($avArray) - 1 $sMsg = $sMsg & "[" & $iCounter & "] = " & StringStripCR($avArray[$iCounter]) & @CR Next MsgBox(4096, "Display Array - " & $sTitle, $sMsg) SetError(0) Return 1 EndFunc ;==> _ArrayDisplay() ;=============================================================================== ; ; Function Name: _ArrayInsert() ; Description: Inserts a blank element into an array, returning the adjusted ; array. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayInsert($avArray, $iElement) Local $iCntr = 0 If (Not IsArray($avArray)) Then Local $avNewArray[1] = $avArray SetError(1) Return $avNewArray EndIf Local $iUpper = UBound($avArray) Local $avNewArray[$iUpper + 1] If ($iElement > $iUpper) Then $iElement = $iUpper EndIf If ($iElement < 0) Then $iElement = 0 EndIf If ($iElement > 0) Then For $iCntr = 0 To ($iElement - 1) $avNewArray[$iCntr] = $avArray[$iCntr] Next EndIf If ($iElement < $iUpper) Then For $iCntr = ($iElement + 1) To UBound($avNewArray) - 1 $avNewArray[$iCntr] = $avArray[$iCntr - 1] Next EndIf SetError(0) Return $avNewArray EndFunc ;==> _ArrayInsert() ;=============================================================================== ; ; Function Name: _ArrayMax() ; Description: Returns the highest value held in an array. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayMax($avArray) If IsArray($avArray) Then Return $avArray[_ArrayMaxIndex($avArray)] Else SetError(1) Return "" EndIf EndFunc ;==> _ArrayMax() ;=============================================================================== ; ; Function Name: _ArrayMaxIndex() ; Description: Returns the index where the highest value occurs in the array. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayMaxIndex($avArray) Local $iCntr, $iMaxIndex = 0 If Not IsArray($avArray) Then SetError(1) Return "" EndIf Local $iUpper = UBound($avArray) For $iCntr = 1 To ($iUpper - 1) If $avArray[$iMaxIndex] < $avArray[$iCntr] Then $iMaxIndex = $iCntr EndIf Next SetError(0) Return $iMaxIndex EndFunc ;==> _ArrayMaxIndex() ;=============================================================================== ; ; Function Name: _ArrayMin() ; Description: Returns the lowest value held in an array. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayMin($avArray) If IsArray($avArray) Then Return $avArray[_ArrayMinIndex($avArray)] Else SetError(1) Return "" EndIf EndFunc ;==> _ArrayMin() ;=============================================================================== ; ; Function Name: _ArrayMinIndex() ; Description: Returns the index where the lowest value occurs in the array. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayMinIndex($avArray) Local $iCntr = 0, $iMinIndex = 0 If Not IsArray($avArray) Then SetError(1) Return "" EndIf Local $iUpper = UBound($avArray) For $iCntr = 1 To ($iUpper - 1) If $avArray[$iMinIndex] > $avArray[$iCntr] Then $iMinIndex = $iCntr EndIf Next SetError(0) Return $iMinIndex EndFunc ;==> _ArrayMinIndex() ;=============================================================================== ; ; Function Name: _ArrayPop() ; Description: Returns the last element of an array, deleting that element ; from the array at the same time. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayPop(ByRef $avArray) If (Not IsArray($avArray)) Then SetError(1) Return "" EndIf ; Save the value in the last element of the array. Local $sLastVal = $avArray[UBound($avArray) - 1] ; Resize the size of the array down by the last element. $avArray = _ArrayDelete($avArray, UBound($avArray) - 1) ; Return the value we saved from the last element of $avArray. SetError(0) Return $sLastVal EndFunc ;==> _ArrayPop() ;=============================================================================== ; ; Function Name: _ArrayPush() ; Description: Adds an element to the end of an array, expanding the array ; to accommodate the extra element. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayPush($avArray, $sNewValue) If (Not IsArray($avArray)) Then SetError(1) Return "" EndIf $avArray = _ArrayAdd($avArray, $sNewValue) SetError(0) Return $avArray EndFunc ;==> _ArrayPush() ;=============================================================================== ; ; Function Name: _ArrayRedim() ; Description: Resizes the given array to the specified new size. ; Author(s): David Nuttall <danuttall@rocketmail.com> ; ;=============================================================================== Func _ArrayRedim(ByRef $avArray, $iNewSize) ; Check parameter validity. Select Case (Not IsArray($avArray)) SetError(1) Return 0 Case (UBound($avArray, 0) > 1) SetError(2) Return 0 Case (Not StringIsInt($iNewSize)) SetError(3) Return 0 Case ($iNewSize < 1) SetError(4) Return 0 EndSelect ; Declare variables. Local $aTmp = $avArray, $iCntr = 0 Dim $avArray[$iNewSize] For $iCntr = 0 To _Min(UBound($aTmp), $iNewSize) - 1 $avArray[$iCntr] = $aTmp[$iCntr] Next For $iCntr = $iCntr To UBound($avArray) - 1 $avArray[$iCntr] = "" Next SetError(0) Return 1 EndFunc ;==> _ArrayRedim() ;=============================================================================== ; ; Function Name: _ArrayReverse() ; Description: Takes the given array and reverses the order in which the ; elements appear in the array. ; Author(s): Brian Keene <brian_keene@yahoo.com> ; ;=============================================================================== Func _ArrayReverse(ByRef $avArray) If (Not IsArray($avArray)) Then SetError(1) Return "" EndIf ; Create a copy of the array. Local $avNewArray = $avArray ; Declare and define variables based on the array. Local $iIndex1, $iIndex2 = UBound($avNewArray) - 1 Local $iMidPoint = $iIndex2 / 2 ; If the array has an odd # of elements then find a slight midpoint. If (Not Int($iMidPoint)) Then $iMidPoint = Round($iMidPoint, 0) EndIf ; Reverse the elements in the array. For $iIndex1 = 0 To UBound($avNewArray) - 1 Step 1 If ($iIndex1 <= $iMidPoint) Then _ArraySwap($avNewArray[$iIndex1], $avNewArray[$iIndex2]) EndIf $iIndex2 = $iIndex2 - 1 Next SetError(0) Return $avNewArray EndFunc ;==> _ArrayReverse() ;=============================================================================== ; ; Function Name: _ArraySwap() ; Description: Swaps two elements of an array. ; Author(s): David Nuttall <danuttall@rocketmail.com> ; ;=============================================================================== Func _ArraySwap(ByRef $svector1, ByRef $svector2) Local $sTemp = $svector1 $svector1 = $svector2 $svector2 = $sTemp SetError(0) EndFunc ;==> _ArraySwap() ;=============================================================================== ; ; Function Name: _ArrayToClip() ; Description: Sends the contents of an array to the clipboard. ; Author(s): Cephas <cephas@clergy.net> ; ;=============================================================================== Func _ArrayToClip($avArray) Local $iCntr, $iRetVal = 0, $sCr = "", $sText = "" If (IsArray($avArray)) Then For $iCntr = 0 To (UBound($avArray) - 1) $iRetVal = 1 If $iCntr > 0 Then $sCr = @CR EndIf $sText = $sText & $sCr & $avArray[$iCntr] Next EndIf ClipPut($sText) Return $iRetVal EndFunc ;==> _ArrayToClip() ;=============================================================================== ; ; Function Name: _ArrayToString() ; Description: Places the elements of an array into a single string, ; separated by the specified delimiter. ; Author(s): Brian Keene <brian_keene@yahoo.com> ; ;=============================================================================== Func _ArrayToString(ByRef $avArray, $iStart, $iEnd, $sDelim) ; Declare local variables. Local $iCntr = 0, $iUBound = 0, $sResult = "" ; If $avArray is an array then set var for efficiency sake. If (IsArray($avArray)) Then $iUBound = UBound($avArray) - 1 EndIf ; Check for parameter validity. Select Case (Not IsArray($avArray)) SetError(1) Return "" Case( ($iUBound + 1) < 2 Or UBound($avArray, 0) > 1) SetError(2) Return "" Case (Not IsInt($iStart)) SetError(3) Return "" Case (Not IsInt($iEnd)) SetError(5) Return "" Case (Not IsString($sDelim)) SetError(7) Return "" Case ($sDelim = "") SetError(8) Return "" Case (StringLen($sDelim) > 1) SetError(9) Return "" Case ($iStart = -1 And $iEnd = -1) $iStart = 0 $iEnd = $iUBound Case ($iStart < 0) SetError(4) Return "" Case ($iEnd < 0) SetError(6) Return "" EndSelect ; Make sure that $iEnd <= to the size of the array. If ($iEnd > $iUBound) Then $iEnd = $iUBound EndIf ; Combine the elements into the string. For $iCntr = $iStart To $iEnd $sResult = $sResult & $avArray[$iCntr] If ($iCntr < $iEnd) Then $sResult = $sResult & $sDelim EndIf Next SetError(0) Return $sResult EndFunc ;==> _ArrayToString()
  15. Sounds to me like the _ArrayRedim() function can be removed from the upcoming revision to the standard library, correct? ;=============================================================================== ; ; Function Name: _ArrayRedim() ; Description: Resizes the given array to the specified new size. ; Author(s): David Nuttall <danuttall@rocketmail.com> ; ;=============================================================================== Func _ArrayRedim(ByRef $avArray, $iNewSize) ; Check parameter validity. Select Case (Not IsArray($avArray)) SetError(1) Return 0 Case (UBound($avArray, 0) > 1) SetError(2) Return 0 Case (Not StringIsInt($iNewSize)) SetError(3) Return 0 Case ($iNewSize < 1) SetError(4) Return 0 EndSelect ; Declare variables. Local $aTmp = $avArray, $iCntr = 0 Dim $avArray[$iNewSize] For $iCntr = 0 To _Min(UBound($aTmp), $iNewSize) - 1 $avArray[$iCntr] = $aTmp[$iCntr] Next For $iCntr = $iCntr To UBound($avArray) - 1 $avArray[$iCntr] = "" Next SetError(0) Return 1 EndFunc ;==> _ArrayRedim() How about _ArrayAdd(), _ArrayInsert(), etc.?
×
×
  • Create New...