Bryco 发表于 2007-5-7 17:09:55

我重新审视了我正在做的事情 首先,我将所有验证代码移出了按钮点击事件,从而解决了这个问题 其次,我缩小了它循环的范围 这是因为我取消了活动,没有#039;当我返回表单时,t退出click事件,因此事件在他们更新信息问题后再次运行。

Bryco 发表于 2007-5-7 21:33:53

好东西Matt CmdrDuh-如果你的代码不在点击事件中,你如何退出它?

Bryco 发表于 2007-5-8 12:15:54

使用Matt's的建议,我用了这个Private Sub txtLengthFt_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
      Select Case KeyAscii
            Case Asc("0") To Asc("9")
            Case Else
                  KeyAscii = 0
      End Select
End Sub 这个Private Sub txtLengthIn_Change()
      If txtLengthIn.Value >= 12 Then
            MsgBox "Whoa the Pony, Nothing greater than 12", vbCritical + vbOKOnly
            txtLengthIn.Text = "0"
            txtLengthIn.SelStart = 0
            txtLengthIn.SelLength = txtLengthIn.TextLength
      End If
End Sub 检查数值 填写完所有txtbox并基于以上两个检查有效后,将启用click事件。(有2个以上的检查,我只是粘贴了其中的2个来显示我在做什么。所有6个框都有相同类型的错误验证)

Bryco 发表于 2007-5-8 13:16:41

这里是#039;如果输入的值大于12,它将提示您将英寸转换为英尺
Private Sub txtLengthIn_Change()
    Dim vbResult As Long
    If txtLengthIn.Value >= 12 Then
      vbResult = MsgBox("Since you're attempting to enter a value GREATER than 12, would you like to convert it to FEET?", vbQuestion + vbYesNo, "Way to go!")
      If vbResult = vbYes Then
            MsgBox "Converted value = " & txtLengthIn / 12
      ElseIf vbResult = vbNo Then
            MsgBox "Start over!"
            txtLengthIn.Text = "0"
            txtLengthIn.SelStart = 0
            txtLengthIn.SelLength = txtLengthIn.TextLength
      End If
    End If
End Sub 这将允许您在数字中添加句点(如果您不使用整英寸)
Private Sub txtLengthIn_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   If InStr(1, txtLengthIn.Text, ".") > 0 And KeyAscii = Asc(".") Then
      KeyAscii = 0
      Exit Sub
    End If
    Select Case KeyAscii
      Case Asc("0") To Asc("9"), Asc(".")
      Case Else
            KeyAscii = 0
    End Select
End Sub 这只是你可能想考虑的其他事情。

Bryco 发表于 2007-5-9 10:21:55

好主意 我必须看看我是否能利用这些 我喜欢添加周期选项,因为我们的土木工程师总是使用###' 总体安排
页: 1 [2]
查看完整版本: 有没有更好的方法来评估TextBox值