Leaderboard
Popular Content
Showing content with the highest reputation on 04/01/2020 in all areas
-
_Base64Encode, _Base64Decode
Colduction reacted to trancexx for a topic
I guess there is no need to explain what Base64 encoding is and what is used for. What is special about this way. Well, I did some testing and it turns that it's fast. About three times faster than the fastest way posted here on this forum (machine code implementation). It's calling functions "CryptBinaryToString" and "CryptStringToBinary" in Crypt32.dll I'm in the phase when discovering functions DllCall(), DllStructCreate(),... and related, so please be gentle to me, lol There is no error checking mainly because of the sentence before this one. If someone is willing to add that to the code below (or correct possible mistakes), I'm willing to learn out of that. So, please do. Here's the script: Updated 29th October 2008 - error checking added and some code optimization $encoded = _Base64Encode("Testing") MsgBox(0, 'Base64 Encoded', $encoded) $decoded = _Base64Decode($encoded) MsgBox(0, 'Base64 Decoded - binary', $decoded) MsgBox(0, 'Base64 Decoded - string', BinaryToString($decoded)) Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode Func _Base64Decode($input_string) Local $struct = DllStructCreate("int") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $input_string, _ "int", 0, _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $input_string, _ "int", 0, _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error decoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Decode There is @CRLF every 64 chars in return of _Base64Encode(). _Base64Decode() will return binary data. That is intentional to avoid Chr(0) issue. Convert it to string using BinaryToString() Microsoft about requirements: Client - Requires Windows Vista or Windows XP. Server - Requires Windows Server 2008 or Windows Server 2003.1 point -
Check out _FileCountLines in the help file. Use it to get the line count, subtract 10, then use FileReadLine in a loop.1 point
-
You might avoid a global var by using Return And also include some Sleep() so your system can breathe a little HotKeySet("+{Enter}", "_ShowPseudoClipboard") While 1 Sleep(100) WEnd Func _ShowPseudoClipboard() $PseudoClipboard = _CopyToPseudoClipboard() ;MsgBox(4096, "", $PseudoClipboard) consolewrite("result = " & $PseudoClipboard & @crlf & @crlf) EndFunc Func _CopyToPseudoClipboard() $OriginalClipboard = ClipGet() Sleep(10) Send("^c") Sleep(10) Local $NewClipboard = ClipGet() ; check it consolewrite("$NewClipboard = " & $NewClipboard & @crlf) consolewrite("$OriginalClipboard = " & $OriginalClipboard & @crlf) ClipPut($OriginalClipboard) Return $NewClipboard EndFunc1 point
-
Byref has nothing to do with that. I second what @Nine said about Static variables. A function can easily be used both explicitely, on timeout and by hotkey and behave differently in all cases. HotKeySet("{F2}", fct) HotKeySet("{ESC}", stop) AdlibRegister(rst, 14000) ; reset static variable every 14s Func fct($p) Local Static $v = 26 If IsDeclared("p") Then If $p < 0 Then ConsoleWrite("fct invoked on timeout; value = " & $v & " and will be reset to 0" & @LF) $v = 0 Else ConsoleWrite("fct invoked explicitely; value = " & $v & " and will increment by " & $p & @LF) $v += $p EndIf Else ConsoleWrite("fct invoked thru hotkey; value = " & $v & " and will increment by " & 100 & @LF) $v += 100 EndIf EndFunc Func stop() Exit EndFunc Func rst() fct(-1) EndFunc While 1 Sleep(1000) fct(Random(1, 9, 1)) WEnd If you need to pass any value in $p (meaning that you can't differentiate calling method by looking at $p), then declare a second variable in fct() and pass there a value for switching between wanted behaviors.1 point
-
zLib (Deflate/Inflate/GZIP) UDF
Earthshine reacted to TheXman for a topic
Did it ever occur to you to read through this topic to see if anyone else has asked the same question and if someone may have answered it?1 point -
Do not forget that there is Local Static $Variables. If you only need that var in a single function, but wants it to act like a global, think of it. I believe it is one of the underestimated and underused feature of AutoIt...1 point
-
Global variables are fine, especially if you wish to use the variable in multiple functions. You can also use functions with parameters (see _Example1 above, but as mikell mentioned if you wish to use HotKeySet, you would need to use a global variable or call a function within your HotKeySet function. Hope that made sense.1 point
-
I like how @Subz calls his variables : $g_sString1 point
-
BTW HotkeySet : The called function can not be given parameters. They will be ignored. (helpfile)1 point
-
There are a number of ways to do this, it really depends if you wish to use the variable throughout all your functions for example: Global $g_sString = "" ;~ Set $g_sString value _SetVariable("Example1 String") ;~ Pass the global variable as a parameter _Example1($g_sString) ;~ $g_sString is referenced within the _Example2 function _Example2() Func _SetVariable($_sString) ;~ $_sString is local to this function ;~ $g_sString has already been decalared in the global scope $g_sString = $_sString EndFunc Func _Example1($_sString = "") MsgBox(4096, "Example 1", "$_sString = " & $_sString) EndFunc Func _Example2() _SetVariable("Example2 String") MsgBox(4096, "Example 2", "$g_sString = " & $g_sString) EndFunc Edit: Added a couple of different examples1 point
-
OMG! Many thanks! I have trying all options without any success. Your tip to use "{}" It brought me back to life in these hard period Stay at home and take care of yourself and your loved Thank U and wish you lots of health!1 point
-
Latest Beta version has this additional test in it as that was a simple change. Hope that makes it perform correctly. Jos1 point
-
https://www.dropbox.com/sh/y4epv7z7i4dmpxc/AADAoktbSrzLnresusI8w6_ua?dl=0&file_subpath=%2FSPiiPlus+COM+Library%2FVBScript%2FCom+Library+Demo.htm&preview=Examples+SPiiPlus+COM+Library.7z <P><STRONG id=SlotNumberLBL> <!--The SPiiPlusCOM.dll must be registered on your computer. <!--Execute regsvr32 "C:\.\ SPiiPlusCOM660_x86.dll" to register the library. --><!--The block definiton of the SPiiPlusCOM object should be introduced in HTML code --> <OBJECT classid=clsid:73C1FDD7-7A9F-45cb-AC12-73AC50F9A3C8 height=1 id=Ch style="HEIGHT: 1px; WIDTH: 16px" VIEWASTEXT></OBJECT> so in AutoIt: ObjCreate('73C1FDD7-7A9F-45cb-AC12-73AC50F9A3C8') ; or ObjCreate('{73C1FDD7-7A9F-45cb-AC12-73AC50F9A3C8}') ; or something like this above....1 point
-
MailSlot
trancexx reacted to seadoggie01 for a topic
Quick note to anyone who knows nothing about MailSlots (like me)... make sure to name the MailSlot like this "\\.\mailslot\" then whatever you want... Otherwise it will fail. Repeatedly. On the other hand, thank you very much for this UDF, it's very helpful! (Once I understand it) Edit: Hmm... maybe I should read the function documentation better 😐1 point -
Think I understand what you were trying to achieve, you wanted to loop from F6:H11 to F11:H11? Try: #include <Excel.au3> #include <Array.au3> #include <GuiComboBox.au3> Local $sWorkbook = "C:\TESTING.xlsm" Local $oExcel = _Excel_Open() Local $oWorkbook $oWorkbook = _Excel_BookAttach($sWorkbook) ;~ If Excel Workbook isn't open, then open the workbook If @error Then $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook) ;~ Select Job Row Start and Job Row End Local $iJobRowStart = 6, $iJobRowEnd = 11 ;~ Copy F6 to H11 to an array Local $aJobCells = _Excel_RangeRead($oWorkbook, Default, "F" & $iJobRowStart & ":H" & $iJobRowEnd) Local $aCell = _Excel_RangeRead($oWorkbook, Default, "E4") Local $dCell = _Excel_RangeRead($oWorkbook, Default, "e7") Local $kCell = _Excel_RangeRead($oWorkbook, Default, "b16") ;~ Array is in the format: ;~ x is the row number ;~ $aJobCells[x][0] = Excel Column F ;~ $aJobCells[x][1] = Excel Column G ;~ $aJobCells[x][2] = Excel Column H For $i = 0 To UBound($aJobCells) - 1 ;~ Start: Debug Code allows you to view the Col:Row for debuggin (Press F5 in Scite) (not required) ConsoleWrite("Excel Column F" & ($iJobRowStart + $i) & " = " & $aJobCells[$i][0] & @CRLF) ConsoleWrite("Excel Column G" & ($iJobRowStart + $i) & " = " & $aJobCells[$i][1] & @CRLF) ConsoleWrite("Excel Column H" & ($iJobRowStart + $i) & " = " & $aJobCells[$i][2] & @CRLF) ;~ End: Debug Code ControlClick("Job Selection","",4144) sleep(2000) WinWait("Job Creation", "Job Owner") WinActivate("Job Creation") Sleep(2000) ControlSend("Job Creation", "", "[CLASS:SNET$combobox; INSTANCE:5]", "0") Sleep(1000) ControlSend("Job Creation", "", "[CLASS:SNET$combobox; INSTANCE:5]", $aCell) Sleep(600) $hCombo = ControlGetHandle("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:5]") _GUICtrlComboBox_SelectString($hCombo, $aJobCells[$i][1]) Sleep(500) $hCombo = ControlGetHandle("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:1]") _GUICtrlComboBox_SelectString($hCombo, "NETWORK") Sleep(500) ControlSend("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:2]", "1") Sleep(500) ControlSend("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:2]", "5") Sleep(500) ControlSend("Job Creation", "", "[CLASS:Edit; INSTANCE:1]", $dCell) Sleep(500) ControlSend("Job Creation", "", "[CLASS:Edit; INSTANCE:1]","^{right}") Sleep(500) ControlSend("Job Creation", "", "[CLASS:Edit; INSTANCE:1]","{right}") Sleep(500) ControlSend("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:8]", "e") Sleep(500) ControlSend("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:9]", "e") Sleep(500) ControlSend("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:10]", "e") Sleep(500) ControlSend("Job Creation", "", "[CLASS:Edit; INSTANCE:2]", $aJobCells[$i][0]) Sleep(500) WinActivate("Job Creation") Sleep(1500) ControlSend("Job Creation", "", "[CLASS:SNET$combobox; INSTANCE:11]", "<") Sleep(1000) ControlSend("Job Creation", "", "[CLASS:SNET$combobox; INSTANCE:11]", "T") Sleep(600) $hCombo = ControlGetHandle("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:11]") _GUICtrlComboBox_SelectString($hCombo, "TCTS TQ profil") WinActivate("Job Creation") Sleep(1500) $hCombo = ControlGetHandle("Job Creation", "", "[CLASS:SNET$combobox;INSTANCE:12]") _GUICtrlComboBox_SelectString($hCombo, $kCell) Sleep(500) ControlSend("Job Creation", "", "[CLASS:SNET$Edit; INSTANCE:2]", "{home}") Sleep(300) ControlSend("Job Creation", "", "[CLASS:SNET$Edit; INSTANCE:2]", "^{del}") Sleep(300) ControlSend("Job Creation", "", "[CLASS:SNET$Edit; INSTANCE:2]", "^{left}") Sleep(300) ControlSend("Job Creation", "", "[CLASS:SNET$Edit; INSTANCE:2]", "{home}") Sleep(300) ControlSend("Job Creation", "", "[CLASS:SNET$Edit; INSTANCE:2]", "^{del}") Sleep(500) ControlSend("Job Creation", "", "[CLASS:SNET$Edit; INSTANCE:2]", "^{del}") Sleep(1000) ControlSend("Job Creation", "", "[CLASS:SNET$Edit; INSTANCE:2]", $aJobCells[$i][2]) Sleep(500) Next1 point