| VB5, VB6 Create a Label for Automatic Totaling This class accepts numeric values from other controls and adds them into a total for display. In turn, the class can pass the value stored in its bound label to another instance of itself. Because totaling is done at the request of the calling object, the class must back off the calling object's old value when it updates the total. Private WithEvents lblTotal As Label Private mvarTotalReceiver As CTotalLabel Public Property Get Name() As String Name = lblTotal.Name End Property Public Property Get Container() As Control Set Container = lblTotal.Container End Property Public Property Get Caption() As String Caption = lblTotal.Caption End Property Public Property Let Caption(ByVal vData As String) lblTotal.Caption = vData End Property Public Property Get Alignment() As Integer Alignment = lblTotal.Alignment End Property Public Property Let Alignment(ByVal vData As Integer) lblTotal.Alignment = vData End Property Public Sub Init(ctl As Label) Set lblTotal = ctl End Sub Public Sub Recalculate(ByVal sngOld As Single, ByVal _ sngNew As Single) Dim sngOldTotal As Single Dim sngNewTotal As Single sngOldTotal = Val(lblTotal.Caption) sngNewTotal = sngOldTotal - sngOld + sngNew lblTotal.Caption = Format$(sngNewTotal, "#,##0.00") On Error Resume Next mvarTotalReceiver.Recalculate sngOldTotal, _ sngNewTotal End Sub Public Sub Clear() lblTotal.Caption = "0.00" End Sub |
Create a Label for Automatic Totaling |
Express News India | Freelance ecommerce web development India