- Offizieller Beitrag
Hi,
sicher wird niemand das Proggi brauchen können aber ich zeigs euch trotzdem mal.
Fragestellung war: Wie kann ich einen beliebigen Geldbetrag auf die minimale Anzahl Banknoten und Münzen verteilen.
Ich denke das Ergebnis sieht ganz hübsch aus
Zum Testen braucht ihr die angehängte Datei "Euro.zip", wegen der Bildchen
Spoiler anzeigen
#include <GUIConstants.au3>
Dim $backcolor = 0x4A579B, $fcolor = 0xFFD700
Dim $picpath = "D:\Eigene Bilder\Euro\"
Dim $arVal[15], $arLabel[15], $arCheckBtn[15][2], $arCheck[15]
For $i = 0 To 14
$arCheckBtn[$i][1] = 1
Next
$arVal[0] = 500
$arVal[1] = 200
$arVal[2] = 100
$arVal[3] = 50
$arVal[4] = 20
$arVal[5] = 10
$arVal[6] = 5
$arVal[7] = 2
$arVal[8] = 1
$arVal[9] = 0.5
$arVal[10] = 0.2
$arVal[11] = 0.1
$arVal[12] = 0.05
$arVal[13] = 0.02
$arVal[14] = 0.01
$Form1 = GUICreate("Geldbetrag stückeln", 500, 504, -1, -1)
GUISetBkColor($backcolor)
GUICtrlCreatePic($picpath & "500eur.jpg", 25, 32, 100, 51, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "200eur.jpg", 140, 33, 100, 54, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "100eur.jpg", 253, 32, 100, 56, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "50eur.jpg", 370, 31, 100, 55, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "20eur.jpg", 25, 118, 100, 54, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "10eur.jpg", 189, 121, 100, 53, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "5eur.jpg", 371, 121, 100, 53, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "2eur.jpg", 25, 215, 75, 75, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "1eur.jpg", 150, 215, 75, 75, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "50ct.jpg", 275, 215, 75, 75, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "20ct.jpg", 400, 215, 75, 75, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "10ct.jpg", 25, 320, 75, 75, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "5ct.jpg", 150, 320, 75, 75, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "2ct.jpg", 275, 320, 75, 75, BitOR($SS_NOTIFY,$WS_GROUP))
GUICtrlCreatePic($picpath & "1ct.jpg", 400, 320, 75, 75, BitOR($SS_NOTIFY,$WS_GROUP))
$arLabel[0] = GUICtrlCreateLabel("", 52, 11, 45, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
$arCheckBtn[0][0] = GUICtrlCreateButton("" ,25, 11, 12, 12, $BS_ICON)
$arCheckBtn[1][0] = GUICtrlCreateButton("" ,140, 11, 12, 12, $BS_ICON)
$arCheckBtn[2][0] = GUICtrlCreateButton("" ,253, 11, 12, 12, $BS_ICON)
$arCheckBtn[3][0] = GUICtrlCreateButton("" ,370, 11, 12, 12, $BS_ICON)
$arCheckBtn[4][0] = GUICtrlCreateButton("" ,25, 96, 12, 12, $BS_ICON)
$arCheckBtn[5][0] = GUICtrlCreateButton("" ,189, 96, 12, 12, $BS_ICON)
$arCheckBtn[6][0] = GUICtrlCreateButton("" ,371, 96, 12, 12, $BS_ICON)
$arCheckBtn[7][0] = GUICtrlCreateButton("" ,25, 190, 12, 12, $BS_ICON)
$arCheckBtn[8][0] = GUICtrlCreateButton("" ,150, 190,12,12, $BS_ICON)
$arCheckBtn[9][0] = GUICtrlCreateButton("" ,275, 190,12,12, $BS_ICON)
$arCheckBtn[10][0] = GUICtrlCreateButton("" ,400, 190,12,12, $BS_ICON)
$arCheckBtn[11][0] = GUICtrlCreateButton("" ,25, 297,12,12, $BS_ICON)
$arCheckBtn[12][0] = GUICtrlCreateButton("" ,150, 297,12,12, $BS_ICON)
$arCheckBtn[13][0] = GUICtrlCreateButton("" ,275, 297,12,12, $BS_ICON)
$arCheckBtn[14][0] = GUICtrlCreateButton("" ,400, 297,12,12, $BS_ICON)
For $i = 0 To 14
GUICtrlSetImage($arCheckBtn[$i][0], $picpath & "check12x12.ico")
Next
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[1] = GUICtrlCreateLabel("", 165, 11, 45, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[2] = GUICtrlCreateLabel("", 279, 11, 45, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[3] = GUICtrlCreateLabel("", 400, 11, 45, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[4] = GUICtrlCreateLabel("", 52, 96, 45, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[5] = GUICtrlCreateLabel("", 214, 96, 45, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[6] = GUICtrlCreateLabel("", 400, 96, 45, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[7] = GUICtrlCreateLabel("", 41, 190, 43, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[8] = GUICtrlCreateLabel("", 166, 190, 43, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[9] = GUICtrlCreateLabel("", 288, 190, 49, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[10] = GUICtrlCreateLabel("", 412, 190, 49, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[11] = GUICtrlCreateLabel("", 41, 297, 49, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[12] = GUICtrlCreateLabel("", 166, 297, 49, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[13] = GUICtrlCreateLabel("", 288, 297, 49, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$arLabel[14] = GUICtrlCreateLabel("", 412, 297, 49, 17, $SS_CENTER)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetState(-1, $GUI_CHECKED)
$Group1 = GUICtrlCreateGroup("Betrag", 24, 420, 453, 59)
GUICtrlSetFont(-1, 10, 500)
GUICtrlSetColor(-1, $fcolor)
$Input1 = GUICtrlCreateInput("", 64, 442, 141, 21, BitOR($ES_RIGHT,$ES_AUTOHSCROLL))
GUICtrlSetColor(-1, $backcolor)
GUICtrlSetBkColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetTip(-1, "Währung ganzzahlig oder mit maximal" & @LF & "2 Nachkommastellen eingeben." & @LF & "(Komma, nicht Dezimalpunkt verwenden.)")
$ret = _GUICtrlCreateColorButton("Stückelung", 316, 442, 125, 21, $backcolor, $fcolor)
$Button1 = $ret[0]
$Label16 = GUICtrlCreateLabel("EUR", 210, 445, 40, 17)
GUICtrlSetColor(-1, $fcolor)
GUICtrlSetFont(-1, 10, 500)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
GUICtrlSetState($Input1, $GUI_FOCUS)
ToolTip("Nicht verfügbare Werte können über die" & @LF & "jeweiligen Button abgewählt werden.", @DesktopWidth/2 -250, @DesktopHeight/2 -252)
Sleep(3500)
ToolTip("")
Do
$msg = GUIGetMsg()
For $i = 0 To 14
If $msg = $arCheckBtn[$i][0] Then
If $arCheckBtn[$i][1] = 0 Then
GUICtrlSetImage($arCheckBtn[$i][0], $picpath & "check12x12.ico")
$arCheckBtn[$i][1] = 1
ElseIf $arCheckBtn[$i][1] = 1 Then
GUICtrlSetImage($arCheckBtn[$i][0], $picpath & "uncheck12x12.ico")
$arCheckBtn[$i][1] = 0
EndIf
GUICtrlSetState($Input1, $GUI_FOCUS)
EndIf
Next
If $msg = $Button1 Then
GUICtrlSetStyle($Button1, $SS_ETCHEDFRAME)
Sleep(150)
GUICtrlSetStyle($Button1, $SS_NOTIFY + $SS_GRAYRECT)
_Berechnung()
EndIf
Until $msg = $GUI_EVENT_CLOSE
Func _Berechnung()
For $i = 0 To 14
GUICtrlSetData($arLabel[$i], "")
Next
$div = StringReplace(GUICtrlRead($Input1), ",", ".")
If _StringIsMoney($div) = 1 Then
If $div > 0 Then
For $i = 0 To 14
If ($div >= $arVal[$i] And $arCheckBtn[$i][1] = 1) Then
$G = Int($div / $arVal[$i])
If $G > 0 Then GUICtrlSetData($arLabel[$i], $G)
$R = Round($div - ($arVal[$i] * $G), 2)
If $R = 0 Then ExitLoop
$div = $R
EndIf
Next
If $R > 0 Then GUICtrlSetData($Input1, "Rest " & $div)
EndIf
Else
MsgBox(16, 'Achtung!', "Eingaben bitte ganzzahlig oder max. 2 Nachkommastellen!")
EndIf
GUICtrlSetState($Input1, $GUI_FOCUS)
EndFunc
Func _StringIsMoney($checkString)
Dim $len = StringLen($checkString)
If StringInStr($checkString, ".") Then
$val = StringSplit($checkString, ".")
If $val[0] > 2 Then Return 0
If ($len - StringInStr($checkString, ".")) > 2 Then Return 0
EndIf
For $i = 1 To $len
$tmp = StringMid($checkString, $i, 1)
If Not (StringIsInt($tmp) Or $tmp = ".") Then
Return 0
EndIf
Next
Return 1
EndFunc
;=============================================================================
;
; Function Name: _GUICtrlCreateColorButton()
;
; Description: Creates a colored Button
;
; Syntax: _GUICtrlCreateColorButton($text, $left, $top, $width, $height,$bkcolor[,$fontcolor])
;
; Parameter(s); $text = The text of the control
; $left = The left side of the control
; $top = The top of the control
; $width = The width of the control
; $height = The height of the control
; $bkcolor = Backgroundcolor of the control
; $fontcolor = [optional] Fontcolor of the control
;
; Return Value(s): array[1] = used to change colors
; array[0] = notifies GUIGetMsg if user clicks
;
; Author: rakudave <[email='rakudave@gmx.net'][/email]>
;=============================================================================
Func _GUICtrlCreateColorButton($text, $left, $top, $width, $height, $bkcolor, $fontcolor = -1)
Local $colbut[2]
If $fontcolor == -1 Then $fontcolor = 0x000000
$colbut[0] = GUICtrlCreateLabel("", $left, $top, $width, $height, $SS_BLACKRECT)
GUICtrlCreateLabel("", $left, $top, $width - 1, $height - 1, $SS_WHITERECT)
GUICtrlCreateLabel("", $left + 1, $top + 1, $width - 2, $height - 2, $SS_GRAYRECT)
$colbut[1] = GUICtrlCreateLabel($text, $left + 1, $top + 1, $width - 3, $height - 3, $SS_NOTIFY & $SS_CENTER)
GUICtrlSetBkColor(-1, $bkcolor)
GUICtrlSetColor(-1, $fontcolor)
GUICtrlSetFont(-1, 10, 500)
Return $colbut
EndFunc ;==>_GUICtrlCreateColorButton
EDIT:
- ein Bugfix (Danke snoozer für den Hinweis), Fehler in der Restbetragsberechnung.
Bsp.:
Basisbetrag = 20,54 lieferte 1x 20 EUR; 1x 50 ct; 1x 2 ct; 1x 1ct !! (Inflation )
Bei Ausgabe der Zwischenergebnisse ( $R = Mod($div, $arVal[$i]) ) war $R = 0,5399999 !!
Auch eine Umstellung auf: $R =$div - ($arVal[$i] * $G) führte zum identischen Fehler.
Naja, mit Round() gehts jetzt
- Neu dazugekommen: die einzelnen Geldwerte können bei Bedarf abgewählt werden, um nur in bestimmte Geldwerte zu wechseln.
Dazu bitte nochmal die "Euro.zip" laden, es sind Icons hinzugekommen.