Benutzer mit den meisten Antworten
vba Excel - dynamische Button - Anzahl per cboBox in einer Zeile steuern

Frage
-
Hallo @ all,
ich habe in einem Frame 6 Button nebeneinander und davon 8 Zeilen
Ich bin jeweils von 10 Minuten ausgegangen im Zeitraum zwischen 8:00 und 16:00 Uhr. Dies habe ich mit einer Schleife gelöst
Public Function CreateMyButton(ByVal myStart As Long, _ ByVal myEnd As Long, _ ByVal dDate As Date) 'Das "Set myClass as New cls_Test" muss vor jede Zuweisung 'eines Objekts an die Klasse, da sonst die alte Zuweisung 'überschrieben wird. Dim myClass As cls_Test Dim btnText As String Dim myPosition As Integer ' von Links Dim myTop As Integer ' von oben Dim myBreite As Integer Dim myHoehe As Integer Dim i As Integer ' Zähler Dim x As Integer Dim myWert As Long myTop = 5 myHoehe = 0 For x = myStart To myEnd - 1 myPosition = 10 myWert = 0 'Spalten erstellen For i = 1 To 6 Set myClass = New cls_Test Set myClass.myToggle = UserForm1.Controls.Item _ ("Frame_Neu").Add("Forms.ToggleButton.1", btnText, True) myBreite = 0 With myClass.myToggle .Left = myPosition .Height = 24 .Top = myTop .Width = Breite .Font.Size = 8 If i = 6 Then ' Termin zur vollen Stunde hin => Stunde + 1 .Caption = Format(CStr(x), "##00") + ":" & Format(myWert, "##00") & "-" _ & Format(CStr(x + 1), "##00") + ":00" .ControlTipText = "frei" .Value = True .BackColor = &HC0C0FF Else .Caption = Format(CStr(x), "##00") + ":" & Format(myWert, "##00") & "-" & _ Format(CStr(x), "##00") + ":" & Format(myWert + 10, "##00") .ControlTipText = "termin " .BackColor = &HC0FFC0 End If myWert = myWert + H_Zuschlag myPosition = myPosition + Breite End With myColl.Add myClass Next i myTop = myTop + 24 Next x
Wie kann ich jetzt O_O erreichen, dass in einer cboBox, ein Intervall gewählt werden kann:
Also10 min Intervall = siehe Bild
15 min Intervall = nur noch 4 Button pro Zeile
20 min Intervall = nur noch 3 Button pro Zeile
30 min Intervall = nur noch 2 Button pro Zeile
plus jeweils die entsprechende Beschriftung. Kann ich dies irgendwie mit einbauen?
Einfach die Function 3 weitere mal mit geänderten Schleifen .....
geht doch bestimmt professioneller?!Gruß
Werner
Woher soll ich wissen, was ich denke, bevor ich höre, was ich sage?
Antworten
-
Hallo Werner,
übergib doch der Funktion einen weiteren Parameter Intervall. Diese Intervall benutzt Du im Schleifenkopf der Spalten:
For i = 1 To (60 / Intervall)
und weiter unten benutzt Du den Parameter Intervall für die Ausgabe (Caption). myWert könnte man weg lassen, wenn Du noch die Schleifenvariable verwendest
If i = (60 / Intervall) Then
' Termin zur vollen Stunde hin => Stunde + 1
.Caption = Format(CStr(x), "##00") + ":" & Format((i-1)*Intervall, "##00") & "-" _
& Format(CStr(x + 1), "##00") + ":00"
.ControlTipText = "frei"
.Value = True
.BackColor = &HC0C0FF
Else
.Caption = Format(CStr(x), "##00") + ":" & Format((i-1)*Intervall, "##00") & "-" & _
Format(CStr(x), "##00") + ":" & Format( i * Intervall, "##00")
.ControlTipText = "termin "
.BackColor = &HC0FFC0
End IfSo müsstest Du mit einer einzigen Funktion parat kommen.
Gruß
Viktor
- Als Antwort markiert w.woerny Donnerstag, 23. Februar 2012 07:27
Alle Antworten
-
Hallo Werner,
übergib doch der Funktion einen weiteren Parameter Intervall. Diese Intervall benutzt Du im Schleifenkopf der Spalten:
For i = 1 To (60 / Intervall)
und weiter unten benutzt Du den Parameter Intervall für die Ausgabe (Caption). myWert könnte man weg lassen, wenn Du noch die Schleifenvariable verwendest
If i = (60 / Intervall) Then
' Termin zur vollen Stunde hin => Stunde + 1
.Caption = Format(CStr(x), "##00") + ":" & Format((i-1)*Intervall, "##00") & "-" _
& Format(CStr(x + 1), "##00") + ":00"
.ControlTipText = "frei"
.Value = True
.BackColor = &HC0C0FF
Else
.Caption = Format(CStr(x), "##00") + ":" & Format((i-1)*Intervall, "##00") & "-" & _
Format(CStr(x), "##00") + ":" & Format( i * Intervall, "##00")
.ControlTipText = "termin "
.BackColor = &HC0FFC0
End IfSo müsstest Du mit einer einzigen Funktion parat kommen.
Gruß
Viktor
- Als Antwort markiert w.woerny Donnerstag, 23. Februar 2012 07:27
-
Hallo Viktor,
sorry für die verspätete Antwort! Bin leider nicht früher an mein Projekt gekommen.
Da ich dem Anwender in einer cboBox die Auswahl 10, 15, 20 und 30 (Minuten) anbiete, habe ich deinen Tipp so umgesetzt... myIntervall = 60 / UserForm1.cboIntervall.Text ... If i = myIntervall Then ' Termin zur vollen Stunde hin => Stunde + 1 .Caption = Format(CStr(x), "##00") + ":" & Format((i - 1) * (60 / myIntervall), "##00") & "-" _ & Format(CStr(x + 1), "##00") + ":00" .ControlTipText = "frei" .Value = True .BackColor = &HC0C0FF Else .Caption = Format(CStr(x), "##00") + ":" & Format((i - 1) * (60 / myIntervall), "##00") & "-" _ & Format(CStr(x), "##00") + ":" & Format(i * (60 / myIntervall), "##00") .ControlTipText = "termin " .BackColor = &HC0FFC0 End If
und .....
es klappt einwandfrei *SUPER* - dank DirGruß
WernerWoher soll ich wissen, was ich denke, bevor ich höre, was ich sage?