• Hi,

    kein Plan, wofür man das brauchen könnte (vermutlich zum "lernen" :D)

    Spoiler anzeigen
    [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    $Form1_1 = GUICreate("Bit Anzeiger", 226, 83, 192, 114)
    $Button1 = GUICtrlCreateButton("0", 16, 16, 19, 25, $WS_GROUP)
    $Button2 = GUICtrlCreateButton("0", 40, 16, 19, 25, $WS_GROUP)
    $Button3 = GUICtrlCreateButton("0", 64, 16, 19, 25, $WS_GROUP)
    $Button4 = GUICtrlCreateButton("0", 88, 16, 19, 25, $WS_GROUP)
    $Label1 = GUICtrlCreateLabel("•", 112, 32, 8, 18)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    $Button5 = GUICtrlCreateButton("0", 120, 16, 19, 25, $WS_GROUP)
    $Button6 = GUICtrlCreateButton("0", 144, 16, 19, 25, $WS_GROUP)
    $Button7 = GUICtrlCreateButton("0", 168, 16, 19, 25, $WS_GROUP)
    $Button8 = GUICtrlCreateButton("0", 192, 16, 19, 25, $WS_GROUP)
    $out = GUICtrlCreateInput("", 16, 48, 65, 21)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
    GUICtrlSetData($Button1, BitXOR(GUICtrlRead($Button1),1))
    GUICtrlSetData($out, bin2dec(GUICtrlRead($Button1) & GUICtrlRead($Button2) & GUICtrlRead($Button3) & GUICtrlRead($Button4) & _
    GUICtrlRead($Button5) & GUICtrlRead($Button6) & GUICtrlRead($Button7) & GUICtrlRead($Button8)))
    Case $Button2
    GUICtrlSetData($Button2, BitXOR(GUICtrlRead($Button2),1))
    GUICtrlSetData($out, bin2dec(GUICtrlRead($Button1) & GUICtrlRead($Button2) & GUICtrlRead($Button3) & GUICtrlRead($Button4) & _
    GUICtrlRead($Button5) & GUICtrlRead($Button6) & GUICtrlRead($Button7) & GUICtrlRead($Button8)))
    Case $Button3
    GUICtrlSetData($Button3, BitXOR(GUICtrlRead($Button3),1))
    GUICtrlSetData($out, bin2dec(GUICtrlRead($Button1) & GUICtrlRead($Button2) & GUICtrlRead($Button3) & GUICtrlRead($Button4) & _
    GUICtrlRead($Button5) & GUICtrlRead($Button6) & GUICtrlRead($Button7) & GUICtrlRead($Button8)))
    Case $Button4
    GUICtrlSetData($Button4, BitXOR(GUICtrlRead($Button4),1))
    GUICtrlSetData($out, bin2dec(GUICtrlRead($Button1) & GUICtrlRead($Button2) & GUICtrlRead($Button3) & GUICtrlRead($Button4) & _
    GUICtrlRead($Button5) & GUICtrlRead($Button6) & GUICtrlRead($Button7) & GUICtrlRead($Button8)))
    Case $Button5
    GUICtrlSetData($Button5, BitXOR(GUICtrlRead($Button5),1))
    GUICtrlSetData($out, bin2dec(GUICtrlRead($Button1) & GUICtrlRead($Button2) & GUICtrlRead($Button3) & GUICtrlRead($Button4) & _
    GUICtrlRead($Button5) & GUICtrlRead($Button6) & GUICtrlRead($Button7) & GUICtrlRead($Button8)))
    Case $Button6
    GUICtrlSetData($Button6, BitXOR(GUICtrlRead($Button6),1))
    GUICtrlSetData($out, bin2dec(GUICtrlRead($Button1) & GUICtrlRead($Button2) & GUICtrlRead($Button3) & GUICtrlRead($Button4) & _
    GUICtrlRead($Button5) & GUICtrlRead($Button6) & GUICtrlRead($Button7) & GUICtrlRead($Button8)))
    Case $Button7
    GUICtrlSetData($Button7, BitXOR(GUICtrlRead($Button7),1))
    GUICtrlSetData($out, bin2dec(GUICtrlRead($Button1) & GUICtrlRead($Button2) & GUICtrlRead($Button3) & GUICtrlRead($Button4) & _
    GUICtrlRead($Button5) & GUICtrlRead($Button6) & GUICtrlRead($Button7) & GUICtrlRead($Button8)))
    Case $Button8
    GUICtrlSetData($Button8, BitXOR(GUICtrlRead($Button8),1))
    GUICtrlSetData($out, bin2dec(GUICtrlRead($Button1) & GUICtrlRead($Button2) & GUICtrlRead($Button3) & GUICtrlRead($Button4) & _
    GUICtrlRead($Button5) & GUICtrlRead($Button6) & GUICtrlRead($Button7) & GUICtrlRead($Button8)))
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func bin2dec($strBin)
    Local $Return
    Local $lngResult
    Local $intIndex

    [/autoit] [autoit][/autoit] [autoit]

    If StringRegExp($strBin,'[0-1]') then
    $lngResult = 0
    For $intIndex = StringLen($strBin) to 1 step -1
    $strDigit = StringMid($strBin, $intIndex, 1)
    Select
    case $strDigit="0"
    case $strDigit="1"
    $lngResult = $lngResult + (2 ^ (StringLen($strBin)-$intIndex))
    case else
    $lngResult = 0
    $intIndex = 0
    EndSelect
    Next

    [/autoit] [autoit][/autoit] [autoit]

    $Return = $lngResult
    Return $Return
    EndIf
    EndFunc

    [/autoit]

    Beschreibung: Selbsterklärend!

    Gruß
    x0r

    Simon nörgelt, Simon nervt - aber Simon verbessert die Welt. Glaubt er.

  • Schön, aber das geht auch etwas ( :D ) kürzer und übersichtlicher:

    Spoiler anzeigen
    [autoit]

    Opt("GUIOnEventMode", 1)
    Local $aBits[8], $c = 0

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("Bits", 205, 60)
    GUISetOnEvent(-3, "quit")
    For $x = 0 To 7
    $aBits[$c] = GUICtrlCreateButton("0", $x*25+5, 5, 20, 20)
    GUICtrlSetOnEvent(-1, "update")
    $c += 1
    Next
    $hOutput = GUICtrlCreateInput("0", 5, 30, 195, 21)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func update()
    If GUICtrlRead(@GUI_CtrlId) = "0" Then
    GUICtrlSetData(@GUI_CtrlId, "1")
    Else
    GUICtrlSetData(@GUI_CtrlId, "0")
    EndIf
    Local $Bin = ""
    For $i = 0 To 7
    $Bin &= GUICtrlRead($aBits[$i])
    Next
    GUICtrlSetData($hOutput, _BinaryToDec($Bin))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func quit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _BinaryToDec($strBin)
    Local $lngResult = 0
    For $intIndex = StringLen($strBin) to 1 step -1
    Switch StringMid($strBin, $intIndex, 1)
    case "0"
    case "1"
    $lngResult += (2^(StringLen($strBin)-$intIndex))
    case else
    ExitLoop
    EndSwitch
    Next
    Return $lngResult
    EndFunc

    [/autoit]
  • Ich war mal so frei und habe dein Skript ein wenig gekürzt:

    [autoit]


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

    [/autoit][autoit][/autoit][autoit]

    $Form1_1 = GUICreate("Bit Anzeiger", 226, 83, 192, 114)
    $Label1 = GUICtrlCreateLabel("•", 112, 32, 8, 18)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    Global $aButtons[8], $aBits[8], $iX = 16, $iVal, $i
    For $i = 0 To 7
    $aButtons[$i] = GUICtrlCreateButton("0", $iX + $i * 24, 16, 19, 25, $WS_GROUP)
    If $i = 3 Then $iX += 10
    Next
    $out = GUICtrlCreateInput("", 16, 48, 65, 21)
    GUISetState(@SW_SHOW)

    [/autoit][autoit][/autoit][autoit]

    While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
    Case $GUI_EVENT_CLOSE
    GUIDelete()
    Exit
    Case $aButtons[0] To $aButtons[7]
    $iPos = $iMsg - $aButtons[0]
    $iBit = BitXOR($aBits[$iPos], 1)
    $aBits[$iPos] = $iBit
    GUICtrlSetData($aButtons[$iPos], $iBit)
    For $i = 7 To 0 Step - 1
    $iVal += 2 ^ (7 - $i) * $aBits[$i]
    Next
    GUICtrlSetData($out, $iVal)
    $iVal = 0
    EndSwitch
    WEnd

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • pff, kürzer :D

    [autoit]

    $aButtons[$i] = GUICtrlCreateButton("0", $iX+(($i>3)*10) + $i * 24, 16, 19, 25, $WS_GROUP)
    ;If $i = 3 Then $iX += 10

    [/autoit]

    so macht man das :D
    und in der Case kann man auch noch drei Zeilen rausschinden, aber ansonsten :thumbup:

    und btw.:

    [autoit]

    ;~ If GUICtrlRead(@GUI_CtrlId) = "0" Then
    GUICtrlSetData(@GUI_CtrlId, 1*(not(number(GUICtrlRead(@GUI_CtrlId)))))
    ;~ Else
    ;~ GUICtrlSetData(@GUI_CtrlId, "0")
    ;~ EndIf

    [/autoit]

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    Einmal editiert, zuletzt von Andy (27. April 2013 um 20:37)


  • Das mit

    [autoit]


    $aButtons[$i] = GUICtrlCreateButton("0", $iX + (($i > 3) * 10) + $i * 24, 16, 19, 25, $WS_GROUP)

    [/autoit]


    ist eine klasse Idee! Warum bin ich nicht selbst darauf gekommen? Kann sein, dass es an der Uhrzeit hing. ;)

    Die 3 Zeilen rauszuschmeißen macht die Sache leider unübersichtlich und nicht wirklich kürzer, eher länger, außer die Anzahl der Zeilennummern, denn man wiederholt immer wieder Teile von den Zeilen.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Zitat

    ist eine klasse Idee! Warum bin ich nicht selbst darauf gekommen? Kann sein, dass es an der Uhrzeit hing.

    Guck mal in den Spiegel :D
    Bei Typen wie uns spricht man nicht mehr von Uhrzeit, sondern von ALTER! :rofl: