Jump to content
baroquebob

Full GUI Calculator in under 40 lines

Recommended Posts

baroquebob

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?

Opt("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

 

  • Like 1

Share this post


Link to post
Share on other sites
Chimp

... 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

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
UEZ

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

 

  • Like 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
qwert

Thanks for posting these.  They're great examples of what can be accomplished with AutoIt.

For anyone scanning these posts, here's an example:

12-line Calculator.PNG

Share this post


Link to post
Share on other sites
Chimp

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

 

  • Like 1

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
baroquebob

9 lines - amazing!  Thanks all for the feedback and input.  I've learned quite a few tricks thanks to you!

Share this post


Link to post
Share on other sites
junkew

down to 5 lines and the feeling at least 1 more should be possible with the ? operator on the GUIGetMsg(1):sweating:

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 by junkew
  • Like 1

Share this post


Link to post
Share on other sites
junkew

Beated my own expectation down to 3 lines :D 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 by junkew
Title can change now to under 4 instead of 40 lines ;-)
  • Like 3

Share this post


Link to post
Share on other sites
Chimp

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 by Chimp
  • Like 1

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
mLipok

All under 5 lines is just causes a headache :frantics:

I miss challenges like these here.
Unfortunately, I do not even have time to deal with them :(

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  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 APIErrorLog.au3 UDF - A logging Library
 

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 *

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 * 

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

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 *

"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"
:naughty:  :ranting:, 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: 2018-10-31

Share this post


Link to post
Share on other sites
Bilgus
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 by Bilgus
Adding Sin Tan Cos Exp Log
  • Like 1

Share this post


Link to post
Share on other sites
lpduy
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 by lpduy
  • Like 1

Share this post


Link to post
Share on other sites
Ascer

This thread is bullshit cuz all we know that the most important thing is code clarity and easy bugs detecting.

-1 for this discussion.

Share this post


Link to post
Share on other sites
lpduy
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

Share this post


Link to post
Share on other sites
Ascer

AutoIt for mobiles is waste time. Something like a start working now on company to create oil cars.

Edited by Ascer

Share this post


Link to post
Share on other sites
junkew

@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.

  • Like 1

Share this post


Link to post
Share on other sites
Chimp
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 by Chimp
  • Like 1

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
lpduy
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!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×