Leaderboard
Popular Content
Showing content with the highest reputation on 03/15/2021 in all areas
-
2 points
-
!!! Argh..... AutoIt EDIT:2 points
-
Incremental search in owner and custom drawn ListViews
pixelsearch reacted to LarsJ for a topic
Incremental search is usually implemented by drawing the background of the substrings that matches the search string with a specific color eg. yellow. Incremental in this context means that the search is performed dynamically after each character while the search string is typed. In a listview this can be implemented by owner drawing through the LVS_OWNERDRAWFIXED flag and WM_DRAWITEM messages. (A custom drawn listview supports coloring of fields. However, the coloring works best for whole fields. This doesn't make it applicable to incremental search.) Inspiration for the example is found in these two questions: Search box for names and Search In ListView (Redraw with matching string). Examples The zip file below contains three examples. Listview items are strings of random characters with different lengths. In all examples a global $iItems = 1000 in top of script specifies the number of rows. There are no performance issues up till 10,000 rows. Note that the search is performed in an array and not directly in the listview. A regular expression can be entered in the search box. Search strings like "m........." with a varying number of dots will result in a varying number of matches. To keep it simple only one occurrence of the search string in each item is tested. As soon as one occurrence is found the search loop moves on to next item. 1) Incremental text search.au3 The first example is a simple demonstration of basic functionality: F3 and Shift+F3 can be used instead of Next and Prev buttons. 2) Show matching rows only.au3 An owner drawn listview can easily be combined with a virtual listview to extend the functionality of the incremental search. A virtual listview is especially interesting if you want to dynamically update the listview to only display the rows that matches the search string. Such an update is very fast in a virtual listview. This example is useful if the listview contains a set of file names and you are searching for a specific file eg. to open the file. In this situation you are probably not interested in the files that doesn't match. Because the listview only contains matching rows "Next match" and "Prev match" buttons are disabled. Clear the search field to display all items. 3) Standard search dialog.au3 The last example is a demonstration of a standard search dialog as the search box in Notepad. FindText function in comdlg32.dll creates the standard search box. The function is implemented as _WinAPI_FindTextDlg in WinAPIDlg.au3. In the Microsoft documentation you can read: Note that the FINDREPLACE structure and the buffer for the search string should be a global or static variable so it does not go out of scope before the dialog box closes. Because the FINDREPLACE structure is created as a local variable in _WinAPI_FindTextDlg it goes out of scope as soon as the function returns. This implementation of FindText is used in the example: ;Func _WinAPI_FindTextDlg($hOwner, $sFindWhat = '', $iFlags = 0, $pFindProc = 0, $lParam = 0) Func _WinAPI_FindTextDlgEx(ByRef $tFR, $hOwner, $sFindWhat = '', $iFlags = 0, $pFindProc = 0, $lParam = 0) $__g_pFRBuffer = __HeapReAlloc($__g_pFRBuffer, 2 * $__g_iFRBufferSize) If @error Then Return SetError(@error + 20, @extended, 0) DllStructSetData(DllStructCreate('wchar[' & $__g_iFRBufferSize & ']', $__g_pFRBuffer), 1, StringLeft($sFindWhat, $__g_iFRBufferSize - 1)) ;Local $tFR = DllStructCreate($tagFINDREPLACE) $tFR = DllStructCreate($tagFINDREPLACE) DllStructSetData($tFR, 'Size', DllStructGetSize($tFR)) DllStructSetData($tFR, 'hOwner', $hOwner) DllStructSetData($tFR, 'hInstance', 0) DllStructSetData($tFR, 'Flags', $iFlags) DllStructSetData($tFR, 'FindWhat', $__g_pFRBuffer) DllStructSetData($tFR, 'ReplaceWith', 0) DllStructSetData($tFR, 'FindWhatLen', $__g_iFRBufferSize * 2) DllStructSetData($tFR, 'ReplaceWithLen', 0) DllStructSetData($tFR, 'lParam', $lParam) DllStructSetData($tFR, 'Hook', $pFindProc) DllStructSetData($tFR, 'TemplateName', 0) Local $Ret = DllCall('comdlg32.dll', 'hwnd', 'FindTextW', 'struct*', $tFR) If @error Or Not $Ret[0] Then Local $Error = @error + 30 __HeapFree($__g_pFRBuffer) If IsArray($Ret) Then Return SetError(10, _WinAPI_CommDlgExtendedErrorEx(), 0) Else Return SetError($Error, @extended, 0) EndIf EndIf Return $Ret[0] EndFunc Then it's ensured that the local variable that is used for $tFR in the script, does not go out of scope, while the search box is open. ListviewIncrSearch.7z 1) Incremental text search.au3 2) Show matching rows only.au3 3) Standard Find text dialog.au3 DrawItem.au3 GuiListViewEx.au3 WinAPIDlgEx.au3 You need AutoIt 3.3.14 or later. Tested on Windows 7 32/64 bit and Windows XP 32 bit. Comments are welcome. Let me know if there are any issues. (Set tab width = 2 in SciTE to line up comments by column.) ListviewIncrSearch.7z1 point -
Oracle SQL db queries
TheXman reacted to Earthshine for a topic
First get one that works. Then learn how to construct the string programmatically i can’t be arsed to do it for you just because you don’t feel like doing development. You need to learn and nobody has your Oracle instance installed either1 point -
Oracle SQL db queries
TheXman reacted to Earthshine for a topic
see this website. Oracle connection strings - ConnectionStrings.com it always worked for me1 point -
_WinAPI_DragQueryFileEx()
pixelsearch reacted to jpm for a topic
Many thanks Fixed for the next beta Cheers1 point -
zPlayer - My own little audio/video player
CYCho reacted to pixelsearch for a topic
Hi CYCho In page 1 of this thread, Xandy indicated the issue he had while zPlayer is running, because he couldn't use anymore combinations of keys in his own windows (ctrl + right key for example) as they are used by HotKeySet in your script. I just experienced the same problem and could have written what he said : In the past, I already experienced 2 working solutions when facing this problem : 1) The use of Accelerator keys (just look at the help file, topic GUISetAccelerators) I have to paste here the beginning of what is written in the help file, as it's so well explained ! Accelerator keys are similar to HotKeys, but there are 2 important differences: - 1. They are only active when the GUI specified in the function is active which means that, unlike HotKeys, Accelerator keys will not interfere with other running applications. - 2. ... But as you got 4 different Gui's (main, playlist, video...) then I'm not really sure it's a solution adapted to your script (though I may be mistaken) 2) The second solution seems simpler. Here is your actual MyNext() function, triggered by ctrl + right arrow Func MyNext() ; Ctrl+Right Arrow to play the next file If $lPaused = True Then $lPaused = False GUICtrlSetImage($picPause, $picFolder & "Pause.jpg") EndIf $move = 1 EndFunc ;==>MyNext If you change this function to what follows, then the function will still be triggered by ctrl + right arrow when main or playlist are active... but now the user can also use ctrl + right arrow in his own windows (I just checked it again) because the function itself will send the hotkey when zPlayer (main or playlist) hasn't got the focus. As this solution often ends with bad sticky keys (it just happened to me several times) then _SendEx() instead of Send() solves totally the sticky keys problem. _SendEx() can be found on wiki AutoIt FAQ, but I paste it here too, below your function. Func MyNext() ; Ctrl+Right Arrow to play the next file HotKeySet("^{RIGHT}") ; deactivate the hotkey immediately $hWinActive = WinActive("[ACTIVE]") If $hWinActive = $winMain Or $hWinActive = $winListView Then If $lPaused = True Then $lPaused = False GUICtrlSetImage($picPause, $picFolder & "Pause.jpg") EndIf $move = 1 Else ; Send("^{RIGHT}") ; will often end with sticky keys _SendEx("^{RIGHT}") EndIf HotKeySet("^{RIGHT}", "MyNext") ; reactivate the hotkey at the very end of the function EndFunc ;==>MyNext Func _SendEx($ss, $warn = "") Local $iT = TimerInit() While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12") If $warn <> "" And TimerDiff($iT) > 1000 Then MsgBox($MB_TOPMOST, "Warning", $warn) EndIf Sleep(50) WEnd Send($ss) EndFunc;==>_SendEx I guess you'll have to add also the handle of the video window to the If $hWinActive... line (I didn't check on videos, only checked while main or playlist window were active and it worked fine) If you're ready to try this, I suggest you do it first on 1 function only (ctrl + right key for example) to test it well, then extend it to the 4 functions which use 2 keys only (ctrl + right, ctrl + left, ctrl + up, ctrl + down) . As you got plenty of others ctrl+alt+key (3 keys involved), then maybe it's not useful to include the "3 keys involved functions" in the change and you could let them as they are now. Hope it helps and good luck1 point -
Oracle SQL db queries
jaja714 reacted to FrancescoDiMuro for a topic
@jaja714 If you have any problem, don't be afraid to post a runnable script, so we can assist you more Good luck! EDIT: In fact, there are no examples with Oracle DB in the ADO Wiki section1 point -
ObjEvent tells Outlook to call a function named "oOL_" plus the name of the triggered event. Means: When the NewMailEx event gets triggered Outlook calls function "oOL_NewMaiLEventEx".1 point
-
How can I create a sizable GUI without a Close box?
pixelsearch reacted to CYCho for a topic
What an impressive and loving review! I know my code will look very much amateurish to experts like you. But i console myself thnking what the heck it works for me. I am still asking questions and reflect the solutions to my zPlayer, and I thank all the kndly forum members who willingly and patiently taught an ignorant novice. I have been taking this as my lifetime project hoping that it will keep me safe from, or at least delaty, dementia. Soon I'll be 78 and I am proud of myself for having a zeal to stay up into late hours of the evening looking at the code. You are the first to give a detailed review and even make suggestions for improvement. Many many thanks! I will reflect your suggestions in my next update in a couple of days time.1 point -
How can I create a sizable GUI without a Close box?
CYCho reacted to pixelsearch for a topic
Hi C. Y. Cho Thanks for keeping us updated. I just tested your last version 3.0.1.3 (dated march 14, 2021) great job ! Basically I don't think it's a mouse issue. Even if you click once on the child close button, wait 1 second and click again "on the same spot of the background where the child window was located" then this is what will happen : 1) If this second click is done on the desktop, the main GUI will still be visible 2) If this second click is done on a Window placed behind your main GUI (this is your case) then this Window will steal the focus and your main GUI will disappear. In this 2nd case, your main GUI isn't "minimized" or "hidden" and WinGetState shows it clearly (just tested) : $WIN_STATE_EXISTS (1) = Window exists $WIN_STATE_VISIBLE (2) = Window is visible $WIN_STATE_ENABLED (4) = Window is enabled $WIN_STATE_ACTIVE (8) = Window is active $WIN_STATE_MINIMIZED (16) = Window is minimized $WIN_STATE_MAXIMIZED (32) = Window is maximized Retrieving your main GUI state gives these results : * 23 if you force it to minimize (16 + 4 + 2 + 1) * 15 when it's active (8 + 4 + 2 + 1) * 7 when the other Window you clicked on stole the focus and your main Gui vanished (4 + 2 + 1) * 5 when you "really" hide it with a code like WinSetState($winMain, "", @SW_HIDE) (4 + 1) A solution to fix this is to set $WS_TOPMOST style to main GUI at line 89 (version 3.0.1.3) : ; $winMain = GUICreate("zPlayer by C. Y. Cho", $mainWidth, $mainHeight, $listLeft+$listWidth, $listHeight/2) $winMain = GUICreate("zPlayer by C. Y. Cho", $mainWidth, $mainHeight, $listLeft+$listWidth, $listHeight/2, -1, 0x0008) ; $WS_TOPMOST = 0x0008 But it all depends on you in case it bothers you to have the main GUI always on top, which means you'll have to minimize it with its button when needed. By the way, I detect a minor issue with the playlist window title : * Its title is "Playing in Sequential Mode..." when we 1st run the program (no .ini file yet) * Then we click on "Play in Shuffled Mode" in main gui... * ...which correctly changes the playlist window title to "Playing in Shuffled Mode..." * Now comes the problem : if we click on "Play in Sequential" in main gui... * ...then the playlist window title doesn't change and keeps saying "Playing in Shuffled Mode..." To fix this, adding a new line #888 solves it (tested) : Also I just read your resume in this link and bravo for what you did : so you retired from active duty in 2002 and "came from a sales career with no experience in programming, it was not an easy task." Impressive result, especially you had no experience in programming1 point -
How to detect when ConsoleWrite() invisible?
FrancescoDiMuro reacted to jchd for a topic
You can use a substitute to the standard ConsoleWrite to display text to a (or the) console. It will work the same way uncompiled (run from SciTE via F5), compiled for GUI or compiled to CUI. The only difference is when you compile for CUI, the standard ConsoleWrite function won't write to the same console. Just don't use it in this case and always use CW() in all cases. My functions convert and write Unicode (depending on the console default font set). If you wish to use this just set SciTE4AutoIt3 console setting to use Unicode. #AutoIt3Wrapper_Run_AU3Check=n #AutoIt3Wrapper_Change2CUI=n Func CW($s = "") (@Compiled ? _CUI_ConsoleWrite : _ConsoleWrite)($s) EndFunc ;==>CW Func _CUI_ConsoleWrite(ByRef $s) Local Static $hCon = __CUI_ConsoleInit() DllCall("kernel32.dll", "bool", "WriteConsoleW", "handle", $hCon, "wstr", $s & @LF, "dword", StringLen($s) + 1, "dword*", 0, "ptr", 0) Return EndFunc ;==>_CUI_ConsoleWrite Func __CUI_ConsoleInit() DllCall("kernel32.dll", "bool", "AllocConsole") Return DllCall("kernel32.dll", "handle", "GetStdHandle", "int", -11)[0] EndFunc ;==>__CUI_ConsoleInit ; Unicode-aware ConsoleWrite Func _ConsoleWrite($s) ConsoleWrite(BinaryToString(StringToBinary($s & @LF, 4), 1)) EndFunc ;==>_ConsoleWrite ConsoleWrite("First message"& @LF) CW("Hello World!" & @LF & "Γειά σου Κόσμε!") Sleep(2000) Last note: I set Au3Check to No because it doesn't recognize the ternay construct in CW() and barks at it. The interpreter is immune. You can use a classical If ... Then ... Else ... EndIf instead if you rely on Au3Check.1 point -
Today thanks to @Danyfirex help, and thanks to this topic, I was able to make better AcrobatReader Viewer. Quick example: #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Example() Func Example() ; This particular object is declared as ObjEvent() need to stored the Object, #forceref to avoid Au3Check warning. Local $oErrorHandler = ObjEvent("AutoIt.Error", _ErrFunc) #forceref $oErrorHandler ; Create a simple GUI for our output Local $hGUI = GUICreate("Embedded Web control Test", 640, 580, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN)) Local $oIE = ObjCreate("Shell.Explorer.2") Local $iID = GUICtrlCreateObj($oIE, 5, 5, 640 - 10, 580 - 10) #forceref $iID GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUISetState(@SW_SHOW) ;Show GUI Local $s_PDF_FileFullPath = FileOpenDialog("Choose PDF", "C:\Temp", "PDF Files(*.pdf)", 3) Local $oPDF If FileExists($s_PDF_FileFullPath) Then $oIE.navigate($s_PDF_FileFullPath) ;~ ObjName_FlagsValue($oIE) $oPDF = $oIE.document ; https://www.autoitscript.com/forum/topic/177368-how-to-get-reference-to-pdf-object-embeded-in-ie/?do=findComment&comment=1272692 ;~ ObjName_FlagsValue($oPDF) ;~ $oPDF.LoadFile($s_PDF_FileFullPath) $oPDF.GotoFirstPage ;~ $oPDF.SetZoom(200) ;~ $oPDF.SetZoom(20) $oPDF.SetLayoutMode('SinglePage') $oPDF.SetPageMode('none') $oPDF.SetShowToolbar(0) $oPDF.SetShowScrollbars(0) $oPDF.SetView('FitBH') $oPDF.SetViewScroll('FitBH',10) ;~ $oPDF.SetViewRect(100,100,100,100) ;~ $oPDF.SetCurrentHighlight(10,10,50,50) EndIf Local $a_Msg ; Loop until the user exits. While 1 $a_Msg = GUIGetMsg($GUI_EVENT_ARRAY) If $a_Msg[1] = $hGUI Then Switch $a_Msg[0] Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE ; , $GUI_EVENT_PRIMARYDOWN $oPDF.SetLayoutMode('SinglePage') $oPDF.SetPageMode('none') $oPDF.SetShowToolbar(0) $oPDF.SetShowScrollbars(0) $oPDF.SetView('FitBH') $oPDF.SetViewScroll('FitBH',10) ;~ $oPDF.SetViewRect(100,100,100,100) ;~ $oPDF.SetCurrentHighlight(10,10,50,50) EndSwitch EndIf WEnd GUIDelete() EndFunc ;==>Example ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc Func ObjName_FlagsValue(ByRef $oObj) Local $sInfo = '' $sInfo &= '+>' & @TAB & 'ObjName($oObj,1) {The name of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_NAME) & @CRLF ; HELPFILE REMARKS: Not all Objects support flags 2 to 7. Always test for @error in these cases. $sInfo &= '+>' & @TAB & 'ObjName($oObj,2) {Description string of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_STRING) If @error Then $sInfo &= '@error = ' & @error $sInfo &= @CRLF & @CRLF $sInfo &= '+>' & @TAB & 'ObjName($oObj,3) {The ProgID of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_PROGID) If @error Then $sInfo &= '@error = ' & @error $sInfo &= @CRLF & @CRLF $sInfo &= '+>' & @TAB & 'ObjName($oObj,4) {The file that is associated with the object in the Registry} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_FILE) If @error Then $sInfo &= '@error = ' & @error $sInfo &= @CRLF & @CRLF $sInfo &= '+>' & @TAB & 'ObjName($oObj,5) {Module name in which the object runs (WIN XP And above). Marshaller for non-inproc objects.} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_MODULE) If @error Then $sInfo &= '@error = ' & @error $sInfo &= @CRLF & @CRLF $sInfo &= '+>' & @TAB & 'ObjName($oObj,6) {CLSID of the object''s coclass} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_CLSID) If @error Then $sInfo &= '@error = ' & @error $sInfo &= @CRLF & @CRLF $sInfo &= '+>' & @TAB & 'ObjName($oObj,7) {IID of the object''s interface} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_IID) If @error Then $sInfo &= '@error = ' & @error $sInfo &= @CRLF & @CRLF MsgBox($MB_SYSTEMMODAL, "ObjName:", $sInfo) EndFunc ;==>ObjName_FlagsValue1 point
-
API Authentication Failed
FrancescoDiMuro reacted to TheXman for a topic
It's not a "late reply". It's an attempt to re-engage on a topic that you abandoned. I replied to your initial post the same day that you posted it, almost 3 weeks ago. Given that we may not be in the same country or time zone, I can understand a reply that takes a day or two, but 2.5 weeks is ridiculous. If this topic was as important as you say, notification or not, one would think that you would've checked to see if anyone had replied long before now. I don't have the patience to try to help people that don't promptly reply. There are plenty of others that may be able to help you. Hopefully, for your sake, one of them has more patience than I do and is willing to deal with your "sense of urgency". You're welcome.1 point -
Exit Register
Bilgus reacted to seadoggie01 for a topic
OnAutoItExitRegister is nice, but it doesn't quite hit the spot for me. What if I want to save and close an Excel document when the script ends? Then I have to make the document global (possibly the Excel object as well) and write a separate function. I'm lazy and don't like separate functions. Enter Sandman ExitRegister Register functions with parameters to be run on script exit. If you want to, you can even insert them at the beginning. For our Excel example: Now I can sleep easy knowing that Excel will be closed even if the workbook fails to be created and the script exits early. Documentation to come soon... I hope... 🤥 Updated with documentation. I forgot to mention, I only added 10 parameters for the exit functions, but his can be expanded very quickly, so let me know if you need more! I don't think I've ever used more than 10 parameters on a function (before now)1 point -
All Files Compression.zip Compression.au3 #include <WinAPI.au3> #include <Memory.au3> Example() Func Example() Local $FileOpenA , $FileOpenB , $BinaryA , $BinaryB , $NewSizeA , $NewSizeB $NewSizeA = CompressionA("Untitled.ico","Rxr.Rxr") $NewSizeB = Decompressing("Rxr.Rxr","Untitled2.ico") $FileOpenA = FileOpen("Untitled.ico",16) $FileOpenB = FileOpen("Untitled2.ico",16) $BinaryA = FileRead($FileOpenA) $BinaryB = FileRead($FileOpenB) if $BinaryA == $BinaryB Then MsgBox(0,"MSG","OK") FileClose($FileOpenA) FileClose($FileOpenB) EndFunc Func CompressionA($InFile,$OutFile = "Rxr.Rxr") Local $nBytes , $hFile , $FileSize , $FileStruct , $Remainder , $FileStructPtr Local $TempDataStructA,$ReturnSt , $NewSize , $hFileA , $hFileB , $RemainderSt Local $NuA , $NuB , $NuC $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf if $FileSize < 254 Then $RemainderSt = DllStructCreate("byte Count;byte[" & $FileSize & "]") DllStructSetData($RemainderSt,1,$FileSize) _WinAPI_ReadFile($hFileA,DllStructGetPtr($RemainderSt,2),$FileSize,$nBytes) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,($FileSize + 1)) Else $FileStruct = DllStructCreate("byte[" & $FileSize & "]") $FileStructPtr = DllStructGetPtr($FileStruct) _WinAPI_ReadFile($hFileA,$FileStructPtr,$FileSize,$nBytes) $Remainder = Mod($FileSize,254) if $Remainder Then $RemainderSt = DllStructCreate("byte Count;byte[" & $Remainder & "]") DllStructSetData($RemainderSt,1,$Remainder) _MemMoveMemory($FileStructPtr + ($FileSize - $Remainder),DllStructGetPtr($RemainderSt,2),$Remainder) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = ($Remainder + 1) Else $RemainderSt = DllStructCreate("byte Count") DllStructSetData($RemainderSt,1,0) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = 1 EndIf For $MovPos = 0 To ($FileSize - $Remainder) - 254 Step 254 $TempDataStructA = DllStructCreate("Byte[254]") _MemMoveMemory($FileStructPtr + $MovPos,DllStructGetPtr($TempDataStructA),254) $ReturnSt = CompressionB($TempDataStructA) _WinAPI_WriteFile($hFileB,DllStructGetPtr($ReturnSt),DllStructGetSize($ReturnSt),$nBytes) $NewSize += DllStructGetSize($ReturnSt) $NuA = "[ % " & StringLeft((($MovPos + 254) / ($FileSize - $Remainder) * 100),4) & " ]" $NuB = "[ File Size " & StringLeft((($MovPos + 254 + $Remainder) / 1024),4) & " KB ]" $NuC = "[ Compression Size " & StringLeft(($NewSize / 1024),4) & " KB ]" ToolTip( $NuA & " " & $NuB & " " & $NuC , 100, 100) Next EndIf _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Func CompressionB($TempDataStructA) Local $TempDataStructB = DllStructCreate( "Byte[254]" ) Local $TempDataStructC = DllStructCreate( "Byte[254]" ) Local $i = 0 , $NuA = 0 ,$NuB = 0 ,$NuC = 0 ,$PtrB , $ReturnSt Local $ByteE,$ByteB,$ByteC,$ByteD,$PtrA,$ByteA,$NuBPtr,$NuCPtr While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuA += 1 Next if $NuA > 2 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteB,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnSt = DllStructCreate("Byte CountB;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnSt,"CountB",$NuB) DllStructSetData($ReturnSt,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnSt,"NuB") $NuCPtr = DllStructGetPtr($ReturnSt,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnSt = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnSt,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf Return $ReturnSt EndFunc Func CompressionC($TempDataStructA) Local $TestByte = False , $ByteE = 0 ; (Max $TempDataStructA Size Is 254) // (Max $v is 255 Start From Zero) // One Byte Out For $v = 0 To (255 - 1) $TestByte = True For $q = 1 To DllStructGetSize($TempDataStructA) $ByteE = DllStructGetData($TempDataStructA,1,$q) if $v = $ByteE Then $TestByte = False ExitLoop EndIf Next if $TestByte Then $ByteE = $v ExitLoop EndIf Next Return $ByteE EndFunc Func Decompressing($InFile,$OutFile) Local $nBytes, $FileSize , $hFileA , $hFileB , $FileSt , $FileStPtr , $NuF Local $Remainder , $CountBSt , $CountB , $CountCSt , $CountC , $StructBPtr Local $StructCPtr , $NuG , $TempDataStructB , $TempDataStructC , $NewSize Local $ByteA , $ByteB , $ByteE , $vByteE , $TempDataStructD , $StructDPtr $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf $FileSt = DllStructCreate("Byte[" & $FileSize & "]") $FileStPtr = DllStructGetPtr($FileSt) _WinAPI_ReadFile($hFileA,$FileStPtr,$FileSize,$nBytes) $Remainder = DllStructGetData($FileSt,1,1) $FileStPtr = DllStructGetPtr($FileSt) $NuF = ($FileSize - ($Remainder + 1)) if Not $NuF Then _WinAPI_WriteFile($hFileB,$FileStPtr + 1,$Remainder,$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$Remainder) Else $FileStPtr += ($Remainder + 1) EndIf While 1 if $NuF = 0 Then ExitLoop $CountBSt = DllStructCreate("Byte",$FileStPtr) $CountB = DllStructGetData($CountBSt,1) if $CountB = 0 Then $FileStPtr += 1 _WinAPI_WriteFile($hFileB,$FileStPtr,254,$nBytes) $FileStPtr += 254 $NuF -= (254 + 1) Else $NuG = 0 $FileStPtr += 1 $TempDataStructB = DllStructCreate("Byte[" & $CountB & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) _MemMoveMemory($FileStPtr,$StructBPtr,$CountB) $FileStPtr += $CountB $CountCSt = DllStructCreate("Byte",$FileStPtr) $CountC = DllStructGetData($CountCSt,1) $FileStPtr += 1 $TempDataStructC = DllStructCreate("Byte[" & $CountC & "]") $StructCPtr = DllStructGetPtr($TempDataStructC) _MemMoveMemory($FileStPtr,$StructCPtr,$CountC) $FileStPtr += $CountC $NuF -= ($CountB + $CountC + 2) For $i = $CountC To 3 Step -3 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $ByteE = DllStructGetData($TempDataStructC,1,$i - 2) $ByteA = DllStructGetData($TempDataStructC,1,$i - 1) $ByteB = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $vByteE = DllStructGetData($TempDataStructB,1,$j) if $vByteE = $ByteE Then $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) Else $NuG += 1 DllStructSetData($TempDataStructD,1,$vByteE,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next $StructBPtr = DllStructGetPtr($TempDataStructB) _WinAPI_WriteFile($hFileB,$StructBPtr,$NuG,$nBytes) $NewSize += $NuG EndIf WEnd $FileStPtr = DllStructGetPtr($FileSt) + 1 _WinAPI_WriteFile($hFileB,$FileStPtr,$Remainder,$nBytes) $NewSize += $Remainder _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Compression.zip1 point
-
@adityaparakh Since you provided absolutely no information related to what your 2D array should look like or contain, the well-documented example below is very generic. With 100's of relevant examples across the forums (including many in this topic alone), one would think you could have shown a little more effort than the two lines that you provided. #include <Constants.au3> #include <Array.au3> #include "json.au3" ; <== Modify as needed Const $JSON_DATA = _ '{' & _ ' "type": "success",' & _ ' "code": "123ABC",' & _ ' "description": "Another simple example",' & _ ' "result": {' & _ ' "fruits": [' & _ ' {"Fruit": "Apple" , "Qty": 34700, "Cost": 94.89, "Status": false},' & _ ' {"Fruit": "Banana" , "Qty": 34100, "Cost": 01.79, "Status": true} ,' & _ ' {"Fruit": "Orange" , "Qty": 34000, "Cost": 56.82, "Status": true} ,' & _ ' {"Fruit": "Mango" , "Qty": 33900, "Cost": 15.74, "Status": false},' & _ ' {"Fruit": "Pineapple" , "Qty": 34600, "Cost": 30.22, "Status": false},' & _ ' {"Fruit": "Cantaloupe", "Qty": 34500, "Cost": 69.17, "Status": false}' & _ ' ]' & _ ' }' & _ '}' json_udf_example() Func json_udf_example() Local $oJson Local $aResult[0][3] ;Decode JSON to an object $oJson = Json_Decode($JSON_DATA) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to decode JSON - @error = " & @error) ;For each object in the array For $oFruit in json_get($oJson, ".result.fruits") ;Add a row of data to the table _ArrayAdd($aResult, _ Json_Get($oFruit, ".Fruit") & "|" & _ Json_Get($oFruit, ".Qty") & "|" & _ Json_Get($oFruit, ".Cost") _ ) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "_ArrayAdd failed - @error = " & @error) Next ;Display result _ArrayDisplay($aResult, "Example 2D Array", "", 0, Default, "Fruit|Qty|Cost") EndFunc1 point
-
$ojson = Json_Decode($JSON) $aGroups = Json_Get($ojson, ".groups") ConsoleWrite("Groups count = " & UBound($aGroups) & @CRLF) .groups is an array of json objects. So you would get the count of how many array items like you would with any other array.1 point
-
Just add it at the end of the body should work...no? Jos1 point