Prozentrechner

  • Könnte mir bitte jemand ein % Rechner schreiben, wo ich dann z.B. eingeben kann, dass er ausrechnen soll, wv von 35 Euro 7% sind?

    Also zuerst soll man die Zahl eingeben und in die nächste Input Box die % , die ausgerechnet werden soll.

    Beispiel :

    erste Inputbox : 300

    zweite Inputbox : 10 ; wv Prozent ausgerechnet werden sollen

    Ergebniss : 30

  • So?

    Spoiler anzeigen
    [autoit]

    $nGesamtwert = InputBox("Prozentrechner", "Gesamtwert")
    $nProzentsatz = InputBox("Prozentrechner", "Prozentsatz")

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

    MsgBox(64, "Ergebnis", $nGesamtwert * ($nProzentsatz / 100) & "%" & @CRLF & "Thanks for using the Percentage Calculator by name22. Please visit http://www.autoit.de.")

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

    ;Copyright name22 (autoit.de) - Donnerstag, 11. August 2011 (All rights belong to me).

    [/autoit]
  • Ja danke bist ein Gott.

    Habe irgendwie vergessen, wie die Prozentrechnung geht.

    Normalerweise kann ich es aber heute weiß ich nichts.

    Zitat

    ;Copyright name22 (autoit.de) - Donnerstag, 11. August 2011 (Allrights belong to me).

    :rofl::rofl::rofl::rofl::rofl:

  • Teste mal dies:

    Spoiler anzeigen
    [autoit]


    ;coded by UEZ 2011
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    $hGUI = GUICreate("Prozentrechnung", 615, 277)
    $idLabelLogo = GUICtrlCreateLabel("Prozentrechnung", 16, 8, 583, 101)
    GUICtrlSetFont(-1, 64, 400, 0, "Times New Roman")
    $idLabelG = GUICtrlCreateLabel("Grundwert G=", 32, 136, 134, 28)
    GUICtrlSetFont(-1, 16, 400, 0, "Arial")
    GUICtrlSetTip(-1, "G=W/p*100")
    $idLabelW = GUICtrlCreateLabel("Prozentwert W=", 14, 176, 154, 28)
    GUICtrlSetFont(-1, 16, 400, 0, "Arial")
    GUICtrlSetTip(-1, "W=G*p/100")
    $idLabelp = GUICtrlCreateLabel("Prozentsatz p=", 25, 216, 142, 28)
    GUICtrlSetFont(-1, 16, 400, 0, "Arial")
    GUICtrlSetTip(-1, "p=W/G*100")
    $idGrundwert = GUICtrlCreateInput("0", 168, 136, 250, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Arial")
    $idProzentwert = GUICtrlCreateInput("0", 168, 174, 250, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Arial")
    $idProzentsatz = GUICtrlCreateInput("0", 168, 213, 250, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Arial")
    $idExit = GUICtrlCreateButton("Exit", 545, 209, 50, 32)
    GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman")
    $idCalcG = GUICtrlCreateButton("Calc G", 425, 136, 75, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman")
    $idCalcW = GUICtrlCreateButton("Calc W", 425, 176, 75, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman")
    $idCalcp = GUICtrlCreateButton("Calc p", 425, 216, 75, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman")
    GUISetState(@SW_SHOW)

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

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE, $idExit
    GUIDelete($hGUI)
    Exit
    Case $idCalcG
    Calculate("G")
    Case $idCalcW
    Calculate("W")
    Case $idCalcp
    Calculate("p")
    EndSwitch
    WEnd

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

    Func Calculate($prozent)
    Local $G = GUICtrlRead($idGrundwert)
    Local $W = GUICtrlRead($idProzentwert)
    Local $p = GUICtrlRead($idProzentsatz)
    Switch $prozent
    Case "G"
    If $p = 0 Then Return MsgBox(16, "Error", "p = 0")
    GUICtrlSetData($idGrundwert, Round($W / $p * 100, 2)) ;G=W/p*100
    Case "W"
    GUICtrlSetData($idProzentwert, Round($G * $p / 100, 2)) ;W=G*p/100
    Case "p"
    If $G = 0 Then Return MsgBox(16, "Error", "G = 0")
    GUICtrlSetData($idProzentsatz, Round($W / $g * 100, 2)) ;p=W/G*100
    EndSwitch
    EndFunc

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

    Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $control_id = BitAND($wParam, 0x0000FFFF)
    Switch $control_id
    Case $idGrundwert
    GUICtrlSetData($idGrundwert, CheckInput($idGrundwert))
    Case $idProzentwert
    GUICtrlSetData($idProzentwert, CheckInput($idProzentwert))
    Case $idProzentsatz
    GUICtrlSetData($idProzentsatz, CheckInput($idProzentsatz))
    EndSwitch
    Return "GUI_RUNDEFMSG"
    EndFunc

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

    Func CheckInput($control_id)
    Local $number = StringRegExpReplace(GUICtrlRead($control_id), "[^0-9.]", "")
    StringReplace($number, ".", ".")
    If @extended > 1 Then $number = StringLeft($number, StringInStr($number, ".", 0, 2) - 1)
    Return $number
    EndFunc

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯