baroquebob Posted February 19, 2018 Share Posted February 19, 2018 I've been experimenting with creating a simple GUI calculator (with actual buttons and display), in the fewest possible lines of code. So far, I'm at 38 lines (without white space). Unfortunately the script does not have any error handling, nor does it recognize numeric keypresses from the keyboard, but it otherwise seems to work okay. The code doesn't necessarily follow good programming practice, but I was just aiming for 'small'. Just sharing in case somebody else might find it interesting, and maybe would like to add error handling or keyboard input, (of course, following my minimalist approach. :-) ) Any thoughts on keeping the functionality as-is, but making the script even smaller? expandcollapse popupOpt("GUIOnEventMode", 1) DIM $BA[] = ["7","8","9","+","C","4","5","6","-","SqRt","1","2","3","*",".","0","(",")","/","="] Global $x = 8, $y = 50 GUICreate("Calc", 360, 330, 229, 118) $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080,2)) For $j = 0 to Ubound($BA) - 1 ;make the buttons btn($BA[$j]) Next GUISetState(@SW_SHOW) GUISetOnEvent(-3, "Bye") While 1 Sleep(25) ;Throttle WEnd Func btn($t) ;make button, associate event for each button press GUICtrlCreateButton($t, $x, $y, 65, 63) GUICtrlSetOnEvent(-1, "BP") GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $x += 70 If $x > 350 Then ;move down and left for next row of buttons $x = 8 $y += 70 EndIf EndFunc Func BP() ;handle the button press $v = GuiCtrlRead(@GUI_CtrlId) If $v = "C" Then GuiCtrlSetData($D, "") ElseIf $v = "SqRt" Then ;Solve expression, then take sqrt. GuiCtrlSetData($D, Sqrt(Execute(GuiCtrlRead($D)))) ElseIf $v = "=" Then ;solve the expression GuiCtrlSetData($D, Execute(GuiCtrlRead($D))) Else GuiCtrlSetData($D, GuiCtrlRead($D) & $v) EndIf EndFunc Func Bye() Exit EndFunc Gianni 1 Link to comment Share on other sites More sharing options...
Gianni Posted February 19, 2018 Share Posted February 19, 2018 ... nice "Code golf". (if you like such puzzles, here you can find some funny code golf puzzles) P.S. just for fun... code reduced to 23 lines (apologyes for the 'brutalization' of your code ) Local $0 = Opt("GUIOnEventMode", 1), $BA[] = ["7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", "="] Local $hGui = GUICreate("Calc", 360, 330, 229, 118), $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetOnEvent(-3, "Bye") For $j = 0 to UBound($BA) - 1 ;make the buttons $2 = GUICtrlCreateButton($BA[$j], Mod($j, 5) * 70 + 7, Int($j / 5) * 70 + 50, 65, 63) + GUICtrlSetOnEvent(-1, "BP") + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") Next GUISetState(@SW_SHOW) While Sleep(25) ;Throttle WEnd Func BP() ;handle the button press $v = GUICtrlRead(@GUI_CtrlId) If $v = "C" Then GUICtrlSetData($D, "") ElseIf $v = "SqRt" Then ;Solve expression, then take sqrt. GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) ElseIf $v = "=" Then ;solve the expression GUICtrlSetData($D, Execute(GUICtrlRead($D))) Else GUICtrlSetData($D, GUICtrlRead($D) & $v) EndIf EndFunc ;==>BP Func Bye() Exit EndFunc ;==>Bye Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
UEZ Posted February 19, 2018 Share Posted February 19, 2018 12 lines: Local $0 = Opt("GUIOnEventMode", 1), $BA[] = ["7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", "="], $hGui = GUICreate("Calc", 360, 330, 229, 118), $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetOnEvent(-3, "Bye") * GUISetState(@SW_SHOW) For $j = 0 to UBound($BA) - 1 ;make the buttons $2 = GUICtrlCreateButton($BA[$j], Mod($j, 5) * 70 + 7, Int($j / 5) * 70 + 50, 65, 63) + GUICtrlSetOnEvent(-1, "BP") + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") Next While Sleep(100) ;Throttle WEnd Func BP() ;handle the button press $v = GUICtrlRead(@GUI_CtrlId) = "C" ? GUICtrlSetData($D, "") : GUICtrlRead(@GUI_CtrlId) = "SqRt" ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead(@GUI_CtrlId)= "=" ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) : GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead(@GUI_CtrlId)) EndFunc ;==>BP Func Bye() Exit EndFunc ;==>Bye Gianni and junkew 2 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
qwert Posted February 19, 2018 Share Posted February 19, 2018 Thanks for posting these. They're great examples of what can be accomplished with AutoIt. For anyone scanning these posts, here's an example: Link to comment Share on other sites More sharing options...
Gianni Posted February 19, 2018 Share Posted February 19, 2018 9 lines: Local $0 = Opt("GUIOnEventMode", 1), $BA[] = ["7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", "="], $hGui = GUICreate("Calc", 360, 330, 229, 118), $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetOnEvent(-3, "BP") * GUISetState(@SW_SHOW) For $j = 0 To UBound($BA) - 1 ;make the buttons $2 = GUICtrlCreateButton($BA[$j], Mod($j, 5) * 70 + 7, Int($j / 5) * 70 + 50, 65, 63) + GUICtrlSetOnEvent(-1, "BP") + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") Next While Sleep(100) ;Throttle WEnd Func BP() ;handle the button press If (GUICtrlRead(@GUI_CtrlId) = "C" ? GUICtrlSetData($D, "") : GUICtrlRead(@GUI_CtrlId) = "SqRt" ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead(@GUI_CtrlId) = "=" ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) : GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead(@GUI_CtrlId))) And @GUI_CtrlId = -3 Then Exit EndFunc ;==>BP UEZ 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
baroquebob Posted February 19, 2018 Author Share Posted February 19, 2018 9 lines - amazing! Thanks all for the feedback and input. I've learned quite a few tricks thanks to you! Link to comment Share on other sites More sharing options...
junkew Posted February 19, 2018 Share Posted February 19, 2018 (edited) down to 5 lines and the feeling at least 1 more should be possible with the ? operator on the GUIGetMsg(1) Local $j=0, $2=0, $amsg[]=[0,0,0,0,0], $BA[] = ["7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", "="], $hGui = GUICreate("Calc", 360, 330, 229, 118), $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetState(@SW_SHOW),$2 = GUICtrlCreateButton($BA[0],7,50,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"), $2 = GUICtrlCreateButton($BA[1],77,50,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[2],147,50,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[3],217,50,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[4],287,50,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[5],7,120,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[6],77,120,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[7],147,120,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[8],217,120,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[9],287,120,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[10],7,190,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[11],77,190,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[12],147,190,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[13],217,190,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[14],287,190,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[15],7,260,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[16],77,260,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[17],147,260,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[18],217,260,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif"),$2 = GUICtrlCreateButton($BA[19],287,260,65, 63) + GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") Do $aMsg = GUIGetMsg(1) ;Get as array ; Should be possible with a ? somewhere if ($aMsg[2]=0 ? $2=0 : (GUICtrlRead($aMsg[0]) = "C" ? GUICtrlSetData($D, "") : GUICtrlRead($aMsg[0]) = "SqRt" ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead($aMsg[0]) = "=" ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) : GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead($aMsg[0]))) and ($aMsg[0]=-3)) Then exit Until $aMsg[0] = -3 ; $GUI_EVENT_CLOSE Edited February 19, 2018 by junkew UEZ 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
junkew Posted February 20, 2018 Share Posted February 20, 2018 (edited) Beated my own expectation down to 3 lines and shortened in bytes (using the $fcBtn makes it shorter could have made it $f offcourse but goal was not to obfuscate) local $fcBtn=GUICtrlCreateButton, $j=0, $2=0, $amsg[]=[0,0,0,0,0], $BA[] = ["7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", "="], $hGui = GUICreate("Calc", 360, 330, 229, 118), $f=GUISetFont(18, 400, 0, "MS Sans Serif"), $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetState(@SW_SHOW),$2 = $fcBtn($BA[0],7,50,65, 63) , $2 = $fcBtn($BA[1],77,50,65, 63) ,$2 = $fcBtn($BA[2],147,50,65, 63) ,$2 = $fcBtn($BA[3],217,50,65, 63) ,$2 = $fcBtn($BA[4],287,50,65, 63) ,$2 = $fcBtn($BA[5],7,120,65, 63) ,$2 = $fcBtn($BA[6],77,120,65, 63) ,$2 = $fcBtn($BA[7],147,120,65, 63) ,$2 = $fcBtn($BA[8],217,120,65, 63) ,$2 = $fcBtn($BA[9],287,120,65, 63) ,$2 = $fcBtn($BA[10],7,190,65, 63) ,$2 = $fcBtn($BA[11],77,190,65, 63) ,$2 = $fcBtn($BA[12],147,190,65, 63) ,$2 = $fcBtn($BA[13],217,190,65, 63) ,$2 = $fcBtn($BA[14],287,190,65, 63) ,$2 = $fcBtn($BA[15],7,260,65, 63) ,$2 = $fcBtn($BA[16],77,260,65, 63) ,$2 = $fcBtn($BA[17],147,260,65, 63) ,$2 = $fcBtn($BA[18],217,260,65, 63) ,$2 = $fcBtn($BA[19],287,260,65, 63) Do Until ((assign("aMsg",GUIGetMsg(1))=1) and ($aMsg[2]=0 ? $2=0 : (GUICtrlRead($aMsg[0]) = "C" ? GUICtrlSetData($D, "") : GUICtrlRead($aMsg[0]) = "SqRt" ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead($aMsg[0]) = "=" ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) : GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead($aMsg[0]))) and ($aMsg[0]=-3))=true) or ($aMsg[0] = -3) ; $GUI_EVENT_CLOSE I think I am out of tricks but maybe an MVP knows how to get it into a one liner Edited February 20, 2018 by junkew Title can change now to under 4 instead of 40 lines ;-) Gianni, mLipok and UEZ 3 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Gianni Posted February 21, 2018 Share Posted February 21, 2018 (edited) a 4 line version was also missing, here is one (... is few bytes less than the nice 3 lines version by @junkew) Global $iMsg, $j, $BA[] = [7, 8, 9, '+', 'C', 4, 5, 6, "-", "SqRt", 1, 2, 3, '*', '.', 0, '(', ')', '/', '='], $hGui = GUICreate('Calc', 360, 330, 229, 118, 0x00C00000), $D = GUICtrlCreateInput('', 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetState(@SW_SHOW), $a = DllCallbackRegister('BP', 'none', 'hwnd;uint;uint_ptr;dword'), $b = DllCall('user32.dll', 'uint_ptr', 'SetTimer', 'hwnd', 0, 'uint_ptr', 0, 'uint', 10, 'ptr', DllCallbackGetPtr($a)), $exit = MsgBox(0, "Info", "hit 'esc' or click here to exit"), $TheEnd1 = DllCallbackFree($a), $TheEnd2 = DllCall('user32.dll', 'bool', 'KillTimer', 'hwnd', 0, 'uint_ptr', $b) Func BP($hWnd, $iMsg2, $iTimerID, $iTime) ;handle the button press $j = (Assign('iMsg', GUIGetMsg(0))) * 0 ? 0 :($j < UBound($BA)) ?(GUICtrlCreateButton($BA[$j], Mod($j, 5) * 70 + 7, Int($j / 5) * 70 + 50, 65, 63) + GUICtrlSetFont(-1, 18, 400, 0, 'MS Sans Serif')) * 0 + $j + 1 : UBound($BA) + 0 * ($iMsg > 3 And $iMsg < 24 ?(GUICtrlRead($iMsg) = 'C' ? GUICtrlSetData($D, '') : GUICtrlRead($iMsg) = 'SqRt' ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead($iMsg) = '=' ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) :(StringInStr('0123456789()+-*/.', GUICtrlRead($iMsg))) > 0 ? GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead($iMsg)) : 0) : 20) EndFunc ;==>BP Edited February 21, 2018 by Chimp mLipok 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mLipok Posted February 21, 2018 Share Posted February 21, 2018 (edited) All under 5 lines is just causes a headache I miss challenges like these here. Unfortunately, I do not even have time to deal with them Edited February 21, 2018 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Bilgus Posted February 22, 2018 Share Posted February 22, 2018 (edited) Local $BA[] = ["Sin", "Tan", "Cos", "Exp", "Log", "7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", " = "] $hGui = GUICreate("Calc", 360, 400, 229, 138, 0x10000000 + 0x20000000 + 0xC00000 + 0x80000) ;VISIBLE, MINIMIZEBOX, CAPTION, POPUP, SYSMENU $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)) ;$ES_AUTOHSCROLL, $ES_RIGHT For $j = 0 To UBound($BA) - 1 ;make the buttons $BA[$j] = GUICtrlCreateButton($BA[$j], Mod($j, 5) * 70 + 7, Int($j / 5) * 70 + 50, 65, 63) $sB = GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") Next While Execute(Assign("j", GUIGetMsg()) And $j <> -3) If $j > 0 And Assign("sB", GUICtrlRead($j)) And Call($sB, GUICtrlRead($D)) Then GUICtrlSetData($D, Call($sB, GUICtrlRead($D))) ;Sqrt; Tan; Cos.. Execute($j - $D > 0xDEAD - @error And GUICtrlSetData($D, ($sB = "C" Or $sB = " = ") ? Execute(StringLeft($sB, 1) & GUICtrlRead($D)) : GUICtrlRead($D) & $sB)) WEnd 11 lines with a bit different method Still 11 Lines but its a bit more concise back to dynamic 'C' and '=' buttons and I showed how to add more named functions like Tan() Cos() Sin() Edited February 22, 2018 by Bilgus Adding Sin Tan Cos Exp Log Gianni 1 Link to comment Share on other sites More sharing options...
Popular Post JohnOne Posted February 22, 2018 Popular Post Share Posted February 22, 2018 1 line Run("calc.exe") junkew, BrewManNH, kyo and 4 others 6 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
lpduy Posted February 24, 2018 Share Posted February 24, 2018 (edited) Improved from junkew 's code into two lines Hi Funs Improved from junkew 's code into 2 line if not FileExists(@TempDir&"\Cal.au3") then FileWrite(@TempDir&"\Cal.au3",'local $fcBtn=GUICtrlCreateButton, $j=0, $2=0, $amsg[]=[0,0,0,0,0], $BA[] = ["7", "8", "9", "+", "C", "4", "5", "6", "-", "SqRt", "1", "2", "3", "*", ".", "0", "(", ")", "/", "="], $hGui = GUICreate("Calc", 360, 330, 229, 118), $f=GUISetFont(18, 400, 0, "MS Sans Serif"), $D = GUICtrlCreateInput("", 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetState(@SW_SHOW),$2 = $fcBtn($BA[0],7,50,65, 63) , $2 = $fcBtn($BA[1],77,50,65, 63) ,$2 = $fcBtn($BA[2],147,50,65, 63) ,$2 = $fcBtn($BA[3],217,50,65, 63) ,$2 = $fcBtn($BA[4],287,50,65, 63) ,$2 = $fcBtn($BA[5],7,120,65, 63) ,$2 = $fcBtn($BA[6],77,120,65, 63) ,$2 = $fcBtn($BA[7],147,120,65, 63) ,$2 = $fcBtn($BA[8],217,120,65, 63) ,$2 = $fcBtn($BA[9],287,120,65, 63) ,$2 = $fcBtn($BA[10],7,190,65, 63) ,$2 = $fcBtn($BA[11],77,190,65, 63) ,$2 = $fcBtn($BA[12],147,190,65, 63) ,$2 = $fcBtn($BA[13],217,190,65, 63) ,$2 = $fcBtn($BA[14],287,190,65, 63) ,$2 = $fcBtn($BA[15],7,260,65, 63) ,$2 = $fcBtn($BA[16],77,260,65, 63) ,$2 = $fcBtn($BA[17],147,260,65, 63) ,$2 = $fcBtn($BA[18],217,260,65, 63) ,$2 = $fcBtn($BA[19],287,260,65, 63)' &@CRLF & 'do' &@CRLF & 'Until (((assign("aMsg",GUIGetMsg(1))=1) and ($aMsg[2]=0 ? $2=0 : (GUICtrlRead($aMsg[0]) = "C" ? GUICtrlSetData($D, "") : GUICtrlRead($aMsg[0]) = "SqRt" ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead($aMsg[0]) = "=" ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) : GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead($aMsg[0]))) and ($aMsg[0]=-3))=true) or ($aMsg[0] = -3))') ShellExecute(@TempDir&"\Cal.au3",@TempDir) Edited February 24, 2018 by lpduy mLipok 1 Link to comment Share on other sites More sharing options...
Ascer Posted February 24, 2018 Share Posted February 24, 2018 This thread is bullshit cuz all we know that the most important thing is code clarity and easy bugs detecting. -1 for this discussion. Link to comment Share on other sites More sharing options...
lpduy Posted February 24, 2018 Share Posted February 24, 2018 13 minutes ago, Ascer said: Chủ đề này là bullshit cuz tất cả chúng ta biết rằng điều quan trọng nhất là mã rõ ràng và dễ dàng phát hiện lỗi. -1 cho cuộc thảo luận này. But sometime we need small and smaller code to reduce file size! If develop Autoit for mobile app that it's wolderfull Link to comment Share on other sites More sharing options...
Ascer Posted February 24, 2018 Share Posted February 24, 2018 (edited) AutoIt for mobiles is waste time. Something like a start working now on company to create oil cars. Edited February 24, 2018 by Ascer Link to comment Share on other sites More sharing options...
junkew Posted February 24, 2018 Share Posted February 24, 2018 @Ascer offcourse readability is great but challenges like this proof how well you know indepth your language of programming. In my code editor with color highlighting the short version is still readable and understandable. And if you want to write an obfuscator thes tricks are nice to know. mLipok 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Gianni Posted February 24, 2018 Share Posted February 24, 2018 (edited) 4 hours ago, lpduy said: Improved from junkew 's code into two lines if that "trick" is allowed then just one line it's enough Local $1 = FileWrite(FileOpen(@TempDir & "\Cal.au3", 2), "Global $iMsg, $j, $BA[] = [7, 8, 9, '+', 'C', 4, 5, 6, '-', 'SqRt', 1, 2, 3, '*', '.', 0, '(', ')', '/', '='], $hGui = GUICreate('Calc', 360, 330, 229, 118, 0x00C00000), $D = GUICtrlCreateInput('', 8, 8, 344, 31, BitOR(0x00000080, 2)), $1 = GUISetState(@SW_SHOW), $a = DllCallbackRegister('BP', 'none', 'hwnd;uint;uint_ptr;dword'), $b = DllCall('user32.dll', 'uint_ptr', 'SetTimer', 'hwnd', 0, 'uint_ptr', 0, 'uint', 10, 'ptr', DllCallbackGetPtr($a)), $exit = MsgBox(0, 'Info', 'click here to exit'), $TheEnd1 = DllCallbackFree($a), $TheEnd2 = DllCall('user32.dll', 'bool', 'KillTimer', 'hwnd', 0, 'uint_ptr', $b)" & @CRLF & "Func BP($hWnd, $iMsg2, $iTimerID, $iTime)" & @CRLF & "$j = (Assign('iMsg', GUIGetMsg(0))) * 0 ? 0 :($j < UBound($BA)) ?(GUICtrlCreateButton($BA[$j], Mod($j, 5) * 70 + 7, Int($j / 5) * 70 + 50, 65, 63) + GUICtrlSetFont(-1, 18, 400, 0, 'MS Sans Serif')) * 0 + $j + 1 : UBound($BA) + 0 * ($iMsg > 3 And $iMsg < 24 ?(GUICtrlRead($iMsg) = 'C' ? GUICtrlSetData($D, '') : GUICtrlRead($iMsg) = 'SqRt' ? GUICtrlSetData($D, Sqrt(Execute(GUICtrlRead($D)))) : GUICtrlRead($iMsg) = '=' ? GUICtrlSetData($D, Execute(GUICtrlRead($D))) :(StringInStr('0123456789()+-*/.', GUICtrlRead($iMsg))) > 0 ? GUICtrlSetData($D, GUICtrlRead($D) & GUICtrlRead($iMsg)) : 0) : 20)" & @CRLF & "EndFunc"), $2 = Run(@AutoItExe & " " & @TempDir & "\Cal.au3") Edited February 24, 2018 by Chimp mLipok 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
junkew Posted February 24, 2018 Share Posted February 24, 2018 The implicit rule i feel "not allowed" But as with anything changing the rules during the game is also not allowed. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
lpduy Posted February 25, 2018 Share Posted February 25, 2018 15 hours ago, Chimp said: if that "trick" is allowed then just one line it's enough Autoit's wonderfull!!! if replace func name by short varian and can use Au3stripper /rm so i think it can do this! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now