在显示文本之前对文本输入执行 VB.net 中的代码

Do code in VB.net on text input before text being shown

我在 VB6 中有这段代码:

Private Sub t_Change(Index As Integer)
Iznos = 0
For i = 1 To 4
    Iznos = Iznos + t(i).Text
Next
If CDbl(Iznos) > Label13.Caption Then
    t(Index).Text = 0
    Iznos = 0
    t(Index).SelStart = 0
    t(Index).SelLength = 1
    For i = 1 To 4
        Iznos = Iznos + t(i).Text
    Next
End If
t(0).Text = Format(Label13.Caption - CDbl(Iznos), "#,##0.00")
End Sub

此代码适用于我的 textboxes(其中 4 个名为:t(0),t(1),t(2),t(3))。 我正在尝试使用 VB.net 实现相同的目标,但我似乎无法理解它。 这是我在 VB.Net:

中的代码
 Public Function izracunaj(ByVal s As Object)
    Dim ukupniIznos As Decimal = Decimal.Parse(maticnavalutatbox.Text)
    Dim poslaniIznos As Decimal = Decimal.Parse(s.text)
    Dim iznos As Decimal
    Dim allTextboxesPayment() As TextBox = {gotovinaTbox, karticeTbox, ostaloTbox, ziralnoTbox}
    For Each kontrola As TextBox In allTextboxesPayment
        iznos = iznos + Decimal.Parse(kontrola.Text)
    Next
    If CDbl(iznos) > ukupniIznos Then
        s.Text = 0
        iznos = 0
        For Each kontrola As TextBox In allTextboxesPayment
            iznos = iznos + Decimal.Parse(kontrola.Text)
        Next
    End If
    gotovinaTbox.Text = Format(ukupniIznos - CDbl(iznos), "#,##0.00")
End Function

但是如果我这样调用我的函数:

Private Sub ziralnoTbox_TextChanged(sender As Object, e As TextChangedEventArgs) Handles ziralnoTbox.TextChanged
izracunaj(sender)
End Sub

它不起作用,因为我的 izracunaj 函数已经有了 ziralnoTbox 的输入值。如何使用 vb.net 实现与 vb6

相同的功能

如果我没看错的话,你可以利用 TextChanged 事件。

Private Sub TextBox1_TextChanged(sender As Object,
                                     e As EventArgs) Handles gotovinaTbox.TextChanged,
                                                            karticeTbox.TextChanged, 
                                                            ostaloTbox.TextChanged,
                                                            ziralnoTbox.TextChanged
    Dim ukupniIznos As Decimal = Decimal.Parse(maticnavalutatbox.Text)
    Dim poslaniIznos As Decimal = Decimal.Parse(s.text)
    Dim iznos As Decimal
    Dim allTextboxesPayment() As TextBox = {gotovinaTbox, karticeTbox, ostaloTbox, ziralnoTbox}
       'gotovinaTbox, quita esto?
    For Each kontrola As TextBox In allTextboxesPayment
        iznos = iznos + Decimal.Parse(kontrola.Text)
    Next
    If CDbl(iznos) > ukupniIznos Then
        s.Text = 0
        iznos = 0
        For Each kontrola As TextBox In allTextboxesPayment
            iznos = iznos + Decimal.Parse(kontrola.Text)
        Next
    End If
    gotovinaTbox.Text = Format(ukupniIznos - CDbl(iznos), "#,##0.00")
End Sub