Leaderboard
Popular Content
Showing content with the highest reputation on 09/22/2012 in all areas
-
Restricting the minimum and maximum sizes of a GUI.
Professor_Bernd and one other reacted to guinness for a topic
At some point we've all seen the example for WM_GETMINMAXINFO floating around the forum, in regards to restricting the size of the GUI. I therefore decided to have a look at this and see if it could be rearranged to use structures and code already predefined in AutoIt and the UDFs. Sometimes users like to duplicate variables that may already exist in WindowsConstants.au3 or StructureConstants.au3 and it can cause problems down the line if the variable values change. You never know $GUI_EVENT_CLOSE (-3) might change to -99 one day, so this is why 'magic numbers' are bad to use in examples. So having read about WM_GETMINMAXINFO on MSDN, the structure that was required turned out to be tagMINMAXINFO, which was made up of 5 tagPOINT structures (long X;long Y;) strung together. So I created the following code below and will probably propose that the tagMINMAXINFO structure be added to the AutoIt UDFs. So my questions is: Does the structure look correct? Or should I use a different approach? Any feed back is much appreciated. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <Windowsconstants.au3> ; MINMAXINFO Struct >> http://msdn.microsoft.com/en-us/library/windows/desktop/ms632605(v=vs.85).aspx ; It uses a $tagPOINT structure which is long X; long Y; Global Const $tagMINMAXINFO = "struct; long ReservedX;long ReservedY;long MaxSizeX;long MaxSizeY;long MaxPositionX;long MaxPositionY;" & _ "long MinTrackSizeX;long MinTrackSizeY;long MaxTrackSizeX;long MaxTrackSizeY; endstruct" ; GUI API for setting the minimum an maximum sizes of the GUI. These don't need to be called by the end user, but rather use _GUISetSize(). Global Enum $__iMinSizeX, $__iMinSizeY, $__iMaxSizeX, $__iMaxSizeY, $__iGUISizeMax Global $__vGUISize[$__iGUISizeMax] Example() Func Example() ; Create a resizable GUI. Local $hGUI = GUICreate('', Default, Default, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) GUISetState(@SW_SHOW, $hGUI) ; Set the minimum and maximum sizes of the GUI. _GUISetSize(150, 150, 500, 500) ; Register the WM_GETMINMAXINFO message. GUIRegisterMsg($WM_GETMINMAXINFO, 'WM_GETMINMAXINFO') While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example Func _GUISetSize($iMinWidth, $iMinHeight, $iMaxWidth, $iMaxHeight) $__vGUISize[$__iMinSizeX] = $iMinWidth $__vGUISize[$__iMinSizeY] = $iMinHeight $__vGUISize[$__iMaxSizeX] = $iMaxWidth $__vGUISize[$__iMaxSizeY] = $iMaxHeight EndFunc ;==>_GUISetSize Func WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam) ; Original idea by Zedna & updated by guinness 21/09/12. #forceref $hWnd, $iMsg, $wParam Local $tMINMAXINFO = DllStructCreate($tagMINMAXINFO, $lParam) DllStructSetData($tMINMAXINFO, 'MinTrackSizeX', $__vGUISize[$__iMinSizeX]) DllStructSetData($tMINMAXINFO, 'MinTrackSizeY', $__vGUISize[$__iMinSizeY]) DllStructSetData($tMINMAXINFO, 'MaxTrackSizeX', $__vGUISize[$__iMaxSizeX]) DllStructSetData($tMINMAXINFO, 'MaxTrackSizeY', $__vGUISize[$__iMaxSizeY]) EndFunc ;==>WM_GETMINMAXINFO2 points -
String Regular Expression Tester V2
jvanegmond reacted to Szhlopp for a topic
Since there are WAY to many posts on how to SRE something I thought I would create a nice little tester. This thing does SRE and SRER. Loads files to test. Gets internet content to test. And more! Here it is: SRETesterV2.1.au3 Prev DL - 211 Enjoy!1 point -
Fast Array Write To Excel
abberration reacted to Bowmore for a topic
I have some scripts that use Excel to present the result of data validation tests and I was becoming a little frustrated at the length of time it was taking to write the data to excel, using _ExcelWriteSheetFromArray() function in the Excel.au3 UDF. So I thought I'd take a look and see if I could improve on it's performance. This was the result. This new function is 200 to 300 times faster than _ExcelWriteSheetFromArray() for large arrays (20000 plus elements) and in the region of 100 times faster for small arrays. I have also included the option to write only part of the array to the spreadsheet as sometimes I do not need all of the array. _ExcelSheetWriteFromArray ; #FUNCTION# ==================================================================================================================== ; Name...........: _ExcelSheetWriteFromArray ; Description ...: Writes a 2D array, or part of, to a specified location in the active worksheet ; Syntax.........: _ExcelSheetWriteFromArray($oExcel, ByRef $aArray, $iExcelStartRow = Default, $iExcelStartCol = Default, $iArrayStartRow = Default, $iArrayStartCol = Default, $iArrayEndRow = Default, $iArrayEndCol = Default) ; Parameters ....: $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew() ; $aArray - The array ByRef to write data from (array is not modified) ; $iExcelStartRow - The spreadsheet row to start writing the array to, default is 1 ; $iExcelStartCol - The spreadsheet column to start writing the array to, default is 1 ; $iArrayStartRow - Start row index of array to start writing data from, default is 0 ; $iArrayStartCol - Start column index of array to start writing data from, default is 0 ; $iArrayEndRow - End row index of array to stop writing data from, default is Ubound($aArray) ; $iArrayEndCol - End column index of array to stop writing data from, default is Ubound($aArray,2) ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error on errors: ; |@error=1 - Excel object does not exist ; |@error=2 - Not a 2D array ; |@error=3 - End row greater than start row ; |@error=4 - End col greater than start col ; Author ........: Bowmore ; Modified.......: ; Remarks .......: Only 2D arrays are currently handeled. Maxim cell content length is 255 characters ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ExcelSheetWriteFromArray($oExcel, ByRef $aArray, $iExcelStartRow = Default, $iExcelStartCol = Default, $iArrayStartRow = Default, $iArrayStartCol = Default, $iArrayEndRow = Default, $iArrayEndCol = Default) Local $iExcelEndRow = 1 Local $iExcelEndCol = 1 If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If UBound($aArray, 0) <> 2 Then Return SetError(2, 0, 0) If $iExcelStartRow = Default Then $iExcelStartRow = 1 If $iExcelStartCol = Default Then $iExcelStartCol = 1 If $iArrayStartRow = Default Then $iArrayStartRow = 0 If $iArrayStartCol = Default Then $iArrayStartCol = 0 If $iArrayEndRow = Default Then $iArrayEndRow = UBound($aArray) - 1 If $iArrayEndCol = Default Then $iArrayEndCol = UBound($aArray, 2) - 1 If $iExcelStartRow < 1 Then $iExcelStartRow = 1 If $iExcelStartCol < 1 Then $iExcelStartCol = 1 If $iArrayStartRow < 0 Then $iArrayStartRow = 0 If $iArrayStartCol < 0 Then $iArrayStartCol = 0 If $iArrayEndRow < $iArrayStartRow Then Return SetError(3, 1, 0) If $iArrayEndCol < $iArrayStartCol Then Return SetError(4, 1, 0) $iExcelEndRow = $iExcelStartRow + $iArrayEndRow - $iArrayStartRow $iExcelEndCol = $iExcelStartCol + $iArrayEndCol - $iArrayStartCol ; Check if only part of the array is to written to the speadsheet If $iArrayStartRow <> 0 Or $iArrayStartCol <> 0 Or $iArrayEndRow <> UBound($aArray) - 1 Or $iArrayEndCol = UBound($aArray, 2) - 1 Then ;Copy specified array range to a temporary array Local $aTemp[$iArrayEndRow - $iArrayStartRow + 1][$iArrayEndCol - $iArrayStartCol + 1] Local $iRow = 0 Local $iCol = 0 For $i = $iArrayStartRow To $iArrayEndRow $iCol = 0 For $j = $iArrayStartCol To $iArrayEndCol $aTemp[$iRow][$iCol] = $aArray[$i][$j] $iCol += 1 Next $iRow += 1 Next With $oExcel.ActiveSheet .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).Select .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).value = $oExcel.Application.WorksheetFunction.Transpose($aTemp) EndWith Else With $oExcel.ActiveSheet .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).Select .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).value = $oExcel.Application.WorksheetFunction.Transpose($aArray) EndWith EndIf EndFunc ;==>_ExcelSheetWriteFromArray Simple Speed Test _ExcelSheetWriteFromArray #include <excel.au3> Test_Main() Func Test_Main() Local $sXlsFile1 = @ScriptDir & "Test1.xls" Local $sXlsFile2 = @ScriptDir & "Test2.xls" Local $oExcel = 0 Local $Tim = 0 Local $aData[5000][10] For $i = 0 To 4999 $aData[$i][0] = "Y" $aData[$i][1] = "DATA_TEST_ROW_0" & StringFormat("%03i", $i) $aData[$i][2] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ultrices est varius elit consequat sollicitudin mollis libero ultrices. Quisque lobortis lorem quis nunc vestibulum tincidunt. Duis eget urna sapien, nec egestas purus. Fusce massa nunc." $aData[$i][3] = $i * 10 $aData[$i][4] = $i * 100 $aData[$i][5] = $aData[$i][3] / $aData[$i][4] $aData[$i][6] = "Pass" $aData[$i][7] = @YEAR & "-" & @MON & "-" & @MDAY & "T" & @HOUR & ":" & @MIN $aData[$i][8] = "FAIL" $aData[$i][9] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ultrices est varius elit consequat sollicitudin mollis libero ultrices. Quisque lobortis lorem quis nunc vestibulum tincidunt. Duis eget urna sapien, nec egestas purus. Fusce massa nunc." Next ; Speed Test of new function $oExcel = _ExcelBookNew(0) $Tim = TimerInit() _ExcelSheetWriteFromArray($oExcel, $aData) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : TimerDiff($Tim) = ' & TimerDiff($Tim) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _ExcelBookSaveAs($oExcel, $sXlsFile1) _ExcelBookClose($oExcel, 0, 0) ; Speed Test of old function $oExcel = _ExcelBookNew(0) $Tim = TimerInit() _ExcelWriteSheetFromArray($oExcel, $aData) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : TimerDiff($Tim) = ' & TimerDiff($Tim) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _ExcelBookSaveAs($oExcel, $sXlsFile2) _ExcelBookClose($oExcel, 0, 0) EndFunc ;==>Test_Main ; #FUNCTION# ==================================================================================================================== ; Name...........: _ExcelSheetWriteFromArray ; Description ...: Writes a 2D array, or part of, to a specified location in the active worksheet ; Syntax.........: _ExcelSheetWriteFromArray($oExcel, ByRef $aArray, $iExcelStartRow = Default, $iExcelStartCol = Default, $iArrayStartRow = Default, $iArrayStartCol = Default, $iArrayEndRow = Default, $iArrayEndCol = Default) ; Parameters ....: $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew() ; $aArray - The array ByRef to write data from (array is not modified) ; $iExcelStartRow - The spreadsheet row to start writing the array to, default is 1 ; $iExcelStartCol - The spreadsheet column to start writing the array to, default is 1 ; $iArrayStartRow - Start row index of array to start writing data from, default is 0 ; $iArrayStartCol - Start column index of array to start writing data from, default is 0 ; $iArrayEndRow - End row index of array to stop writing data from, default is Ubound($aArray) ; $iArrayEndCol - End column index of array to stop writing data from, default is Ubound($aArray,2) ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error on errors: ; |@error=1 - Excel object does not exist ; |@error=2 - Not a 2D array ; |@error=3 - End row greater than start row ; |@error=4 - End col greater than start col ; Author ........: Bowmore ; Modified.......: ; Remarks .......: Only 2D arrays are currently handeled. Maxim cell content length is 255 characters ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ExcelSheetWriteFromArray($oExcel, ByRef $aArray, $iExcelStartRow = Default, $iExcelStartCol = Default, $iArrayStartRow = Default, $iArrayStartCol = Default, $iArrayEndRow = Default, $iArrayEndCol = Default) Local $iExcelEndRow = 1 Local $iExcelEndCol = 1 If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If UBound($aArray, 0) <> 2 Then Return SetError(2, 0, 0) If $iExcelStartRow = Default Then $iExcelStartRow = 1 If $iExcelStartCol = Default Then $iExcelStartCol = 1 If $iArrayStartRow = Default Then $iArrayStartRow = 0 If $iArrayStartCol = Default Then $iArrayStartCol = 0 If $iArrayEndRow = Default Then $iArrayEndRow = UBound($aArray) - 1 If $iArrayEndCol = Default Then $iArrayEndCol = UBound($aArray, 2) - 1 If $iExcelStartRow < 1 Then $iExcelStartRow = 1 If $iExcelStartCol < 1 Then $iExcelStartCol = 1 If $iArrayStartRow < 0 Then $iArrayStartRow = 0 If $iArrayStartCol < 0 Then $iArrayStartCol = 0 If $iArrayEndRow < $iArrayStartRow Then Return SetError(3, 1, 0) If $iArrayEndCol < $iArrayStartCol Then Return SetError(4, 1, 0) $iExcelEndRow = $iExcelStartRow + $iArrayEndRow - $iArrayStartRow $iExcelEndCol = $iExcelStartCol + $iArrayEndCol - $iArrayStartCol ; Check if only part of the array is to written to the speadsheet If $iArrayStartRow <> 0 Or $iArrayStartCol <> 0 Or $iArrayEndRow <> UBound($aArray) - 1 Or $iArrayEndCol = UBound($aArray, 2) - 1 Then ;Copy specified array range to a temporary array Local $aTemp[$iArrayEndRow - $iArrayStartRow + 1][$iArrayEndCol - $iArrayStartCol + 1] Local $iRow = 0 Local $iCol = 0 For $i = $iArrayStartRow To $iArrayEndRow $iCol = 0 For $j = $iArrayStartCol To $iArrayEndCol $aTemp[$iRow][$iCol] = $aArray[$i][$j] $iCol += 1 Next $iRow += 1 Next With $oExcel.ActiveSheet .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).Select .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).value = $oExcel.Application.WorksheetFunction.Transpose($aTemp) EndWith Else With $oExcel.ActiveSheet .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).Select .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).value = $oExcel.Application.WorksheetFunction.Transpose($aArray) EndWith EndIf EndFunc ;==>_ExcelSheetWriteFromArray1 point -
how do you change the color of a button
abberration reacted to guinness for a topic
For those of you that don't know where Trac is situated, visit this link: #3761 point -
Aye, my code works perfectly now. Seems instant for me. I will have a loop at Spiff59's link to see if its any different. In a totally different note, I have found that the place where I read stuff into my other arrays have changed stuff. So I need to create a new function that figures out why and what and where.1 point
-
Or, don't load the files into your array in the first place. There are multiple versions of a recursive _FileListToArray() that allow for excluding files using a parameter with wildcards such as: " *.db;*.sfv;*.log;*" This is a small, fast one I often use: Melba has a larger version that has subfolder depth and sort parameters that is popular. You'll find a dozen versions with the exclusion option if you search the Examples forum... Edit: Most of these also allow multiple "include" strings with wildcards allowed. So, between the include and exclude parameters, you can pretty much tailor your list to what you want. The functions all also have a parameter to disable recursive folder searching (typically the default) when it is not required.1 point
-
This script crashes after 2 houers or so, i dont know why
Makaveli10a reacted to BrewManNH for a topic
Your problem is you're recursing from one function to another and then back to the original function, you can only do that about 1800 times before the script crashes. You need to figure out how to do what you need without functions calling back to their original calling function.1 point -
This script crashes after 2 houers or so, i dont know why
Makaveli10a reacted to Jos for a topic
See my last comment in previous post and get us some exact information to work with as that makes it soo much easier to help people1 point -
This script crashes after 2 houers or so, i dont know why
Makaveli10a reacted to Jos for a topic
No intention of running it, so what is the error you get or what is happening at that time? Are you getting a stack overflow as it looks like you keep on calling Func's without ever returning from them?1 point -
@gil900 I'm not going to use the _IE UDF as long as in my opinion the browser sucks and It's not a furtive way to do it, which also sucks. I will use the WinHTTP UDF or the curl exe, or in "pure" autoit. Br, FireFox.1 point