I try to update some lable value for each textbox change. i searched and found this link and this link in website, but i still having trouble adopt it in my code. Because i have no idea how "class" work.
Code in Class named "QuoTxtBoxEvt":
Option Explicit
Private WithEvents TxtBoxGroup As MSForms.textbox
Public Sub TxtBoxGroup_Change()
With frmQuo
.TextBox28.value = Val(.TextBox8.value) * Val(.TextBox9.value)
.TextBox28.value = Val(.TextBox28.value) + (Val(.TextBox11.value) * Val(.TextBox12.value))
.TextBox28.value = Val(.TextBox28.value) + (Val(.TextBox14.value) * Val(.TextBox15.value))
.TextBox28.value = Val(.TextBox28.value) + (Val(.TextBox17.value) * Val(.TextBox18.value))
.TextBox28.value = Val(.TextBox28.value) + (Val(.TextBox20.value) * Val(.TextBox21.value))
.TextBox28.value = Val(.TextBox28.value) + (Val(.TextBox23.value) * Val(.TextBox23.value))
If .CheckBox1 = True Then .TextBox28.value = Val(.TextBox28.value) * (100 - Val(.TextBox26.value)) / 100
If .CheckBox2 = True Then .TextBox28.value = Val(.TextBox28.value) + (Val(.TextBox28.value) * Val(.TextBox27.value) / 100)
End With
End Sub
Code in userform:
Private Sub UserForm_Initialize()
'Variables for textbox change event handler
Dim TxtBoxGroupEventHandler() As New QuoTxtBoxEvt
Dim vfrmControl As Control
Dim i As Integer
'Event handler for textbox change to update total cost
i = 1
For Each vfrmControl In Me.Controls
If TypeName(vfrmControl) = "TextBox" Then
ReDim Preserve TxtBoxGroupEventHandler(1 To i)
Set TxtBoxGroupEventHandler(i).TxtBoxGroup = vfrmControl
i = 1 + i
End If
Next vfrmControl
End Sub
These my code so far, and it return an error. What i miss in my code? Can someone briefly teach me how to code "class"?
Many thank Orz
Edit: I got another method to achieve this by create a sub that update my value and call that sub in each textbox change event. But is this best way(correct way?) to do it? or using the class method is better?