Leaderboard
Popular Content
Showing content with the highest reputation on 10/21/2015 in all areas
-
Maps 101: All you need to know about them!
SkysLastChance and one other reacted to TheDcoder for a topic
Hello Again! I previously stumbled upon a topic asking for maps datatype's instructions... I too wasn't sure what a map is until I tried it... So I am making this topic to help other newbies (and some oldbies) better understand the Maps datatype of AutoIt! Lets start! A Note for Readers The maps datatype is still in development and is currently in Alpha Stage (More Risky than Beta) and its unstable, so AutoIt can crash indefinably while using Maps! I can't guarantee if this will be implemented in stable versions, this is a fairly new thing to AutoIt coders & in my honest opinion I don't see any use for it Maps are the best datatype in AutoIt, Very Useful ... Not hurting anyone though . Also the maps datatype is DISABLED IN STABLE VERSIONS, So you need to install the latest beta version of AutoIt to make maps work . If you find any bugs while using a map, please report it in the Official Bug Tracker Introduction To Maps Maps are just like arrays, instead they use "keys" to access elements inside them... A key can be either a string or an integer (Other datatypes work too but they are converted to a integer [Equivalent to Int($vKey)] before assignment [Source]). Although Integers don't represent the order of elements in a map unlike in an array... Declaring Maps Its similar to declaring an Array: ; This is the only way to declare a map ; You must have a declarative keyword like Dim/Global/Local before the declaration unless the map is assigned a value from a functions return Local $mMap[] ; Don't insert any numbers or strings it! Simple, Isn't it? Using Maps Using maps is similar to arrays (again!): Local $mMap[] ; Lets declare our map first! ; Adding data to maps is easy... ; This is our key ; | ; v $mMap["Key"] = "Value" ; <--- And our value! ; A key is Case-Sensitive meaning "Key" is not same as "key"! $mMap["key"] = "value" ; Not the same as $mMap["Key"]! ; There are 2 different ways to access an element in a map $mMap["Key"] ; 1st Method $mMap.Key ; 2nd Method Enumerating Maps Its quite easy to enumerate through arrays but what about maps? how can I enumerate through them!? #include <MsgBoxConstants.au3> ; Lets create our map first Local $mMap[] ; Lets add some information to the map, feel free to modify & add new elements $mMap["Name"] = "Damon Harris" $mMap["Alias"] = "TheDcoder" $mMap["Gender"] = "Male" $mMap["Age"] = 14 $mMap["Location"] = "India" $aMapKeys = MapKeys($mMap) ; MapKeys function returns all the keys in the format of an array Local $sProfile = "Profile of " & $mMap["Name"] & ':' & @CRLF ; We will use this string later For $vKey In $aMapKeys ; We use this to get the keys in a map :) $sProfile &= @CRLF & $vKey & ': ' & $mMap[$vKey] ; Add some details to the profile string using our map! Next MsgBox($MB_ICONINFORMATION + $MB_OK, "Profile", $sProfile) ; Finally display the profile :) It is easy as always Multi-Dimensional Maps Now now... I know that you are a little confused that how can an multi-dimensional maps exist... Although I am not 100% sure if its called that but lets continue: #include <MsgBoxConstants.au3> ; Multi-Dimensional maps are just maps in a map Local $mMapOfMapsvilla[] ; This map will store an other map Local $mParkMap[] ; This Park map will be inserted in the Mapsvilla's map :P $mMapOfMapsvilla["Map Item 1"] = "Town Hall" $mMapOfMapsvilla["Map Item 2"] = "Police Station" $mMapOfMapsvilla["Map Item 3"] = "Shopping Mall" $mMapOfMapsvilla["Map Item 4"] = "Residential Area" $mMapOfMapsvilla["Map Item 5"] = "Park" $mParkMap["Map Item 1"] = "Cottan Candy Stand" $mParkMap["Map Item 2"] = "Public Toilet" $mParkMap["Map Item 3"] = "Woods" $mMapOfMapsvilla.Park = $mParkMap MsgBox($MB_OK, "Map Location", $mMapOfMapsvilla["Map Item 1"]) ; Will display Town Hall MsgBox($MB_OK, "Map Location", $mMapOfMapsvilla.Park["Map Item 1"]) ; Will display Cottan Candy Stand I am sure its easy for you to understand now Frequently Asked Questions (FAQs) & Their answers Q #1. Help! My code does not respond to anything (or) I get an "Variable subscript badly formatted" error on the line of declaration... A. DONT USE F5 or Go, Instead use Alt + F5 or Tools -> Beta Run in SciTE (Make sure that you have Beta installed) Q #2. Why are you using "m" in-front of every map variable? A. Best coding Practices: Names of Variables Q #3. What are "Elements" which you mention frequently??? A. This is a newbie question (I have no intention of insulting you ), so I guess you are new to programming. "Elements" are data slots inside a Map (or an Array), you can imagine elements as individual variable which are stored in a Map. You can access them using "keys", Please refer to "Introduction to Maps" section at the starting of this post Q #4. Are Maps faster than Arrays? A. You need to understand that Maps have different purpose than Arrays. Maps are designed to store data dynamically (like storing information for certain controlIDs of GUI) and Arrays are designed to store data in a order (for instance, Storing every character of a string in an element for easy access). If you still want to know then if Maps are faster, then the answer is maybe... Maps are *supposed* (I am not sure ) to be faster in addition of elements (while Arrays are painfully slow while adding or removing elements). Here (Post #24) is a benchmark (Thanks kealper! ) More FAQs coming soon! Feel free to ask a question in the mean while2 points -
Unzip your files without progress bar
ViciousXUSMC reacted to topten for a topic
Very simple: I had seen many examples of unzipping files (Zip) archive, but most of those example where using either some external .dll or are performing the job with the progress bar. Here is a small example how you can unzip your files without any external libraries and without any progress bar $ZipFile5="C:\file.zip" $ExtractTo5="C:\folder" $objShell5 = ObjCreate ("Shell.Application") $FilesInZip5=$objShell5.NameSpace($ZipFile5).items $objShell5.NameSpace($ExtractTo5).CopyHere($FilesInZip5,0x4)Enjoy1 point -
Help Click only inside GUI
Samir90 reacted to JLogan3o13 for a topic
@Samir90, please do not post in more than one forum. Thread locked, as it is basically the exact same as your other post (to which you're already receiving answers!) In the future, if you feel you accidentally posted in the wrong forum, please MP a member of the Mod team and ask that it be moved.1 point -
You get the ID if the control you want to click, you can do that with window info tool. Nine times out of ten, it does not matter if the window containing the control is behind another or even minimized, it will still click it. You need to look at the example again and adapt it to your real life problem. Posting that real life problem with links, names of applications etcetera, will get you better help that vague "let's says".1 point
-
1 point
-
Need help Guys
Samir90 reacted to JLogan3o13 for a topic
@Samir90 in the future please surround your code with code tags, I have done so for you this time. Also, please give thought to giving meaningful titles to your post, this is General Help and Support, everyone needs help.1 point -
I've found the cause of the issue of previous post (somewhat subtle). (I post here since maybe it can be handy for someone sometime) In this little standalone script (used as a simplified reproducer) is clearly visible the cause of the problem: There are an input box and a Label; When you type into the Input box, keystrokes are copied from the InputBox to the Label. There is also an GUIRegisterMsg() to catch the WM_CTLCOLORSTATIC signal (this signal is fired when the Label content is modified). Now, since the Label is modified also within the _ WM_CTLCOLORSTATIC function, this triggers a closed loop, causing the script to stuck, and the GUICtrlSetBkColor Label going crazy. The solution (or workaround) I've found is visible in the script within the second function _WM_CTLCOLORSTATIC_ok(). Comment out line the line GUIRegisterMsg($WM_CTLCOLORSTATIC, '_WM_CTLCOLORSTATIC') and use line GUIRegisterMsg($WM_CTLCOLORSTATIC, '_WM_CTLCOLORSTATIC_ok') instead to see the script working ok. #include <WindowsConstants.au3> #include <WinAPI.au3> $hwnd = GUICreate("test",220, 60) $hInput = GUICtrlCreateInput("", 10, 5, 20, 20) $iLabel = GUICtrlCreateLabel("", 10, 30, 200, 20, -1, 0x00020000) GUISetState() GUIRegisterMsg($WM_CTLCOLORSTATIC, '_WM_CTLCOLORSTATIC') ; Triggered when Label changes NOT OK ; GUIRegisterMsg($WM_CTLCOLORSTATIC, '_WM_CTLCOLORSTATIC_ok') ; Triggered when Label changes OK While 1 If GUIGetMsg() = -3 Then ExitLoop $key = GUICtrlRead($hInput) If $key Then ; following change to the label will trigger the event $WM_CTLCOLORSTATIC GUICtrlSetData($iLabel, GUICtrlRead($iLabel) & $key) ; --+ GUICtrlSetData($hInput, "") ; | $key = "" ; | EndIf ; | WEnd ; | GUIDelete() ; | Exit ; | ; | ; This function is problematic | Func _WM_CTLCOLORSTATIC($hwnd, $iMsg, $wParam, $iParam) ; <----+---------------------------+ #forceref $hWnd, $iMsg ; | Local $iID = _WinAPI_GetDlgCtrlID($iParam) ; proble due to | Switch _WinAPI_GetDlgCtrlID($iParam) ; closed loop | Case $iLabel ; | $iCol = Random(0, 16777215, 1) ; | GUICtrlSetBkColor(_WinAPI_GetDlgCtrlID($iParam), $iCol) ; - trigger fired again -+ Return EndSwitch Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_CTLCOLORSTATIC ; This function works OK Func _WM_CTLCOLORSTATIC_ok($hwnd, $iMsg, $wParam, $iParam) #forceref $hWnd, $iMsg Local Static $bTriggered = False Local $iID = _WinAPI_GetDlgCtrlID($iParam) ; from handle to ID Switch $iID Case $iLabel If Not $bTriggered Then ; to prevent the triggering of the "closed loop" $iCol = Random(0, 16777215, 1) $bTriggered = True ; defuse next trigger GUICtrlSetBkColor($iID, $iCol) Return EndIf $bTriggered = False ; ok trigger loop was defused EndSwitch Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_CTLCOLORSTATIC_ok p.s. Here is the working version of the scripts from post #36 Main.au3 ; Main #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <array.au3> ; Array to hold data - ControlIDs of inputs, labels and current colours Global $aData[101] ; Create GUI Global $hGUI = GUICreate("Label_Master", 510, 510) Global $hDelay, $iDelay = 10 ; Create labels and hidden inputs For $i = 0 To 9 For $j = 0 To 9 $iIndex = $j + ($i * 10) + 1 $aData[$iIndex] = GUICtrlCreateLabel("", 10 + ($j * 50), 10 + ($i * 50), 40, 40) ; $aData[$iIndex][0] = GUICtrlGetHandle($aData[$iIndex][1]) GUICtrlSetBkColor(-1, 0x888888) GUICtrlSetFont(-1, 12) Next Next $aData[0] = UBound($aData) - 1 GUISetState() ; Launch 100 child processes - each will change the colour of one label For $iIndex = 1 To $aData[0] ; Pass parameters to the child process ; First parameter id the handle of the control ; second parameter id the handle of the window Run(@AutoItExe & " .\child.au3 " & $aData[$iIndex] & " " & $hGUI) Next GUIRegisterMsg($WM_CTLCOLORSTATIC, '_WM_CTLCOLORSTATIC') MsgBox(0, 0, "Pausa") GUIDelete() Exit Func _WM_CTLCOLORSTATIC($hwnd, $iMsg, $wParam, $iParam) #forceref $hWnd, $iMsg, $wParam Local Static $bTriggered = False Local $iID = _WinAPI_GetDlgCtrlID($iParam) ; from handle to ID Switch $iID Case $aData[1] To $aData[$aData[0]] If Not $bTriggered Then ; to prevent the triggering of the "closed loop" $bTriggered = True ; defuse next trigger GUICtrlSetBkColor($iID, Random(0, 16777215, 1)) Return EndIf $bTriggered = False ; ok trigger loop was defused EndSwitch Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_CTLCOLORSTATIC child.au3 ; Child If $CmdLine[0] = 0 Then Exit ; Read parameters $iID = $CmdLine[1] ; ID of the control to bind to $hParentWin = HWnd($CmdLine[2]) ; parent window's handle Sleep(6000) ; wait a few seconds for all other processes to start before beginning to work all together ; Randomize the random process SRandom(@MSEC) ; Randomize the Random seed for each child or we get the same colour for each! ; endless cycle While WinExists(HWnd($hParentWin)) ; when parent window will close, then this process will close itself ; Tell master ; ControlSetText($hParent, "", $iID, Chr(Random(64, 127, 1))) ; with direct $iID it doesn't works. ?? ControlSetText($hParentWin, "", "[ID:" & $iID & "]", Chr(Random(64, 127, 1))) ; the following delay is for avoiding the overload of the window's signals queue ; when there are many child procese running at the same time. ; Random's Min and Max values should be calibrated accordingly. Sleep(Random(500, 1000, 1)) ; from half to 1 second delay WEnd1 point
-
Named pipes, stdout, memory sharing, mailslots, the list of interprocess communication goes on and is abundant across the forum. You, must translate them.1 point
-
so you should Wait I publish today a new version ...minimum 10 hour.1 point
-
here is fix. Func _XMLCreateFile($sXML_FileFullPath, $sRoot, $bUTF8 = False, $iDOM_Version = Default) ; Error handler, automatic cleanup at end of function Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_UserFunction()) #forceref $oXML_COM_ErrorHandler ; TODO $bUTF8 = False -- change to $iEncoding = $FO_UTF8_NOBOM If Not ($sXML_FileFullPath <> "" Or IsString($sXML_FileFullPath)) Then Return SetError($XMLWRAPPER_ERROR_PARAMETER, $XMLWRAPPER_EXT_DEFAULT, $XMLWRAPPER_RESULT_FAILURE) ElseIf FileExists($sXML_FileFullPath) Then Return SetError($XMLWRAPPER_ERROR_SAVE, $XMLWRAPPER_EXT_GENERAL, $XMLWRAPPER_RESULT_FAILURE) EndIf Local $oXmlDoc = _XML_CreateDOMDocument($iDOM_Version) If @error Then Return SetError(@error, @extended, $XMLWRAPPER_RESULT_FAILURE) Local $oProcessingInstruction = $oXmlDoc.createProcessingInstruction('xml', 'version="1.0"' & (($bUTF8) ? 'encoding="UTF-8"' : '')) If $oXmlDoc.parseError.errorCode Then Return SetError($XMLWRAPPER_ERROR_PARSE, $oXmlDoc.parseError.errorCode, $XMLWRAPPER_RESULT_FAILURE) EndIf $oXmlDoc.appendChild($oProcessingInstruction) If @error Then Return SetError($XMLWRAPPER_ERROR_NODEAPPEND, $NODE_PROCESSING_INSTRUCTION, $XMLWRAPPER_RESULT_FAILURE) Local $oXML_RootElement = $oXmlDoc.createElement($sRoot) $oXmlDoc.documentElement = $oXML_RootElement ; TODO use _XML_SaveToFile $oXmlDoc.save($sXML_FileFullPath) If @error Then Return SetError($XMLWRAPPER_ERROR_SAVE, $XMLWRAPPER_EXT_DEFAULT, $XMLWRAPPER_RESULT_FAILURE) If $oXmlDoc.parseError.errorCode Then Return SetError($XMLWRAPPER_ERROR_PARSE, $oXmlDoc.parseError.errorCode, $XMLWRAPPER_RESULT_FAILURE) EndIf Return SetError($XMLWRAPPER_ERROR_OK, $XMLWRAPPER_EXT_DEFAULT, $oXmlDoc) EndFunc ;==>_XMLCreateFile1 point
-
Why doent my sleep() work
K3STROS reacted to ViciousXUSMC for a topic
As Jos said. Bad Syntax. Break it down into it's pieces and then put them together. $iTime = Random(990, 1990, 1) Sleep($iTime) ;or Sleep(Random(990, 1990, 1))1 point -
Ah yes, you are right. That is for the account expiration. I'm not sure of a way to set an explicit expiration date. I think is just notes the last time the password was changed and compares it to the computer's security policy on maximum password age. Best I'm aware of is you can expire a password and then un-expire it. When you unexpire the account it will set then expiration date based on the policy (x many days old). See my post here for an example. https://www.autoitscript.com/forum/topic/91933-tickle-expired-passwords/?do=findComment&comment=661395 If someone else knows of a more elegant way to se an account's password expiration I'd be interested to know.1 point
-
hmmmm...after looking the function up in the help file you would have come up with something like this... #include <Array.au3> Global $aArray[35] For $i = 0 To 34 $aArray[$i] = "ex" & $i + 1 Next _arrayshuffle($aArray) _arraydisplay($aArray) kylomas1 point
-
Because you coded it wrong and it contains syntax errors. Jos1 point
-
1 point