Pastekan kode pada userform
Option Explicit
Dim
CollectBouton As Collection
Dim
ClGroup As Collection
Dim
mBouton As Cl_Bouton
Private
Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As
Integer)
If KeyCode = 13 Then
ControlClick 11
End If
End
Sub
Private Sub UserForm_Initialize()
Dim
Ctl As Control
Set CollectBouton = New Collection
Set ClGroup = New Collection
For Each Ctl In Me.Controls
If TypeOf Ctl Is MSForms.CommandButton
Then
Set mBouton = New Cl_Bouton
Set mBouton.GroupBoutons = Ctl
CollectBouton.Add mBouton
ClGroup.Add Ctl, Ctl.Tag
End If
Next Ctl
End
Sub
Public Sub ControlClick(Index As Integer)
Select Case Index
Case Is < 10: AjouterSurText CStr(Index)
Case Is = 10:
AjouterSurText ","
Case Is = 11
On Error GoTo
ErreurCalcul
Label1.Caption =
Evaluate(Replace(TextBox1.Text, ",", "."))
Case Is < 18
AjouterSurText
ClGroup(CStr(Index)).Caption
Case 18: If
TextBox1.SelLength > 0 Then AjouterSurText ""
Case 19: TextBox1 = "": Label1 = ""
End Select
Exit Sub
ErreurCalcul:
MsgBox "Votre calcul comporte une erreur", vbCritical,
"Calculatrice"
End Sub
Sub AjouterSurText(T As String)
If Len(TextBox1.Text) =
TextBox1.SelStart Then
TextBox1 = TextBox1
& T
Else
TextBox1 =
Left(TextBox1, TextBox1.SelStart) & T _
& Mid(TextBox1,
TextBox1.SelStart + 1 + TextBox1.SelLength)
End If
TextBox1.SetFocus
End Sub
Pastekan kode pada classModul
Option Explicit
Public WithEvents GroupBoutons As MSForms.CommandButton
Private Sub GroupBoutons_Click()
Call
UserCalculate.ControlClick(GroupBoutons.Tag)
End Sub
No comments:
Post a Comment