Leaderboard
Popular Content
Showing content with the highest reputation on 04/16/2019 in all areas
-
I wouldn't use variables like you do to get access to a window. It is very hard to read, and it is useless, since you will refer to them only once, at the first Win* () function. Because after that statement, you should use the window handle provided by the Win* () function. Local $hWnd = WinWait ("[TITLE: something; CLASS:#32770]") ControlClick ($hWnd, "", "Button1") Don't you think it is clearer ?1 point
-
Execute from var?
user4157124 reacted to Funtime60 for a topic
@JohnOne I have good news for you! execute() already supports multi-line commands! it simply need to know where carriage-return line-feeds need to go by replacing carriage-return line-feeds with the autoit syntax for such. A simple stringreplace($string,@CRLF,' @CRLF ') applied to an .au3 makes it executable using execute(). Here is a proof of concept converter that converts an .au3 to something that can be run using an execute() Local $filepath = FileOpenDialog("Open File",@ScriptDir,"AutoIt Source (*.au3)|Plain Text (*.txt)|All Files (*.*)") Local $filehand = FileOpen($filepath) Local $filedata = FileRead($filehand) MsgBox(0,"Init",$filedata) Local $savedata = StringReplace($filedata,@CRLF,' @CRLF ') MsgBox(0,"Done",$savedata) Local $savepath = FileSaveDialog("Save File",@ScriptDir,"Plain Text (*.txt)|All Files (*.*)") Local $savehand = FileOpen($savepath,2) FileWrite($savehand,$savedata) Apologies if I said something previously mentioned, I missed that this thread was two pages. I hope my post is still relevant.1 point -
Logic Help
BlackSnoww reacted to Nine for a topic
I meant you have to change the way your script would work if you were to go with that Opt("GUIOnEventMode", 1). I'll show you : #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars",1) Global Const $LocationY = 112, $SpaceY = 28, $ButtonArrayIndex = 5 Global $Button[$ButtonArrayIndex] Global $BrowseFields[$ButtonArrayIndex] Global $ButtonCount = 1 Global $MainForm = GUICreate("Auto Backup", 453, 180, 900, 247) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton") Global $BackupLocation = GUICtrlCreateLabel("Location of the Backup Folder:", 8, 8, 169, 19) GUICtrlSetFont(-1, 10, 400, 0, "Calibri") GUICtrlSetResizing(-1,$GUI_DOCKALL) Global $BrowseButton = GUICtrlCreateButton("Browse", 8, 32, 65, 17) GUICtrlSetResizing(-1,$GUI_DOCKALL) GUICtrlSetOnEvent(-1, "Browse") Global $BrowseField = GUICtrlCreateEdit("", 80, 32, 329, 17, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN)) GUICtrlSetResizing(-1,$GUI_DOCKAlL) Global $FolderBackup = GUICtrlCreateLabel("Locations of the Folder to be Backup:", 8, 80, 205, 19) GUICtrlSetFont(-1, 10, 400, 0, "Calibri") GUICtrlSetResizing($FolderBackup,$GUI_DOCKALL) For $i = 0 to $ButtonArrayIndex-1 $Button[$i] = GUICtrlCreateButton("Browse", 8, $LocationY, 65, 17) GUICtrlSetResizing(-1,$GUI_DOCKALL) If $i Then GUICtrlSetState (-1, $GUI_HIDE+$GUI_DISABLE) GUICtrlSetOnEvent(-1, "Browse") $BrowseFields[$i] = GUICtrlCreateEdit("", 80, $LocationY, 329, 17, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN)) GUICtrlSetResizing(-1,$GUI_DOCKALL) If $i Then GUICtrlSetState (-1, $GUI_HIDE+$GUI_DISABLE) Next Global $BackupButton = GUICtrlCreateButton("Backup", 200, 144, 73, 25) GUICtrlSetOnEvent(-1, "StartBackup") Global $ExpandButton = GUICtrlCreateButton("+", 416, 112, 17, 17) GUICtrlSetResizing($ExpandButton,$GUI_DOCKALL) GUICtrlSetOnEvent(-1, "ExpandGUI") GUISetState(@SW_SHOW) While 1 Sleep (100) WEnd Func Browse () Local $sDir = FileSelectFolder ("Select folder","C:\") If @error Then Return ; Do some checks maybe ? GUICtrlSetData (@GUI_CtrlId+1,$sDir) EndFunc Func ExpandGUI() If $ButtonCount = $ButtonArrayIndex Then Return MsgBox($MB_SYSTEMMODAL, "Notice", "Maximum Number of Locations Reached") Local $GuiPosition = WinGetPos($MainForm) ; Get the GUI coördinates WinMove($MainForm, "", $GuiPosition[0], $GuiPosition[1], $GuiPosition[2], $GuiPosition[3] + 30) GUICtrlSetPos ($Button[$ButtonCount], 8, $LocationY+($ButtonCount*$SpaceY)) GUICtrlSetState ($Button[$ButtonCount], $GUI_SHOW+$GUI_ENABLE) GUICtrlSetPos ($BrowseFields[$ButtonCount], 80, $LocationY+($ButtonCount*$SpaceY)) GUICtrlSetState ($BrowseFields[$ButtonCount], $GUI_SHOW+$GUI_ENABLE) $ButtonCount += 1 EndFunc Func CLOSEButton() Exit MsgBox($MB_OK, "GUI Event", "You selected CLOSE! Exiting...") EndFunc ;==>CLOSEButton Func StartBackup () ;Perform the backup here EndFunc1 point -
Logic Help
BlackSnoww reacted to Subz for a topic
Try something like: #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Global $g_iButtonCount = 0 ;~ First Browse Button Top Location Global $g_iTop = 112 ;~ Column 1 = Browse Button ;~ Column 2 = Browse Field Global $g_aBrowse[0][2], $g_sBrowseFolder, $g_sSelectFolder, $g_sBrowseFields Global $g_hMainForm = GUICreate("Auto Backup", 453, 180, 900, 247) Global $g_sBackupLocation = GUICtrlCreateLabel("Location of the Backup Folder:", 8, 8, 169, 19) GUICtrlSetFont($g_sBackupLocation, 10, 400, 0, "Calibri") GUICtrlSetResizing($g_sBackupLocation,$GUI_DOCKALL) Global $g_idBrowseButton = GUICtrlCreateButton("Browse", 8, 32, 65, 17) GUICtrlSetResizing($g_idBrowseButton,$GUI_DOCKALL) Global $g_idBrowseField = GUICtrlCreateEdit("", 80, 32, 329, 17, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN)) GUICtrlSetResizing($g_idBrowseField,$GUI_DOCKAlL) Global $g_idFolderBackup = GUICtrlCreateLabel("Locations of the Folder to be Backup:", 8, 80, 205, 19) GUICtrlSetFont($g_idFolderBackup, 10, 400, 0, "Calibri") GUICtrlSetResizing($g_idFolderBackup,$GUI_DOCKALL) Global $g_idBackupButton = GUICtrlCreateButton("Backup", 200, 144, 73, 25) Global $g_idExpandButton = GUICtrlCreateButton("+", 416, 112, 17, 17) GUICtrlSetResizing($g_idExpandButton,$GUI_DOCKALL) ;~ Add the first Browse/Field Controls AddField() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $g_idExpandButton If $g_iButtonCount <= 3 Then ExpandGUI() AddField() $g_iButtonCount += 1 Else MsgBox($MB_SYSTEMMODAL, "Notice", "Maximum Number of Locations Reached") EndIf Case $g_idBackupButton For $i = 0 To UBound($g_aBrowse) - 1 $g_sBrowseFields = GUICtrlRead($g_aBrowse[$i][1]) If $g_sBrowseFields = "" Then ContinueLoop MsgBox(4096, "$g_aBrowse[" & $i & "]", "$g_aBrowse[" & $i & "] = " & $g_sBrowseFields) Next Case Else ;~ 9 = First Browse/Field Control Id If $nMsg < 9 Then ContinueLoop ;~ Search $if $nMsg = Browse Control Id $g_sBrowseFolder = _ArraySearch($g_aBrowse, $nMsg, 0, 0, 0, 0, 1, 0) $g_sSelectFolder = FileSelectFolder("Select Folder", "") If @error Then ContinueLoop GUICtrlSetData($g_aBrowse[$g_sBrowseFolder][1], $g_sSelectFolder) EndSwitch WEnd Func ExpandGUI() Local $GuiPosition = WinGetPos($g_hMainForm) ; Get the GUI coördinates WinMove($g_hMainForm, "", $GuiPosition[0], $GuiPosition[1], $GuiPosition[2], $GuiPosition[3] + 30) EndFunc Func AddField() Local $iArrayAdd = _ArrayAdd($g_aBrowse, GUICtrlCreateButton("Browse", 8, $g_iTop, 65, 17) & "|" & GUICtrlCreateEdit("", 80, $g_iTop, 329, 17, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))) GUICtrlSetResizing($g_aBrowse[$iArrayAdd][0],$GUI_DOCKALL) GUICtrlSetResizing($g_aBrowse[$iArrayAdd][1],$GUI_DOCKAlL) $g_iTop += 28 EndFunc1 point -
keypress/mouse click emulation. Simple script.
FrancescoDiMuro reacted to JLogan3o13 for a topic
So, you're a dishonest web developer, hoping to cheat your boss. Shoot me your resume so I can ensure I never hire you.1 point -
Try this : #include <Constants.au3> #include <IE.au3> #include <Array.au3> Opt ("MustDeclareVars", 1) Local $oIE = _IECreate("https://www.hkab.org.hk/DisplayInterestSettlementRatesAction.do?lang=en") If Not IsObj ($oIE) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating IE object") Local $oFrame = _IEFrameGetObjByName ($oIE,"out") If Not IsObj ($oFrame) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error searching for frame") Local $oTDs = _IETagNameGetCollection ($oFrame, "td") If Not IsObj ($oTDs) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error gathering tag collection") Local $sValue For $oTD in $oTDs $sValue = _IEPropertyGet ($oTD, "innertext") If @error or $sValue = "" Then ContinueLoop If $sValue = "6 Months" Then $sValue = $oTD.nextElementSibling.innerText ExitLoop Endif Next MsgBox ($MB_SYSTEMMODAL,"",Number($sValue)) _IEQuit ($oIE)1 point
-
ControlSetText
spudw2k reacted to FrancescoDiMuro for a topic
@Rammanan Strange to hear since all the displayed data should be taken from a Database. EDIT: By the way, if the ControlSetText() function is working, you should try to send a change/update message to the control1 point -
Arranging XML File from one line into separate line
KickStarter15 reacted to Nine for a topic
The non-regexp way : #include <String.au3> Global Const $INDENT_SPACES = 3 Local $s = StringStripCR(FileRead ("File.xml")) Local $a = StringSplit(StringReplace ($s, "><", ">" & @LF & "<"), @LF) Local $Ind = -1 For $i = 1 to $a[0] if StringLeft ($a[$i],2) = "</" Then $Ind -= 1 ConsoleWrite (_StringRepeat(" ",$Ind*$INDENT_SPACES) & $a[$i] & @CRLF) if not StringInStr ($a[$i],"</") Then $Ind += 1 Next1 point -
Arranging XML File from one line into separate line
KickStarter15 reacted to Deye for a topic
@Making the zigzag tied it is perhaps better to begin the encounter with the last line .. #include <String.au3> #include <File.au3> Global Const $INDENT_SPACES = 3 Local $Xml = FileRead("file.xml"), $sFilePath = @ScriptDir & "\xml_test.xml", $hFileOpen = FileOpen($sFilePath, 2), $Ind = 0 Local $a = StringRegExp(StringRegExpReplace($Xml, '><', ">" & @LF & "<"), '<.*', 3) For $i = UBound($a) - 1 To 0 Step -1 If Not StringRegExp($a[$i], "^\<.*\<") Then If StringRegExp($a[$i], "^\</") Then $a[$i] = _StringRepeat(" ", $Ind * $INDENT_SPACES) & $a[$i] $Ind += 1 Else $Ind -= 1 $a[$i] = _StringRepeat(" ", $Ind * $INDENT_SPACES) & $a[$i] EndIf Else $a[$i] = _StringRepeat(" ", $Ind * $INDENT_SPACES) & $a[$i] EndIf Next _FileWriteFromArray($hFileOpen, $a) FileClose($hFileOpen) Run("notepad.exe " & $sFilePath) Deye1 point -
Arranging XML File from one line into separate line
KickStarter15 reacted to mikell for a topic
Formerly I made this snippet for personal use. No warranty ! It can work... according on its mood at this moment $s = FileRead("file.xml") Msgbox(0,"test", _regex($s)) ;ConsoleWrite(_regex($s)) Func _regex($xml) Local $indent = "" While 1 $xml = StringRegExpReplace($xml, '(?s)((?<!\t)<(\S+)(?:\sxsi:[^>]+)?>.*?</\2>)', @crlf & $indent & '$1' ) $xml = StringRegExpReplace($xml, '.*>\K(</[^>]+>)', @crlf & $indent & '$1') If @extended = 0 Then Exitloop $indent &= @tab Wend $str = StringRegExpReplace($xml, '\R+', @crlf) Return $str EndFunc1 point