Jump to content

plus


boy14
 Share

Recommended Posts

#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 319, 216, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox(" 1", 48, 56, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox(" 2", 48, 88, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox(" 4", 48, 120, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox(" 8", 216, 56, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("16", 216, 88, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox(" 32", 216, 120, 97, 17)
$Button1 = GUICtrlCreateButton("plus any checked boxes", 64, 160, 155, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        case $Button1

        ???????; show the plus result of checked boxes in message

    EndSwitch
WEnd

 

Link to comment
Share on other sites

#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

$Form1 = GUICreate("Form1", 319, 216, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox(" 1", 48, 56, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox(" 2", 48, 88, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox(" 4", 48, 120, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox(" 8", 216, 56, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("16", 216, 88, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox(" 32", 216, 120, 97, 17)
$Button1 = GUICtrlCreateButton("plus any checked boxes", 64, 160, 155, 25)
GUISetState(@SW_SHOW)

global $boxArray[6][2]=[[$Checkbox1,1],[$Checkbox2,2],[$Checkbox3,4],[$Checkbox4,8],[$Checkbox5,16],[$Checkbox6,32]]
;_ArrayDisplay($boxArray)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        case $Button1
        local $total=0
        for $a=0 to UBound($boxArray)-1
            if GUICtrlRead($boxArray[$a][0])=$GUI_CHECKED then
                $total+=$boxArray[$a][1]
            EndIf
        Next
        MsgBox(0,"Answer",$total)
        ;???????; show the plus result of checked boxes in message

    EndSwitch
WEnd

 

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $HowManyCheckboxs = 12
Global $Answer = 0
Global $Calc = 0.5
Global $CalcAuto = True
Global $plussize = 200
Global $GUI = GUICreate("Calculate", 319, 216+200+$plussize, 192, 124)
Global $Checkbox1 = GUICtrlCreateCheckbox("1",      70*1, 56*1, 55, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("2",      70*2, 56*1, 55, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("4",      70*3, 56*1, 55, 17)
Global $Checkbox4 = GUICtrlCreateCheckbox("8",      70*1, 56*2, 55, 17)
Global $Checkbox5 = GUICtrlCreateCheckbox("16",     70*2, 56*2, 55, 17)
Global $Checkbox6 = GUICtrlCreateCheckbox("32",     70*3, 56*2, 55, 17)
Global $Checkbox7 = GUICtrlCreateCheckbox("64",     70*1, 56*3, 55, 17)
Global $Checkbox8 = GUICtrlCreateCheckbox("126",    70*2, 56*3, 55, 17)
Global $Checkbox9 = GUICtrlCreateCheckbox("256",    70*3, 56*3, 55, 17)
Global $Checkbox10 = GUICtrlCreateCheckbox("512",   70*1, 56*4, 55, 17)
Global $Checkbox11 = GUICtrlCreateCheckbox("1024",  70*2, 56*4, 55, 17)
Global $Checkbox12 = GUICtrlCreateCheckbox("2048",  70*3, 56*4, 55, 17)
Global $Output =     GUICtrlCreateEdit("Please wait...", 10, 216+$plussize, 319-20, 200-10)
Global $Button1 =    GUICtrlCreateButton("Calculate!", 10, 150+$plussize, 299, 25)
Global $Button2 =    GUICtrlCreateButton("Calculating automaticly!", 10, 180+$plussize, 299, 25)
GUISetState(@SW_SHOW)
$timer = TimerInit()
While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Button1
         _Calc()
      Case $Button2
         If GUICtrlRead($Button2) = "Calculating automaticly!" then
            GUICtrlSetData($Button2, "Not calculating automaticly...")
            $CalcAuto = False
         Else
            GUICtrlSetData($Button2, "Calculating automaticly!")
            $CalcAuto = True
         EndIf
   EndSwitch
   If $CalcAuto = True then _Calc()
   Sleep(25)
WEnd
Func _Calc()
   $Answer = 0
   For $CalcCheckboxAnswers=1 to $HowManyCheckboxs
      If Execute("GUICtrlRead($Checkbox"&$CalcCheckboxAnswers&")") = $GUI_CHECKED Then
         $Calc = 0.5
         For $I=1 to $CalcCheckboxAnswers
            $Calc *= 2
         Next
         $Answer = $Answer + $Calc
      EndIf
   Next
   $OutputSend = "Calculating automaticly:"&@CRLF&$answer
   If GUICtrlRead($Output) <> $OutputSend then GUICtrlSetData( $Output, $OutputSend)
EndFunc

Just expermenting :3 I don't know if it will work correctly, but it should. :)

Edited by algiuxas

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

  • Moderators

Why needlessly complicate the process by introducing a bunch of Mouse and Caret calls, when JFish's example does just what the OP is asking for?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

In this case you can use a * 2^i:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 319, 216, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox(" 1", 48, 56, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox(" 2", 48, 88, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox(" 4", 48, 120, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox(" 8", 216, 56, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("16", 216, 88, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox(" 32", 216, 120, 97, 17)
$Button1 = GUICtrlCreateButton("plus any checked boxes", 64, 160, 155, 25)
GUISetState(@SW_SHOW)

Global $iSum
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            $iSum = 0
            For $i = 0 To 5
                $iSum += BitAND(GUICtrlRead(Execute("$Checkbox" & $i + 1)), $GUI_CHECKED) * 2^$i
            Next
            MsgBox(0, "Sum", $iSum)
    EndSwitch
WEnd

 

Edited by UEZ

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

@UEZ - you are a wizard.  Cool solution.  :cheer:

 

 

In this case you can use a * 2^i:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 319, 216, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox(" 1", 48, 56, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox(" 2", 48, 88, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox(" 4", 48, 120, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox(" 8", 216, 56, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("16", 216, 88, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox(" 32", 216, 120, 97, 17)
$Button1 = GUICtrlCreateButton("plus any checked boxes", 64, 160, 155, 25)
GUISetState(@SW_SHOW)

Global $iSum
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            $iSum = 0
            For $i = 0 To 5
                $iSum += BitAND(GUICtrlRead(Execute("$Checkbox" & $i + 1)), $GUI_CHECKED) * 2^$i
            Next
            MsgBox(0, "Sum", $iSum)
    EndSwitch
WEnd

 

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

$iSum = 0
For $i = $Checkbox1 To $Checkbox6
    $iSum += 2 ^ ( $i - $Checkbox1 ) * ( GUICtrlRead( $i ) = $GUI_CHECKED )
Next
MsgBox( 0, "Sum", $iSum )

 

Link to comment
Share on other sites

oh my god, many solutions..

The difficult issue is converting the result to hexadecimal.

For hex conversation you can use the built-in Hex function.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $HowManyCheckboxs = 12
Global $Answer = 0
Global $Calc = 0.5
Global $CalcAuto = True
Global $trans = True
Global $plussize = 200
Global $GUI = GUICreate("Calculate", 319, 216+200+$plussize, 192, 124)
WinSetTrans( $GUI, "", 250 )
Global $Checkbox1 = GUICtrlCreateCheckbox("1",      70*1, 56*1, 55, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("2",      70*2, 56*1, 55, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("4",      70*3, 56*1, 55, 17)
Global $Checkbox4 = GUICtrlCreateCheckbox("8",      70*1, 56*2, 55, 17)
Global $Checkbox5 = GUICtrlCreateCheckbox("16",     70*2, 56*2, 55, 17)
Global $Checkbox6 = GUICtrlCreateCheckbox("32",     70*3, 56*2, 55, 17)
Global $Checkbox7 = GUICtrlCreateCheckbox("64",     70*1, 56*3, 55, 17)
Global $Checkbox8 = GUICtrlCreateCheckbox("126",    70*2, 56*3, 55, 17)
Global $Checkbox9 = GUICtrlCreateCheckbox("256",    70*3, 56*3, 55, 17)
Global $Checkbox10 = GUICtrlCreateCheckbox("512",   70*1, 56*4, 55, 17)
Global $Checkbox11 = GUICtrlCreateCheckbox("1024",  70*2, 56*4, 55, 17)
Global $Checkbox12 = GUICtrlCreateCheckbox("2048",  70*3, 56*4, 55, 17)
Global $Output =     GUICtrlCreateEdit("", 10, 216+$plussize, 319-20, 200-10)
Global $Button1 =    GUICtrlCreateButton("Calculate!", 10, 150+$plussize, 299, 25)
Global $Button2 =    GUICtrlCreateButton("Calculating automaticly!", 10, 180+$plussize, 299, 25)
GUISetState(@SW_SHOW)

Global $iSum
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            $iSum = 0
            For $i = 0 To 11
                $iSum += BitAND(GUICtrlRead(Execute("$Checkbox" & $i + 1)), $GUI_CHECKED) * 2^$i
            Next
            GUICtrlSetData($Output, $iSum & " (0x" & Hex(Int($iSum), 8) & ")")
    EndSwitch
WEnd

You can also use LarsJ version to calculate the sum. ;)

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

Sorry, I couldn't help it.

#include <GUIConstantsEx.au3>

Opt( "MustDeclareVars", 1 )

Example(31) ; Number of check boxes, 2 - 31

Func Example( $iCbs ) ; $iCbs = number of check boxes, 2 - 31
  GUICreate( "Calculate check boxes", 250, 10+30*Int(($iCbs-1)/3)+60 )

  Local $idCbFirst = GUICtrlCreateCheckbox( "2^0", 10, 10, 70, 20 )
  For $i = 1 To $iCbs - 1
    GUICtrlCreateCheckbox( "2^" & $i, 10+80*Mod($i,3), 10+30*Int($i/3), 70, 20 )
  Next

  GUICtrlCreateLabel( "", 10, 10+30*Int(($iCbs-1)/3)+30, 230, 20, 0x12 ) ; 0x12 = $SS_ETCHEDFRAME
  Local $idSum = GUICtrlCreateLabel( "0  (0x" & Hex(0,8) & ")", 12, 10+30*Int(($iCbs-1)/3)+32, 226, 16 )

  GUISetState()
  Local $iMsg, $iSum

  While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
      Case $idCbFirst To $idCbFirst + $iCbs - 1
        $iSum = 0
        For $i = 0 To $iCbs - 1
          $iSum += 2 ^ $i * ( GUICtrlRead( $i + $idCbFirst ) = $GUI_CHECKED )
        Next
        GUICtrlSetData( $idSum, $iSum & "  (0x" & Hex(Int($iSum), 8) & ")" )

      Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
  WEnd
EndFunc

 

Edited by LarsJ
Optimized code
Link to comment
Share on other sites

Optimized code: Second for-loop not required.

#include <GUIConstantsEx.au3>

Opt( "MustDeclareVars", 1 )

Example(31) ; Number of check boxes, 1 - 31

Func Example( $iCbs ) ; $iCbs = number of check boxes, 1 - 31
  GUICreate( "Calculate check boxes", 250, 10+30*Int(($iCbs-1)/3)+60 )

  Local $idCbFirst = GUICtrlCreateCheckbox( "2^0", 10, 10, 70, 20 )
  For $i = 1 To $iCbs - 1
    GUICtrlCreateCheckbox( "2^" & $i, 10+80*Mod($i,3), 10+30*Int($i/3), 70, 20 )
  Next

  GUICtrlCreateLabel( "", 10, 10+30*Int(($iCbs-1)/3)+30, 230, 20, 0x12 ) ; 0x12 = $SS_ETCHEDFRAME
  Local $idSum = GUICtrlCreateLabel( "0  (0x" & Hex(0,8) & ")", 12, 10+30*Int(($iCbs-1)/3)+32, 226, 16 )

  GUISetState()
  Local $iMsg, $iSum = 0

  While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
      Case $idCbFirst To $idCbFirst + $iCbs - 1
        $iSum += 2 ^ ( $iMsg - $idCbFirst ) * ( GUICtrlRead( $iMsg ) = $GUI_CHECKED ? +1 : -1 )
        GUICtrlSetData( $idSum, $iSum & "  (0x" & Hex( Int( $iSum ), 8 ) & ")" )

      Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
  WEnd
EndFunc

 

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
Local $sFont = "courier new", $dec = 0, $sDummy = 0, $Ckboxs = 16, $aDigit[$Ckboxs], $GUI = GUICreate("Bits converter", 25 * ($Ckboxs), 260)
For $i = 0 To $Ckboxs - 1
    GUICtrlCreateLabel(StringRegExpReplace(StringFormat("%05u", 2 ^ ($i), 10), "(.)", " $1"), 25 * ($Ckboxs - $i - 1) + 5, 10, 15, 70, $SS_RIGHT + $SS_SUNKEN)
    $aDigit[$i] = GUICtrlCreateCheckbox("", 25 * ($Ckboxs - $i - 1) + 5, 85, 20, 20)
Next
$sDummy = GUICtrlCreateLabel("Decimal:", 8, 127, 70, 35) + GUICtrlCreateLabel("Hexadecimal:", 8, 169, 70, 35) + GUICtrlCreateLabel("Octal:", 8, 211, 70, 35)
Local $Input1 = GUICtrlCreateInput(0, 80, 127, 130, 35, $SS_RIGHT + $ES_READONLY), $sDummy = GUICtrlSetFont(-1, 24, 700, 0, $sFont)
Local $Input2 = GUICtrlCreateInput(0, 80, 169, 130, 35, $SS_RIGHT + $ES_READONLY), $sDummy = GUICtrlSetFont(-1, 24, 700, 0, $sFont)
Local $Input3 = GUICtrlCreateInput(0, 80, 211, 130, 35, $SS_RIGHT + $ES_READONLY), $sDummy = GUICtrlSetFont(-1, 24, 700, 0, $sFont)
GUISetState(@SW_SHOW)
Do
    $nMsg = GUIGetMsg()
    For $x = 0 To UBound($aDigit) - 1
        Switch $nMsg
            Case $aDigit[$x]
                $dec = 0
                For $i = 0 To UBound($aDigit) - 1
                    $dec += (2 ^ $i) * (GUICtrlRead($aDigit[$i]) = 1)
                Next
                $sDummy = GUICtrlSetData($Input1, $dec) + GUICtrlSetData($Input2, StringFormat("%X", $dec)) + GUICtrlSetData($Input3, StringFormat("%o", $dec))
                ExitLoop
        EndSwitch
    Next
Until $nMsg = $GUI_EVENT_CLOSE

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...