Autoit 스니펫
DB CAFE
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
목차
- 1 AutoItWinShow
- 2 AutoItWinGetText
- 3 _DockToWindow
- 4 _FuncExists
- 5 _FunctionSort
- 6 _IsBeta
- 7 _IsButton
- 8 _IsControlID
- 9 _GetAutoItIncludesFromSciTE
- 10 _GetAutoItInstall
- 11 _GetAutoItInstallEx
- 12 _GetAutoItInstallFromSciTE
- 13 _GetClasses
- 14 _GetFile
- 15 _GetTitle
- 16 _GetXML
- 17 Include Source With Exe
- 18 _IsANSIFile
- 19 _IsUnicodeFile
- 20 _IsAu3File
- 21 _IsDefault
- 22 _IsInTrial
- 23 _IsVisible
- 24 Open Help File to Desired Page
- 25 _RunAU3
- 26 Run Any au3 File From Your Program
- 27 _ScriptName
- 28 _ScriptVersion
- 29 _SetFile
- 30 _ShowHelp
- 31 _SingletonPID
- 32 _Sort
- 33 Speak Object and Save to WAV File
- 34 _VariableSwap
- 35 _WinAPI_CharLower
- 36 _WinAPI_CharUpper
- 37 _WinAPI_PathFileExists
- 38 _WinActiveByExe
- 39 _WindowShake
- 40 _WinGetDetails
- 41 _WinGetNumeratedClassList
- 42 _WinGetHandleByPID
- 43 _1Dto2DArray
- 44 _ArrayAddEx
- 45 _ArrayEmpty
- 46 _ArrayGet
- 47 _ArraySet
- 48 _ArrayLength
- 49 _ArraySortNum
- 50 _AssocArray
- 51 _DynEnumArray
- 52 _FuncListToArray
- 53 Identify Duplicate Values In Arrays
- 54 _Is1DArray
- 55 _Is2DArray
- 56 _IsInBounds
- 57 _MultiFileListToArray
- 58 Return Min or Max Number From One or Two Arrays
1 AutoItWinShow[편집]
#include <GUIConstantsEx.au3>
Example()
Func Example()
; Display AutoIt's Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.
AutoItWinShow()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
EndFunc ;==>Example
; Display AutoIt's Hidden Window. Returns the handle of the window.
Func AutoItWinShow()
Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
WinMove($hWnd, '', (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.
WinSetState($hWnd, '', @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I'm displaying it.
Return $hWnd
EndFunc ;==>AutoItWinShow
2 AutoItWinGetText[편집]
Example()
Func Example()
; Display AutoIt's Hidden Window. See AutoItWinGetTitle and AutoItWinSetTitle for more details.
AutoItWinShow()
; Add a text string to AutoIt's Hidden Window. Compile to see the text in AutoIt's Hidden Window.
AutoItWinSetText('Welcome to AutoIt V' & @AutoItVersion & @CRLF)
; Add a text string to AutoIt's Hidden Window. Compile to see the text in AutoIt's Hidden Window.
AutoItWinSetText('Windows Type: ' & @OSType & @CRLF)
; Display the text stored in AutoIt's Hidden Window.
MsgBox(4096, '', AutoItWinGetText())
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
EndFunc ;==>Example
; Retrieve the text in AutoIt's Hidden Window.
Func AutoItWinGetText()
Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
Return ControlGetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1'))
EndFunc ;==>AutoItWinGetText
; Add text to AutoIt's Hidden Window.
Func AutoItWinSetText($sString)
Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
Return ControlSetText($hWnd, "", ControlGetHandle($hWnd, "", 'Edit1'), ControlGetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1')) & $sString)
EndFunc ;==>AutoItWinSetText
; Display AutoIt's Hidden Window. Returns the handle of the window.
Func AutoItWinShow()
Local Const $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
WinMove($hWnd, '', (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set.
WinSetState($hWnd, '', @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I'm displaying it.
Return $hWnd
EndFunc ;==>AutoItWinShow
3 _DockToWindow[편집]
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
If (Not ProcessExists("SciTE.exe")) Then
Exit MsgBox(4096, '', "Please start SciTE.exe")
EndIf
Example()
Func Example()
; Create a GUI, similar to SciTE Jump's GUI.
Local Const $hGUI = GUICreate('', 215, 400, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetState(@SW_SHOWNORMAL, $hGUI)
; Dock the first window to left and adjust the width based on the width of the second GUI.
_DockToWindow(WinGetHandle("[CLASS:SciTEWindow]"), $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete($hGUI)
EndFunc ;==>Example
Func _DockToWindow(Const $hHandle_1, Const $hHandle_2)
; Retrieve the working area, this is minus the taskbar dimensions so slightly different to @DesktopHeight and @DesktopWidth which is the
; monitors height and width.
Local Const $SPI_GETWORKAREA = 48
Local Const $tWorkArea = DllStructCreate($tagRECT)
_WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))
; Retieve the position of the second GUI.
Local Const $aClientSize_2 = WinGetPos($hHandle_2)
; Set the state of the windows to 'Restore'.
WinSetState($hHandle_1, '', @SW_RESTORE)
WinSetState($hHandle_2, '', @SW_RESTORE)
; Move the first to the far left of the screen and adjust the width to the total screen width minus the width of the second GUI. e.g. 1366 - 215
WinMove($hHandle_1, '', DllStructGetData($tWorkArea, 'Left'), DllStructGetData($tWorkArea, 'Top'), DllStructGetData($tWorkArea, 'Right') - DllStructGetData($tWorkArea, 'Left') - $aClientSize_2[2], DllStructGetData($tWorkArea, 'Bottom') - DllStructGetData($tWorkArea, 'Top'))
; Move the second window to the far right in between the remaining space and adjust the height of the GUI.
WinMove($hHandle_2, '', DllStructGetData($tWorkArea, 'Right') - DllStructGetData($tWorkArea, 'Left') - $aClientSize_2[2], DllStructGetData($tWorkArea, 'Top'), $aClientSize_2[2], DllStructGetData($tWorkArea, 'Bottom') - DllStructGetData($tWorkArea, 'Top'))
EndFunc ;==>_DockToWindow
4 _FuncExists[편집]
MsgBox(0, "TEST", "Function Exists = " & _FuncExists("_FuncExists", @ScriptFullPath))
Func _FuncExists($sFunc, $sPath)
If Not FileExists($sPath) Then Return SetError(1)
Local Const $sStr = FileRead($sPath)
Local Const $sRegEx = "(?i)(?m:^|\n)\s*Func\s+(" & $sFunc & ")\s*\("
Local Const $aRegEx = StringRegExp($sStr, $sRegEx, 1)
If IsArray($aRegEx) Then Return 1
Return 0
EndFunc
5 _FunctionSort[편집]
; Get the list of Functions in a script and sort by alphabetical order.
#include <Array.au3>
#include <String.au3>
Local $sFile = FileOpenDialog(@ScriptName, "Select an AutoIt file.", "Au3 (*.au3)")
If @error Then
Exit
EndIf
ClipPut(_FunctionSort($sFile))
Func _FunctionSort($sFilePath)
Local Const $sRead = FileRead($sFilePath)
Local $aReturn = StringRegExp("Func _Count()" & @CRLF & "EndFunc ;==>_Count" & $sRead, '(?s)(?i)Func(.*?)EndFunc', 3)
If @error Then
Return SetError(1, 0, 0)
EndIf
$aReturn[0] = UBound($aReturn, 1) - 1
_ArraySort($aReturn, 0, 1)
Local $sReturn
For $A = 1 To $aReturn[0]
$sReturn &= "Func" & $aReturn[$A] & "EndFunc" & @CRLF & @CRLF
Next
Return $sReturn
EndFunc ;==>_FunctionSort
6 _IsBeta[편집]
#include <Array.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $aTest[10]
_ArrayUnique($aTest, 0, 5)
Local $iError = @error
ConsoleWrite('$iError = ' & $iError & @CRLF)
If _IsBeta() Then
If $iError = 3 Then
MsgBox($MB_SYSTEMMODAL, '@error', '3 - $iBase or $iCase contains an invalid value' & @CRLF & @AutoItVersion)
EndIf
Else
If $iError = 2 Then
MsgBox($MB_SYSTEMMODAL, '@error', '2 - $iBase or $iCase contains an invalid value' & @CRLF & @AutoItVersion)
EndIf
EndIf
EndFunc ;==>Example
Func _IsBeta()
Return Mod(StringSplit(@AutoItVersion, '.')[3], 2) == 1
EndFunc ;==>_IsBeta
7 _IsButton[편집]
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
Example()
Func Example()
Local Const $hGUI = GUICreate('')
Local Const $iLabel = GUICtrlCreateButton('', 0, 0, 50, 50)
Local Const $iCheckbox = GUICtrlCreateCheckbox('', 0, 0, 100, 20) ; This is considered a 'Button' by _WinAPI_GetClassName too.
GUISetState(@SW_SHOWNORMAL, $hGUI)
MsgBox(4096, '', 'AutoIt Button ID: ' & _IsButton($iLabel) & @CRLF & _
'AutoIt Button Handle: ' & _IsButton(GUICtrlGetHandle($iLabel)) & @CRLF & _
'AutoIt Checkbox ID: ' & _IsButton($iCheckbox) & @CRLF & _
'AutoIt Checkbox Handle: ' & _IsButton(GUICtrlGetHandle($iCheckbox)) & @CRLF)
Return GUIDelete($hGUI)
EndFunc ;==>Example
; Check if a variable is referencing a Button control.
Func _IsButton($hWnd)
If IsHWnd($hWnd) = 0 Then
$hWnd = GUICtrlGetHandle($hWnd)
EndIf
Local Const $sClassName = _WinAPI_GetClassName($hWnd)
If $sClassName = 'Button' Then
Local Const $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]
Local Const $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
For $i = 1 To $aStyle[0]
If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then
Return False
EndIf
Next
Return True
EndIf
Return False
EndFunc ;==>_IsButton
8 _IsControlID[편집]
; Check if a Control ID is a native AutoIt control.
#include <GUIListView.au3>
#include <WinAPI.au3>
Example()
Func Example()
Local Const $hGUI = GUICreate('')
Local Const $iControlID = GUICtrlCreateLabel('', 0, 0, 500, 500)
Local Const $hListView = _GUICtrlListView_Create($hGUI, 'Example', 0, 0, 500, 500)
GUISetState(@SW_SHOWNORMAL, $hGUI)
MsgBox(4096, '', 'AutoIt ControlID: ' & _IsControlID($iControlID) & @CRLF & _
'Random Number: ' & _IsControlID(Random(42, 99, 1)) & @CRLF & _
'AutoIt ControlID Handle: ' & _IsControlID(GUICtrlGetHandle($iControlID)) & @CRLF & _
'ListView UDF Handle: ' & _IsControlID($hListView) & @CRLF & _
'ListView UDF Handle: ' & _IsControlID(GUICtrlGetHandle($hListView)) & @CRLF)
_GUICtrlListView_Destroy($hListView)
Return GUIDelete($hGUI)
EndFunc ;==>Example
Func _IsControlID($iControlID)
If IsHWnd($iControlID) Then
$iControlID = _WinAPI_GetDlgCtrlID($iControlID)
EndIf
Return IsHWnd(GUICtrlGetHandle($iControlID)) = 1
EndFunc ;==>_IsControlID
9 _GetAutoItIncludesFromSciTE[편집]
#include <WinAPIEx.au3>
ConsoleWrite(_GetAutoItIncludesFromSciTE() & @CRLF)
; Retrieve the AutoIt includes path from the SciTE process.
Func _GetAutoItIncludesFromSciTE()
Local $sRelativePath = '..\Include'
Local Const $sWorkingDir = @WorkingDir
FileChangeDir(_WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists('SciTE.exe'))))
$sRelativePath = _WinAPI_GetFullPathName($sRelativePath)
FileChangeDir($sWorkingDir)
Return _WinAPI_PathRemoveBackslash($sRelativePath)
EndFunc ;==>_GetAutoItIncludesFromSciTE
10 _GetAutoItInstall[편집]
; Get the AutoIt installation folder.
ConsoleWrite(_GetAutoItInstall() & @CRLF)
Func _GetAutoItInstall()
Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1)
EndFunc ;==>_GetAutoItInstall
11 _GetAutoItInstallEx[편집]
ConsoleWrite(_GetAutoItInstallEx() & @CRLF)
; Get the installation of AutoIt. An improved version of _GetAutoItInstall.
Func _GetAutoItInstallEx()
Local $aWow6432Node[2] = ['', 'Wow6432Node\'], $aFiles[4] = [3, @ProgramFilesDir, EnvGet("PROGRAMFILES"), EnvGet("PROGRAMFILES(X86)")]
Local $sFilePath = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\' & $aWow6432Node[@AutoItX64] & 'AutoIt v3\AutoIt\', 'InstallDir')
If @error Then
For $A = 1 To $aFiles[0]
$aFiles[$A] &= '\AutoIt'
If FileExists($aFiles[$A]) Then
Return $aFiles[$A]
EndIf
Next
Return SetError(1, 0, '')
Else
Return $sFilePath
EndIf
EndFunc ;==>_GetAutoItInstallEx
12 _GetAutoItInstallFromSciTE[편집]
ConsoleWrite(_GetAutoItInstallFromSciTE() & @CRLF)
; Retrieve the AutoIt installation path from the SciTE process.
Func _GetAutoItInstallFromSciTE()
Local $sRelativePath = '..\', $sWorkingDir = @WorkingDir
FileChangeDir( _WinAPI_PathRemoveFileSpec(_WinAPI_GetProcessFileName(ProcessExists("SciTE.exe"))))
$sRelativePath = _WinAPI_GetFullPathName($sRelativePath)
FileChangeDir($sWorkingDir)
Return _WinAPI_PathRemoveBackslash($sRelativePath)
EndFunc ;==>_GetAutoItInstallFromSciTE
13 _GetClasses[편집]
; Get ALL Controls Info
Example()
Func Example()
; Run Calculator
Run("calc.exe")
; Wait 10 seconds for the Calculator window to appear.
Local const $hWnd = WinWait("[CLASS:CalcFrame]", '', 10)
; Retrieve a list of all the controls in the Calculator window using the handle returned by WinWait.
MsgBox(4096, '', _GetClasses($hWnd))
; Close the Calculator window using the handle returned by WinWait.
WinClose($hWnd)
EndFunc ;==>Example
; This function returns an @LF-separated list of controls on the specified window.
Func _GetClasses($sTitle, $sText = '')
Local $iCount_Button = 0, $iCount_Edit = 0, $iCount_Static = 0
Local $aClasses = StringSplit(WinGetClassList($sTitle, $sText), @LF)
Local $aClassID[$aClasses[0] + 1] = [$aClasses[0]]
For $i = 1 To $aClasses[0]
Select
Case $aClasses[$i] = "Button"
$iCount_Button += 1
$aClassID[$i] = $aClasses[$i] & $iCount_Button
Case $aClasses[$i] = "Edit"
$iCount_Edit += 1
$aClassID[$i] = $aClasses[$i] & $iCount_Edit
$aClasses[$i] = "Input"
Case $aClasses[$i] = "Static"
$iCount_Static += 1
$aClassID[$i] = $aClasses[$i] & $iCount_Static
$aClasses[$i] = "Label"
Case Else
If $aClasses[$i] <> "" Then
$aClassID[$i] = $aClasses[$i] & "?"
EndIf
EndSelect
Next
; Combine the results.
Local $sReturn = ""
For $i = 1 To $aClassID[0]
$sReturn &= $aClassID[$i] & @LF
Next
Return $sReturn
EndFunc ;==>_GetClasses
14 _GetFile[편집]
; FileRead Alternative
Func _GetFile($sFile, $iFormat = 0)
Local $hFileOpen = FileOpen($sFile, $iFormat)
If $hFileOpen = -1 Then
Return SetError(1, 0, "")
EndIf
Local $sData = FileRead($hFileOpen)
FileClose($hFileOpen)
Return $sData
EndFunc ;==>_GetFile
15 _GetTitle[편집]
; Get the title of your program.
ConsoleWrite(_GetTitle('Example') & @CRLF)
; The second parameter would normally be @ScriptDir & '\Uninstall.exe' for example, but for this demonstration I'm using the full path.
ConsoleWrite(_GetTitle('Example', @ScriptFullPath) & @CRLF)
Func _GetTitle($sProgramName, $sInstallPath = '')
Local $aOSArch[2] = ['', ' (64-bit)'], $aPortable[2] = [' (Portable)', '']
Return $sProgramName & $aOSArch[@AutoItX64] & $aPortable[FileExists($sInstallPath)]
EndFunc ;==>_GetTitle
16 _GetXML[편집]
; Simple Way Of Parsing XML Data.
#include <Array.au3>
Global $aReturn, $sXMLData
$sXMLData = "<data>This is a Simple example of XML</data><data>This is a Simple example of XML and is the Second String.</data>"
$aReturn = _GetXML($sXMLData, "data")
_ArrayDisplay($aReturn, "_GetXML()")
Func _GetXML($sString, $sData)
Local $aError[2] = [1, $sString], $aReturn
$aReturn = StringRegExp('<' & $sData & '></' & $sData & '>' & $sString, '(?s)(?i)<' & $sData & '>(.*?)</' & $sData & '>', 3)
If @error Then
Return SetError(1, 0, $aError)
EndIf
$aReturn[0] = UBound($aReturn, 1) - 1
Return SetError(0, 0, $aReturn)
EndFunc ;==>_GetXML
17 Include Source With Exe[편집]
;recover source .au3 file with /Extract switch
; The above code would be copied into the top of your script. The source location (C:\Test.au3 in my example) is the full path to your script file.
;Once compiled, if you run the script from the Run line with the /Extract switch, it will extact the original .au3 file into the Temp directory and will exit without actually executing the script.
If StringInStr($cmdlineRaw, "/Extract") Then
FileInstall("C:\Test.au3", @TempDir & "\Test.au3", 1)
Exit
EndIf
18 _IsANSIFile[편집]
#include <FileConstants.au3>
ConsoleWrite(_IsANSIFile(@ScriptFullPath) & @LF) ; Returns True.
Func _IsANSIFile($sFilePath)
Return FileGetEncoding($sFilePath) = $FO_READ
EndFunc ;==>_IsUnicodeFile
19 _IsUnicodeFile[편집]
#include <FileConstants.au3>
ConsoleWrite(_IsUnicodeFile(@ScriptFullPath) & @LF) ; Returns False.
Func _IsUnicodeFile($sFilePath)
Return FileGetEncoding($sFilePath) = $FO_UNICODE
EndFunc ;==>_IsUnicodeFile
20 _IsAu3File[편집]
ConsoleWrite(_IsAu3File(@AutoItExe) & @CRLF)
ConsoleWrite(_IsAu3File(@ScriptFullPath) & @CRLF)
; Checks whether the filepath is an au3 file.
Func _IsAu3File($sFilePath)
Return StringTrimLeft($sFilePath, StringInStr($sFilePath, ".", 2, -1)) = "au3"
EndFunc ;==>_IsAu3File
21 _IsDefault[편집]
If _IsDefault(Default) Then
MsgBox(0, "_IsDefault() - 1", "This was a Default variable.")
EndIf
If _IsDefault(-1) Then
MsgBox(0, "_IsDefault() - 2", "This was a Default variable.")
EndIf
If _IsDefault("Other") Then
MsgBox(0, "_IsDefault() - 3", "This was a Default variable.")
EndIf
Func _IsDefault($sDefault)
Return StringRegExp($sDefault, "(?-i)\s|Default|-1|0")
EndFunc ;==>_IsDefault
22 _IsInTrial[편집]
#include <Date.au3> ; Required for _DateDiff()
ConsoleWrite('Date trial started: ' & @YEAR & '/' & @MON & '/01' & @CRLF & _
'Today''s date: ' & @YEAR & '/' & @MON & '/' & @MDAY & @CRLF & _
'Trial period: 30 days' & @CRLF & _
'Is the trial period still valid: ' & _IsInTrial(@YEAR & '/' & @MON & '/01', 30) & @CRLF)
; Check if a trial period date is still valid.
Func _IsInTrial($sDateString, $iDays)
Return (_DateDiff('D', $sDateString, _NowCalcDate()) < $iDays)
EndFunc ;==>_IsInTrial
23 _IsVisible[편집]
; Check if the Notepad Window is visible.
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
; Check if the Notepad window is visible and display the appropriate message box.
If _IsVisible($hWnd) Then
MsgBox(4096, "", "Notepad is visible.")
Else
MsgBox(4096, "", "Notepad isn't visible.")
EndIf
; Close the Notepad window using the handle returned by WinWait.
WinClose($hWnd)
EndFunc ;==>Example
; Check if the window is visible.
Func _IsVisible($hWnd)
Return BitAND(WinGetState($hWnd), 2) = 2
EndFunc ;==>_IsVisible
24 Open Help File to Desired Page[편집]
; Open help file / Open a desired page
Global Const $sAutoItPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")
Run(@WindowsDir & "\hh.exe " & $sAutoItPath & "\AutoIt3.chm::/html/functions/GUICtrlCreateUpdown.htm")
25 _RunAU3[편집]
_RunAU3("AU3_Example.txt", '"This is a commandline example!"')
Func _RunAU3($sFilePath, $sCommandLine = "", $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0)
Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '" ' & $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)
EndFunc ;==>_RunAU3
Func _RunWaitAU3($sFilePath, $sCommandLine = "", $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0)
Local $iPID
$iPID = RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '" ' & $sCommandLine, $sWorkingDir, $iShowFlag, $iOptFlag)
If @error Then
Return SetError(@error, 1, 0)
EndIf
Return $iPID
EndFunc ;==>_RunWaitAU3
26 Run Any au3 File From Your Program[편집]
; Run Any Au3 File From Your Program
Global Const $sFilePath = @ScriptDir & "\Test.au3"
If @Compiled Then
Global Const $sFileExe = FileGetShortName(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sFilePath & '"')
Run($sFileExe)
Else
Global Const $sFileAu3 = FileGetShortName($sFilePath)
Run(@AutoItExe & " " & $sFileAu3, "", @SW_HIDE)
EndIf
27 _ScriptName[편집]
ConsoleWrite(_ScriptName() & @CRLF)
; Return the @ScriptName minus the .exe or .au3 extension.
Func _ScriptName()
Return StringLeft(@ScriptName, StringInStr(@ScriptName, '.', 2, -1) - 1)
EndFunc ;==>_ScriptName
28 _ScriptVersion[편집]
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Fileversion=1.2.3.4
#AutoIt3Wrapper_Res_LegalCopyright=2012 www.favessoft.com
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Global $version = _ScriptVersion()
Global $msg = "ScriptVerDemo" & " " & $version & " Copyright (c) 2012 www.favessoft.com" & @CRLF & @CRLF
MsgBox(0x1040, "", $msg)
; return File Version string from compiled or .au3 script
; returns "" if no version info available
; Note: The .au3 script must contain #AutoItWrapper
; directives with file version or "" is returned.
Func _ScriptVersion(Const $Script = @ScriptFullPath)
If StringRight($Script,4) = ".exe" Then
Return FileGetVersion($Script)
Else
Local Const $scriptHandle = FileOpen($Script)
Local $ver
Local $found = False
Local $pos
If $scriptHandle <> -1 Then
Do
$ver = FileReadLine($scriptHandle)
$sPos = StringInStr($ver, "_Fileversion=")
If $sPos Then
$ver = StringMid($ver, $sPos + StringLen("_Fileversion="))
$found = True
ExitLoop
EndIf
Until StringLeft($ver, 1) <> "#"
FileClose($scriptHandle)
EndIf
EndIf
If Not $found Then $ver = ""
Return $ver
EndFunc ;==>_ScriptVersion
29 _SetFile[편집]
; FileWrite Alternative
Func _SetFile(Const $sString, Const $sFile, Const $iOverwrite = 0)
Local Const $hFileOpen = FileOpen($sFile, $iOverwrite + 1)
FileWrite($hFileOpen, $sString)
FileClose($hFileOpen)
If @error Then
Return SetError(1, 0, $sString)
EndIf
Return $sString
EndFunc ;==>_SetFile
30 _ShowHelp[편집]
HotKeySet("{F1}", "_ShowHelp")
Func _ShowHelp()
Return ShellExecute(@ProgramFilesDir & "\AutoIt3\AutoIt3Help.exe") ; change this to the location of your own helpfile.
EndFunc ;==>_ShowHelp
31 _SingletonPID[편집]
Local $iSingleton = _SingletonPID('RandomName', 1)
If $iSingleton = 0 Then
MsgBox(4096, '', 'This is the first instance of the program running: ' & $iSingleton)
Else
MsgBox(4096, '', 'There is another instance running. This PID is: ' & $iSingleton)
EndIf
; #FUNCTION# ====================================================================================================================
; Name ..........: _SingletonPID
; Description ...: Enforce a design paradigm where only one instance of the script may be running.
; Syntax ........: _SingletonPID($sOccurenceName[, $iFlag = 0])
; Parameters ....: $sOccurenceName - String to identify the occurrence of the script.
; $iFlag - [optional] Optional parameters. Default is 0.
; 0 - Exit the script with the exit code -1 if another instance already exists.
; 1 - Return the PID of the main executable and without exiting the script too.
; Return values .: Success - 0 No other process is running.
; Failure - The PID of the main executable.
; Author ........: guinness with initial ideas by Valik for _Singleton & KaFu for _EnforceSingleInstance.
; Example .......: Yes
; ===============================================================================================================================
Func _SingletonPID(Const $sOccurenceName, Const $iFlag = 0)
Local $hHandle = WinGetHandle($sOccurenceName)
If @error Then
AutoItWinSetTitle($sOccurenceName)
$hHandle = WinGetHandle($sOccurenceName)
ControlSetText($hHandle, '', ControlGetHandle($hHandle, '', 'Edit1'), @AutoItPID)
Else
If BitAND($iFlag, 1) Then
Return Number(ControlGetText($hHandle, '', ControlGetHandle($hHandle, '', 'Edit1')))
Else
Exit -1
EndIf
EndIf
Return 0
EndFunc ;==>_SingletonPID
32 _Sort[편집]
#include <Constants.au3>
ConsoleWrite(_Sort("$sVariable" & @CRLF & "$iVariable" & @CRLF & "$tVariable" & @CRLF & "$pVariable"))
Func _Sort(Const $sSortList)
Local Const $iPID = Run("sort.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD), $sOutput = ""
StdinWrite($iPID, $sSortList)
StdinWrite($iPID)
While 1
$sOutput &= StdoutRead($iPID)
If @error Then
ExitLoop
EndIf
WEnd
Return $sOutput
EndFunc ;==>_Sort
33 Speak Object and Save to WAV File[편집]
; Speak Object and save to wav file
Local $ObjFile = ObjCreate("Sapi.SpFileStream.1")
$ObjVoice.Speak($sText)
$ObjFile.Open($sFilePath, 3)
$ObjVoice.AudioOutputStream = $ObjFile
EndFunc ;==>_SpeakToWAV
34 _VariableSwap[편집]
Global $sString_1 = 'This is string 1.'
Global $sString_2 = 'This is string 2.'
ConsoleWrite('$sString_1: ' & $sString_1 & @CRLF)
ConsoleWrite('$sString_2: ' & $sString_2 & @CRLF & @CRLF)
_VariableSwap($sString_1, $sString_2)
ConsoleWrite('$sString_1: ' & $sString_1 & @CRLF)
ConsoleWrite('$sString_2: ' & $sString_2 & @CRLF & @CRLF)
; Swap the contents of two variables.
Func _VariableSwap(ByRef $vVariable_1, ByRef $vVariable_2) ; Similar to _ArraySwap though not obvious to some this isn't limited to arrays.
Local Const $vTemp = $vVariable_1
$vVariable_1 = $vVariable_2
$vVariable_2 = $vTemp
EndFunc ;==>_VariableSwap
35 _WinAPI_CharLower[편집]
ConsoleWrite(_WinAPI_CharLower("EXAMPLE") & @CRLF) ; Similar to StringLower.
; Convert characters to lowercase.
Func _WinAPI_CharLower($sString)
Local $aReturn = DllCall('user32.dll', 'wstr', 'CharLowerW', 'wstr', $sString)
If @error Then
Return SetError(1, 0, $sString)
EndIf
Return $aReturn[0]
EndFunc ;==>_WinAPI_CharLower
36 _WinAPI_CharUpper[편집]
ConsoleWrite(_WinAPI_CharUpper("example") & @CRLF) ; Similar to StringUpper.
; Convert characters to uppercase.
Func _WinAPI_CharUpper($sString)
Local $aReturn = DllCall('user32.dll', 'wstr', 'CharUpperW', 'wstr', $sString)
If @error Then
Return SetError(1, 0, $sString)
EndIf
Return $aReturn[0]
EndFunc ;==>_WinAPI_CharUpper
37 _WinAPI_PathFileExists[편집]
; An API Alternative To FileExist.
ConsoleWrite(_WinAPI_PathFileExists(@ScriptFullPath) & @LF) ; File.
ConsoleWrite(_WinAPI_PathFileExists("C:\") & @LF) ; Drive.
ConsoleWrite(_WinAPI_PathFileExists(@ProgramFilesDir) & @LF) ; Directory.
ConsoleWrite(_WinAPI_PathFileExists("Z:\File.txt") & @LF) ; Shouldn't exist!
Func _WinAPI_PathFileExists($sFilePath)
Local $aReturn = DllCall('shlwapi.dll', 'int', 'PathFileExistsW', 'wstr', $sFilePath)
If @error Then
Return SetError(1, 0, 0)
EndIf
Return $aReturn[0]
EndFunc ;==>_WinAPI_PathFileExists
38 _WinActiveByExe[편집]
; Window Active/Activate by Exe, Open Notepad whilst script is running
While 1
If _WinActiveByExe('notepad.exe', False) Then MsgBox(64, 'info', 'true')
Sleep(100)
WEnd
Func _WinActiveByExe($sExe, $iActive = True);False to WinActivate, True to just see if it's active
If Not ProcessExists($sExe) Then Return SetError(1, 0, 0)
Local $aPL = ProcessList($sExe)
Local $aWL = WinList()
For $iCC = 1 To $aWL[0][0]
For $xCC = 1 To $aPL[0][0]
If $aWL[$iCC][0] <> '' And _
WinGetProcess($aWL[$iCC][1]) = $aPL[$xCC][1] And _
BitAND(WinGetState($aWL[$iCC][1]), 2) Then
If $iActive And WinActive($aWL[$iCC][1]) Then Return 1
If Not $iActive And Not WinActive($aWL[$iCC][1]) Then
WinActivate($aWL[$iCC][1])
Return 1
EndIf
EndIf
Next
Next
Return SetError(2, 0, 0)
EndFunc
39 _WindowShake[편집]
; Shake a window left to right.
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
; Wait for 1 second.
Sleep(1000)
; Shake the Notepad window left to right.
_WindowShake($hWnd)
; Wait for 1 second.
Sleep(1000)
; Close the Notepad window using the handle returned by WinWait.
WinClose($hWnd)
EndFunc ;==>Example
Func _WindowShake($sTitle, $sText = '', $iDistance = 20)
Local $hWnd = WinGetHandle($sTitle, $sText)
Local $aWinGetPos = WinGetPos($hWnd)
If @error Then
Return SetError(1, 0, 0)
EndIf
Local $aArray[5] = [4, $aWinGetPos[0] + $iDistance, $aWinGetPos[0], $aWinGetPos[0] + $iDistance, $aWinGetPos[0]]
For $i = 1 To $aArray[0]
WinMove($hWnd, '', $aArray[$i], Default)
Sleep(100)
Next
EndFunc ;==>_WindowShake
40 _WinGetDetails[편집]
#include <Array.au3>
Global $aArray = _WinGetDetails('[ACTIVE]') ; Returns the Window's title, PID, folder path filename.
If @error Then
Exit
EndIf
_ArrayDisplay($aArray)
Func _WinGetDetails($sTitle, $sText = '') ; Based on code of _WinGetPath by GaryFrost.
Local $aReturn[5] = [4, '-WinTitle', '-PID', '-FolderPath', '-FileName'], $aStringSplit
If StringLen($sText) > 0 Then
$aReturn[1] = WinGetTitle($sTitle, $sText)
Else
$aReturn[1] = WinGetTitle($sTitle)
EndIf
$aReturn[2] = WinGetProcess($aReturn[1])
Local $oWMIService = ObjGet('winmgmts:\\.\root\CIMV2')
Local $oItems = $oWMIService.ExecQuery('Select * From Win32_Process Where ProcessId = ' & $aReturn[2], 'WQL', 0x30)
If IsObj($oItems) Then
For $oItem In $oItems
If $oItem.ExecutablePath Then
$aStringSplit = StringSplit($oItem.ExecutablePath, '\')
$aReturn[3] = ''
For $A = 1 To $aStringSplit[0] - 1
$aReturn[3] &= $aStringSplit[$A] & '\'
Next
$aReturn[3] = StringTrimRight($aReturn[3], 1)
$aReturn[4] = $aStringSplit[$aStringSplit[0]]
Return $aReturn
EndIf
Next
EndIf
Return SetError(1, 0, $aReturn)
EndFunc ;==>_WinGetPath
41 _WinGetNumeratedClassList[편집]
; Description: Retrieves the numerated classes from a window.
Func _WinGetNumeratedClassList($sTitle)
Local $sClassList = WinGetClassList($sTitle)
Local $aClassList = StringSplit($sClassList, @LF)
Local $sRetClassList = "", $sHold_List = "|"
Local $aiInHold, $iInHold
For $i = 1 To UBound($aClassList) - 1
If $aClassList[$i] = "" Then ContinueLoop
If StringRegExp($sHold_List, "\|" & $aClassList[$i] & "~(\d+)\|") Then
$aiInHold = StringRegExp($sHold_List, ".*\|" & $aClassList[$i] & "~(\d+)\|.*", 1)
$iInHold = Number($aiInHold[UBound($aiInHold)-1])
If $iInHold = 0 Then $iInHold += 1
$aClassList[$i] &= "~" & $iInHold + 1
$sHold_List &= $aClassList[$i] & "|"
$sRetClassList &= $aClassList[$i] & @LF
Else
$aClassList[$i] &= "~1"
$sHold_List &= $aClassList[$i] & "|"
$sRetClassList &= $aClassList[$i] & @LF
EndIf
Next
Return StringReplace(StringStripWS($sRetClassList, 3), "~", "")
EndFunc
42 _WinGetHandleByPID[편집]
; Get Window Handle by PID
#include <Array.au3>
Global $a1 = _WinGetHandleByPID(232)
Global $a2 = _WinGetHandleByPID("notepad.exe", -1)
Global $a3 = _WinGetHandleByPID("notepad.exe", 0)
Global $a4 = _WinGetHandleByPID("notepad.exe", 1)
_ArrayDisplay($a1, "1")
_ArrayDisplay($a2, "2")
_ArrayDisplay($a3, "3")
_ArrayDisplay($a4, "4")
;$nVisible = -1 "All (Visble or not)", $nVisible = 0 "Not Visible Only", $nVisible = 1 "Visible Only"
Func _WinGetHandleByPID($vProc, $nVisible = 1)
$vProc = ProcessExists($vProc);
If Not $vProc Then Return SetError(1, 0, 0)
Local $aWL = WinList()
Local $aTemp[UBound($aWL)][2]
Local $nAdd = 0
For $iCC = 1 To $aWL[0][0]
If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then
$nAdd += 1
$aTemp[$nAdd][0] = $aWL[$iCC][0]
$aTemp[$nAdd][1] = $aWL[$iCC][1]
ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _
BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then
$nAdd += 1
$aTemp[$nAdd][0] = $aWL[$iCC][0]
$aTemp[$nAdd][1] = $aWL[$iCC][1]
ElseIf $nVisible > 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _
BitAND(WinGetState($aWL[$iCC][1]), 2) Then
$nAdd += 1
$aTemp[$nAdd][0] = $aWL[$iCC][0]
$aTemp[$nAdd][1] = $aWL[$iCC][1]
EndIf
Next
If $nAdd = 0 Then Return SetError(2, 0, 0) ; No windows found
ReDim $aTemp[$nAdd + 1][2]
$aTemp[0][0] = $nAdd
Return $aTemp
EndFunc
43 _1Dto2DArray[편집]
#include <Array.au3>
Global $aArray_1D[2] = ["Data", "Data"]
_ArrayDisplay($aArray_1D)
_1Dto2DArray($aArray_1D)
_ArrayDisplay($aArray_1D)
Global $aArray_1D[10] = ["Data", "Data", "Data", "Data", "Data", "Data", "Data", "Data", "Data", "Data"]
_ArrayDisplay($aArray_1D)
_1Dto2DArray($aArray_1D, 9)
_ArrayDisplay($aArray_1D)
Func _1Dto2DArray(ByRef $aArray, Const $iAdditionalColumns = 1)
Local Const $iSize = UBound($aArray, 1)
Local $aReturn[$iSize][$iAdditionalColumns + 1]
For $A = 0 To $iSize - 1
$aReturn[$A][0] = $aArray[$A]
Next
$aArray = $aReturn
Return $aReturn
EndFunc ;==>_1Dto2DArray
44 _ArrayAddEx[편집]
#include <Array.au3>
Example_1()
Example_2()
Func Example_1()
Local $aArray_1[1] = ["Data_0"], $iBegin
$iBegin = TimerInit() ; Start the timer.
For $i = 1 To 5000
_ArrayAdd($aArray_1, "Data_" & $i)
Next
$iBegin = TimerDiff($iBegin) ; End the timer and find the difference from start to finish.
ConsoleWrite("_ArrayAdd from Array.au3 >> " & $iBegin & @CRLF)
_ArrayDisplay($aArray_1)
EndFunc ;==>Example_1
Func Example_2()
Local $aArray_2[1] = ["Data_0"], $iBegin, $iDimension, $iCount
$iBegin = TimerInit() ; Start the timer.
For $i = 1 To 5000
_ArrayAddEx($aArray_2, "Data_" & $i, $iDimension, $iCount) ; $iDimension is the overall size of the array & $iCount is the last index number, because regarding the overall size +1 as the next item will give false results as we're increasing the size of the array not by 1 but multiplying 2.
Next
$iBegin = TimerDiff($iBegin) ; End the timer and find the difference from start to finish.
ConsoleWrite("_ArrayAddEx by guinness >> " & $iBegin & @CRLF)
ReDim $aArray_2[$iCount] ; Remove the empty rows.
_ArrayDisplay($aArray_2)
EndFunc ;==>Example_2
Func _ArrayAddEx(ByRef $aArray, $sData, ByRef $iDimension, ByRef $iCount) ; Taken from Array.au3 and modified by guinness to reduce the use of ReDim.
If IsArray($aArray) = 0 Then
Return SetError(1, 0, -1)
EndIf
If UBound($aArray, 0) <> 1 Then
Return SetError(2, 0, -1)
EndIf
If $iCount = 0 Then
$iCount = UBound($aArray, 1)
EndIf
$iCount += 1
If ($iCount + 1) >= $iDimension Then
$iDimension = (UBound($aArray, 1) + 1) * 2
ReDim $aArray[$iDimension]
EndIf
$aArray[$iCount - 1] = $sData
Return $iCount - 1
EndFunc ;==>_ArrayAddEx
45 _ArrayEmpty[편집]
#include <Array.au3>
Global $aMain[11] = [10]
_ArrayEmpty($aMain)
_ArrayDisplay($aMain, "Empty 1D Array.")
Global $aMainEx[11][3] = [[10]]
_ArrayEmpty($aMainEx)
_ArrayDisplay($aMainEx, "Empty 2D Array.")
Func _ArrayEmpty(ByRef $aArray)
Switch UBound($aArray, 0) ; Dimension, 1D or 2D array are supported.
Case 1
Local $aEmpty1D[1]
$aArray = $aEmpty1D
Case 2
; Edit by DatMCEyeBall - Instead of emptying the array to [1][$x] we empty it to [$x][$y]
; where $x is the 1st dimensions size and $y the 2nd.
; Previous code was: Local $aEmpty2D[1][UBound($aArray, 2)]
; This way we preserve the arrays' original size.
Local $aEmpty2D[UBound($aArray, 1)][UBound($aArray, 2)]
$aArray = $aEmpty2D
EndSwitch
EndFunc ;==>_ArrayEmpty
46 _ArrayGet[편집]
Global $b[2] = ["a", "b"]
Global $a[3][2] = [[0, -1], [$b, "x"], [1, -2]]
Global $c[5] = [11, 22, 33, 44, 55]
MsgBox(0, "", _ArrayGet($a, 1, 0, 1) & " # " & @error)
; #FUNCTION# ====================================================================================================================
; Name ..........: _ArrayGet
; Description ...: Gets a value from a nested multidimensional array
; Syntax ........: _ArrayGet(Byref $aArray, $i1[, $i2 = 0[, $i3 = 0[, $i4 = 0[, $i5 = 0[, $i6 = 0[, $i7 = 0[, $i8 = 0[,
; $i9 = 0[, $i10 = 0[, $i11 = 0[, $i12 = 0[, $i13 = 0[, $i14 = 0[, $i15 = 0[, $i16 = 0[, $i17 = 0[,
; $i18 = 0[, $i19 = 0[, $i20 = 0]]]]]]]]]]]]]]]]]]])
; Parameters ....: $aArray - [in/out] An array of unknowns.
; $i1 - first array index.
; $i2 - [optional] second array index.
; $i3 - [optional] third array index.
; $i4 - [optional] fourth array index.
; $i5 - [optional] fifth array index.
; $i6 - [optional] sixth array index.
; $i7 - [optional] seventh array index.
; $i8 - [optional] eighth array index.
; $i9 - [optional] ninth array index.
; $i10 - [optional] 10th array index.
; $i11 - [optional] 11th array index.
; $i12 - [optional] 12th array index.
; $i13 - [optional] 13th array index.
; $i14 - [optional] 14th array index.
; $i15 - [optional] 15th array index.
; $i16 - [optional] 16th array index.
; $i17 - [optional] 17th array index.
; $i18 - [optional] 18th array index.
; $i19 - [optional] 19th array index.
; $i20 - [optional] 20th array index.
; Return values .: Success: Value at the specified index
; Error: Nothing, Sets @error to:
; |1 - Trying to acces non-array as array
; |2 - Not enough dimensions for the last accessed array
; |3 - Index out of bounds for a dimension
; @extended contains the dimension in error (according to parameter list)
; Author ........: ProgAndy
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ArrayGet(ByRef $aArray, $i1, $i2=0, $i3=0, $i4=0, $i5=0, $i6=0, $i7=0, $i8=0, $i9=0, $i10=0, $i11=0, $i12=0, $i13=0, $i14=0, $i15=0, $i16=0, $i17=0, $i18=0, $i19=0, $i20=0)
#forceref $i1, $i2, $i3, $i4, $i5, $i6, $i7, $i8, $i9, $i10, $i11, $i12, $i13, $i14, $i15, $i16, $i17, $i18, $i19, $i20
; ProgAndy
Local $NULL
If Not IsArray($aArray) Then Return SetError(1, 1, $NULL)
Local $iDims = UBound($aArray, 0)
If @NumParams <= $iDims Then Return SetError(2, @NumParams, $NULL)
Local $sAccess = "$aArray"
For $i = 1 To $iDims
Local $iIndex = Int(Eval("i" & $i))
If $iIndex >= UBound($aArray, $i) Then Return SetError(3, $i, $NULL)
$sAccess &= '[' & $iIndex & ']'
Next
If @NumParams-1 > $iDims Then ; Still indices left
For $i = $iDims+1 To @NumParams-1
$sAccess &= ", $i" & $i
Next
Local $vResult = Execute("_ArrayGet(" & $sAccess & ")")
If @error Then SetError(@error, @extended+$iDims)
Return $vResult
Else ;
Return Execute($sAccess)
EndIf
EndFunc
47 _ArraySet[편집]
Global $b[2] = ['a', 'b'
Global $a[3][2] = [[0, -1], [$b, "x"], [1, -2]]
Global $c[5] = [11, 22, 33, 44, 55]
_ArraySet($a, $c, 1, 0, 0)
; #FUNCTION# ====================================================================================================================
; Name ..........: _ArraySet
; Description ...: Sets a value from a nested multidimensional array
; Syntax ........: _ArraySet(Byref $aArray, $vValue, $i1[, $i2 = 0[, $i3 = 0[, $i4 = 0[, $i5 = 0[, $i6 = 0[, $i7 = 0[, $i8 = 0[,
; $i9 = 0[, $i10 = 0[, $i11 = 0[, $i12 = 0[, $i13 = 0[, $i14 = 0[, $i15 = 0[, $i16 = 0[, $i17 = 0[,
; $i18 = 0[, $i19 = 0[, $i20 = 0]]]]]]]]]]]]]]]]]]])
; Parameters ....: $aArray - [in/out] An array of unknowns.
; $vValue - value to set at specified index.
; $i1 - first array index.
; $i2 - [optional] second array index.
; $i3 - [optional] third array index.
; $i4 - [optional] fourth array index.
; $i5 - [optional] fifth array index.
; $i6 - [optional] sixth array index.
; $i7 - [optional] seventh array index.
; $i8 - [optional] eighth array index.
; $i9 - [optional] ninth array index.
; $i10 - [optional] 10th array index.
; $i11 - [optional] 11th array index.
; $i12 - [optional] 12th array index.
; $i13 - [optional] 13th array index.
; $i14 - [optional] 14th array index.
; $i15 - [optional] 15th array index.
; $i16 - [optional] 16th array index.
; $i17 - [optional] 17th array index.
; $i18 - [optional] 18th array index.
; $i19 - [optional] 19th array index.
; $i20 - [optional] 20th array index.
; Return values .: Success: True
; Error: False, Sets @error to:
; |1 - Trying to acces non-array as array
; |2 - Not enough dimensions for the last accessed array
; |3 - Index out of bounds for a dimension
; |all: - @extended contains the dimension in error (according to parameter list)
; Author ........: ProgAndy
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ArraySet(ByRef $aArray, Const $vValue, $i1, $i2=0, $i3=0, $i4=0, $i5=0, $i6=0, $i7=0, $i8=0, $i9=0, $i10=0, $i11=0, $i12=0, $i13=0, $i14=0, $i15=0, $i16=0, $i17=0, $i18=0, $i19=0, $i20=0)
; ProgAndy
Local Const $NULL = False
If Not IsArray($aArray) Then Return SetError(1, 1, $NULL)
Local $iDims = UBound($aArray, 0)
If @NumParams-2 < $iDims Then Return SetError(2, @NumParams-1, $NULL)
Local $sAccess = "$aArray"
For $i = 1 To $iDims
Local $iIndex = Int(Eval("i" & $i))
If $iIndex >= UBound($aArray, $i) Then Return SetError(3, $i, $NULL)
$sAccess &= '[' & $iIndex & ']'
Next
If @NumParams-2 > $iDims Then
$sAccess &= ", $vValue"
For $i = $iDims+1 To @NumParams-2
$sAccess &= ", $i" & $i
Next
Local $fSuccess = Execute("_ArraySet(" & $sAccess & ")")
If @error Then SetError(@error, @extended+$iDims)
Return $fSuccess
EndIf
Switch $iDims
Case 1
$aArray[$i1] = $vValue
Case 2
$aArray[$i1][$i2] = $vValue
Case 3
$aArray[$i1][$i2][$i3] = $vValue
Case 4
$aArray[$i1][$i2][$i3][$i4] = $vValue
Case 5
$aArray[$i1][$i2][$i3][$i4][$i5] = $vValue
Case 6
$aArray[$i1][$i2][$i3][$i4][$i5][$i6] = $vValue
Case 7
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7] = $vValue
Case 8
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8] = $vValue
Case 9
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9] = $vValue
Case 10
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10] = $vValue
Case 11
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11] = $vValue
Case 12
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12] = $vValue
Case 13
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13] = $vValue
Case 14
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14] = $vValue
Case 15
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15] = $vValue
Case 16
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16] = $vValue
Case 17
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17] = $vValue
Case 18
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17][$i18] = $vValue
Case 19
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17][$i18][$i19] = $vValue
Case 20
$aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17][$i18][$i19][$i20] = $vValue
EndSwitch
Return True
EndFunc
48 _ArrayLength[편집]
Global $aArray[2][50]
ConsoleWrite(_ArrayLength($aArray, 2) & @CRLF) ;= > 10 - Total items
ConsoleWrite(_ArrayLength($aArray, 1) & @CRLF) ;= > 5 - Columns
ConsoleWrite(_ArrayLength($aArray, 0) & @CRLF) ;= > 2 - Rows
ConsoleWrite(@CRLF)
Global $aArray[2]
ConsoleWrite(_ArrayLength($aArray, 2) & @CRLF) ;= > 2 - Total items
ConsoleWrite(_ArrayLength($aArray, 1) & @CRLF) ;= > 1 - Columns
ConsoleWrite(_ArrayLength($aArray, 0) & @CRLF) ;= > 2 - Rows
Func _ArrayLength($aArray, $iType = 1)
Local $iDim = UBound($aArray, 0)
If $iDim < 0 Or $iDim > 2 Then ; If not a 1D or 2D Array, then return -1 and set @error to non-zero.
Return SetError(1, 0, -1)
EndIf
Switch $iType
Case 2
If $iDim = 2 Then
Return UBound($aArray, 2) * UBound($aArray, 1)
Else
Return UBound($aArray, 1)
EndIf
Case 1
If $iDim = 2 Then
Return UBound($aArray, 2)
Else
Return 1
EndIf
Case Else
Return UBound($aArray, 1)
EndSwitch
EndFunc ;==>_ArrayLength
49 _ArraySortNum[편집]
; ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1)
; Sorts arrays based on TRUE Numerical Order, including Decimals
#include <Array.au3>
; Example sort Array created with StringSplit.
Global $avArray = StringSplit("6,8,10,4,2,13,12,129,106.1,106.4", ",")
_ArraySortNum($avArray, 1)
_ArrayDisplay($avArray, "Sorted Desc starting at 1")
Func _ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1)
For $i = $Start To UBound($nArray) - 2
Local $SE = $i
If $Ascending = 0 Then
For $x = $i To UBound($nArray) - 1
If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x
Next
Else
For $x = $i To UBound($nArray) - 1
If Number($nArray[$SE]) > Number($nArray[$x]) Then $SE = $x
Next
EndIf
Local $HLD = $nArray[$i]
$nArray[$i] = $nArray[$SE]
$nArray[$SE] = $HLD
Next
EndFunc ;==>_ArraySortNum
50 _AssocArray[편집]
; use Scripting.Dictionary object for simple associative arrays
; with string keys. Key comparisons are case insensitive.
Global $myArray
$myArray = _AssocArray()
If @error Then
MsgBox(0x1010,"_AssocArray() Error", "Error Creating Associative Array!")
Exit
EndIf
$myArray("AntiqueWhite") = 0xFAEBD7
$myArray("Black") = 0x000000
$myArray("Blue") = 0x0000FF
$myArray("Brown") = 0xA52A2A
$myArray("CadetBlue") = 0x5F9EA0
$myArray("Chocolate") = 0xD2691E
$myArray("Coral") = 0xFF7F50
MsgBox(0x1040,"","Hex for Chocolate Color is: 0x" & Hex($myArray("Chocolate"),6))
_AssocArrayDestroy($myArray)
Func _AssocArray()
Local $aArray = ObjCreate("Scripting.Dictionary")
If @error Then
Return SetError(1, 0, 0)
EndIf
$aArray.CompareMode = 1
Return $aArray
EndFunc ;==>_AssocArray
Func _AssocArrayDestroy(ByRef $aArray)
If Not IsObj($aArray) Then
Return False
EndIf
$aArray.RemoveAll()
$aArray = 0
Return True
EndFunc ;==>_AssocArrayDestroy
51 _DynEnumArray[편집]
Func _DynEnumArray($aArrayToEnum)
Local $aDims[1][2]=[["ElementIdx","ElementCount"]] ;Create an Array to Track Dimensions and Elements
For $iX = 1 to UBound($aArrayToEnum,0)
ReDim $aDims[$iX+1][2]
$aDims[$iX][0]=0
$aDims[$iX][1]=UBound($aArrayToEnum,$iX)
Next
Do ;Loop Through Array Elements
$sArray = "$aArrayToEnum"
For $iX = 1 to UBound($aDims)-1
$sArray &= "[" & $aDims[$iX][0] & "]"
Next
ConsoleWrite($sArray & " " & Execute($sArray) & @CRLF) ;Output Subscript and Value
$aDims[UBound($aDims)-1][0] += 1 ;Increment Last Dimension Element
For $iY = UBound($aDims)-2 To 1 Step -1 ;Increment Dimension Element
If $aDims[$iY+1][0] = $aDims[$iY+1][1] Then
$aDims[$iY+1][0]=0
$aDims[$iY][0]+=1
EndIf
Next
Until $aDims[1][0]=$aDims[1][1]
Return ConsoleWrite(@CRLF)
EndFunc
;Demos
Local $aArray[5]=["Never","Gonna","Give","You","Up"]
_DynEnumArray($aArray)
Local $aArray[6][2]=[["Penn", "Teller"],["Gilbert", "Sullivan"],["Sonny", "Cher"],["Stone", "Parker"],["Fischbacher", "Horn"],["Plant", "Page"]]
_DynEnumArray($aArray)
Local $aArray[2][3][2]=[[["All","Your"],["Base","Are"],["Belong","To Us"]],[["Is","This"],["The","Way"],["Back","Home"]]]
_DynEnumArray($aArray)
52 _FuncListToArray[편집]
$aFlist = _FuncListToArray(@ScriptFullPath)
If NOT @Error Then
For $i = 0 To Ubound($aFlist) -1
MsgBox(0, "TEST", $aFlist[$i], 2)
Next
EndIf
Func _FuncListToArray($sStr)
If FileExists($sStr) Then $sStr = FileRead($sStr)
Local $sRegEx = "(?i)(?m:^|\n)\s*Func\s+(\w+)\s*\("
$aRegEx = StringRegExp($sStr, $sRegEx, 3)
If IsArray($aRegEx) Then Return $aRegEx
Return SetError(1)
EndFunc
53 Identify Duplicate Values In Arrays[편집]
; Identify Duplicate Values In Arrays
#include <Array.au3>
Global $a1[3] = [1, 2, 3], $a2[5] = [5, 6, 7, 8, 9], $a3[2] = [3, 5]
Global $a_a[4] = [3, $a1, $a2, $a3]
MsgBox(0, "Dupes?", _SearchForDupes($a_a))
Func _SearchForDupes($a_arrays, $i_ReturnType = 0)
Local $Dupes[1] = [0]
If $a_arrays[0] < 2 Then Return ''
For $i = 1 To $a_a[0] - 1
For $j = $i + 1 To $a_a[0]
_FindDupe($a_a[$i], $a_a[$j], $Dupes)
Next
Next
If $Dupes[0] = 0 Then Return ''
_ArraySort($Dupes)
If Not $i_ReturnType Then
Local $s_return = ''
For $x = 1 To $Dupes[0]
$s_return &= $Dupes[$x] & ','
Next
Return StringTrimRight($s_return, 1)
Else
Return $Dupes
EndIf
EndFunc ;==>_SearchForDupes
Func _FindDupe(ByRef $a_array01, ByRef $a_array02, ByRef $Dupes)
Local $found = False
For $i = 0 To UBound($a_array01) - 1
For $j = 0 To UBound($a_array02) - 1
If $a_array01[$i] = $a_array02[$j] Then
$found = False
For $x = 1 To $Dupes[0]
If $Dupes[$x] = $a_array01[$i] Then
$found = True
ExitLoop
EndIf
Next
If Not $found Then
$Dupes[0] += 1
ReDim $Dupes[$Dupes[0] + 1]
$Dupes[$Dupes[0]] = $a_array01[$i]
EndIf
EndIf
Next
Next
EndFunc ;==>_FindDupe
54 _Is1DArray[편집]
Local $sString = 'String'
Local $a1DArray[2] = [1, 'Row_1']
Local $a2DArray[2][2] = [[1],['Row_1: Col_1', 'Row_1: Col_2']]
ConsoleWrite('Is the variable $sString a 1D Array?: ' & _Is1DArray($sString) & @CRLF)
ConsoleWrite('Is the variable $a1DArray a 1D Array?: ' & _Is1DArray($a1DArray) & @CRLF)
ConsoleWrite('Is the variable $a2DArray a 1D Array?: ' & _Is1DArray($a2DArray) & @CRLF)
; Check if a variable is a 1D Array.
Func _Is1DArray(ByRef Const $aArray)
Return UBound($aArray) And (UBound($aArray, 0) = 1)
EndFunc ;==>_Is1DArray
55 _Is2DArray[편집]
Local $sString = 'String'
Local $a1DArray[2] = [1, 'Row_1']
Local $a2DArray[2][2] = [[1],['Row_1: Col_1', 'Row_1: Col_2']]
ConsoleWrite('Is the variable $sString a 1D Array?: ' & _Is2DArray($sString) & @CRLF)
ConsoleWrite('Is the variable $a1DArray a 1D Array?: ' & _Is2DArray($a1DArray) & @CRLF)
ConsoleWrite('Is the variable $a2DArray a 1D Array?: ' & _Is2DArray($a2DArray) & @CRLF)
; Check if a variable is a 2D Array.
Func _Is2DArray(ByRef Const $aArray)
Return UBound($aArray) And (UBound($aArray, 0) = 2)
EndFunc ;==>_Is2DArray
56 _IsInBounds[편집]
#include <Constants.au3>
Local $aArray[5] = ['Item_1', 'Item_2', 'Item_3', 'Item_4', 'Item_5']
ConsoleWrite(_IsInBounds($aArray, 1) & @CRLF) ; Returns True as the Array has 5 items.
ConsoleWrite(_IsInBounds($aArray, 5) & @CRLF) ; Returns False as the Array has 5 items but starts from the 0th index not 1st.
ConsoleWrite(_IsInBounds($aArray, 0) & @CRLF) ; Returns True.
If _IsInBounds($aArray, 4) Then
MsgBox($MB_SYSTEMMODAL, '', 'Position 4 contains the value: "' & $aArray[4] & '"')
EndIf
Func _IsInBounds(ByRef Const $aArray, $iIndex)
Local $iDim = UBound($aArray, 0)
If $iDim < 0 Or $iDim > 2 Then ; If not a 1D or 2D Array, then return -1 and set @error to non-zero.
Return SetError(1, 0, False)
EndIf
Return $iIndex < UBound($aArray, 1)
EndFunc ;==>_IsInBounds
57 _MultiFileListToArray[편집]
; Multiple File List to Array
$Files_List = _MultiFileListToArray(@ScriptDir, "*.txt|*.ini")
; for display only
$GUI = GUICreate(" _MultiFileListToArray - DEMO")
$Edit1 = GUICtrlCreateEdit("", 50, 50, 300, 300)
For $x = 1 To UBound($Files_List) - 1
GUICtrlSetData(-1, $Files_List[$x] & @CRLF, 1)
Next
GUISetState()
While GUIGetMsg() <> -3
WEnd
; end display only
Func _MultiFileListToArray($sPath, $sFilter = "*", $iFlag = 0)
Local $hSearch, $sFile, $asFileList[1], $sCount
If Not FileExists($sPath) Then Return SetError(1, 1, "")
If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "")
$sFilter = (StringSplit($sFilter, "|"))
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
For $sCount = 1 To $sFilter[0]
$hSearch = FileFindFirstFile($sPath & "\" & $sFilter[$sCount])
If $hSearch = -1 Then
If $sCount = $sFilter[0] Then Return SetError(4, 4, $asFileList)
ContinueLoop
EndIf
While 1
$sFile = FileFindNextFile($hSearch)
If @error Then
SetError(0)
ExitLoop
EndIf
If $iFlag = 1 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
ReDim $asFileList[UBound($asFileList) + 1]
$asFileList[0] = $asFileList[0] + 1
$asFileList[UBound($asFileList) - 1] = $sFile
WEnd
FileClose($hSearch)
Next
Return $asFileList
EndFunc ;==>_MultiFileListToArray
58 Return Min or Max Number From One or Two Arrays[편집]
#include <Array.au3>
Func _MinMaxa($a_nums01, $MaxFlag = 0, $a_nums02 = 0)
If Not IsArray($a_nums01) Then
SetError(1)
Return (0)
EndIf
If @NumParams = 3 Then
If Not IsArray($a_nums02) Then
SetError(3)
Return (0)
EndIf
EndIf
Local $idx
For $idx = 0 To UBound($a_nums01) - 1
If StringIsFloat($a_nums01[$idx]) Or StringIsInt($a_nums01[$idx]) Then
$a_nums01[$idx] = Number($a_nums01[$idx])
Else
SetError(2)
Return (0)
EndIf
Next
_ArraySort($a_nums01, $MaxFlag)
If @NumParams = 3 Then
For $idx = 0 To UBound($a_nums02) - 1
If StringIsFloat($a_nums02[$idx]) Or StringIsInt($a_nums02[$idx]) Then
$a_nums02[$idx] = Number($a_nums02[$idx])
Else
SetError(4)
Return (0)
EndIf
Next
_ArraySort($a_nums02, $MaxFlag)
If $MaxFlag Then
If Number($a_nums01[0]) > Number($a_nums02[0]) Then
Return $a_nums01[0]
Else
Return $a_nums02[0]
EndIf
Else
If Number($a_nums01[0]) < Number($a_nums02[0]) Then
Return $a_nums01[0]
Else
Return $a_nums02[0]
EndIf
EndIf
EndIf
Return $a_nums01[0]
EndFunc ;==>_MinMaxa