我正在尝试计算7个文本框,如果它们被填充我将为每个值乘以10.50的值,但我无法进行此验证...我在下面编写了代码但是它没有使用
错误91
Sub btnCal_Click()
Dim cont As Integer
Dim ctrl As Control
cont = 1
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If Not IsNull(ctrl.Value) And Left(ctrl.Name, 6) = "txtDp" & cont Then
cont = cont + 1
End If
End If
Next ctrl
txtEx.Value = ctrl * 10.5
End Sub
答案 0 :(得分:0)
如果我了解您的要求,您需要添加文本框中包含的值,然后乘以10.5。如果这是正确的,请尝试以下代码:
Private Sub btnCal_Click()
Dim cont As Integer
Dim ctrl As Control
cont = 0
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If Val(ctrl.Text) <> 0 And Left(ctrl.Name, 5) = "txtDp" Then
cont = cont + Val(ctrl.Text)
End If
End If
Next ctrl
txtEx.Text = cont * 10.5
End Sub