0
A
回答
0
假設你的文本框的一個名爲TextBox1
您可以將此代碼放在您的用戶窗體:
Option Explicit
Dim blnClosing As Boolean
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If blnClosing = False Then
Dim iVal As Integer
Dim minVal As Integer
minVal = 10 'Change to your needs
'Test for numeric characters
On Error Resume Next
iVal = CInt(Me.TextBox1.Value)
'If characters are not numeric
If Err.Number = 13 Then
MsgBox "Value must be numeric!", vbCritical, "Incorrect Value"
Me.TextBox1.Text = vbNullString
Cancel = True 'Retain focus on the textbox
Exit Sub
End If
'Reset error handling to normal
On Error GoTo 0
'Check if textbox value is less than the minimum
If Me.TextBox1.Value < minVal Then
MsgBox "Value must be greater than " & minVal & "", vbCritical, "Incorrect Value"
Me.TextBox1.Value = vbNullString
Cancel = True 'Retain focus on the textbox
End If
End If
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
blnClosing = True
End Sub
我把一個數值檢查以及的自由,因爲你問的是文本框中的值是否必須是數字。如果不是這種情況,請將'Test for numeric characters
註釋中的代碼行刪除至On ErrorGoTo 0
行。
全局變量blnClosing
允許我們在表單關閉時跳過代碼。如果沒有包含這些信息,並且用戶在窗體的右上角按下了「X」,並顯示無效數據(空白,小於最小值或非數字),則會顯示消息框。
相關問題
- 1. 將評分值設置爲文本框
- 2. 將值設置爲「」後調整文本框的大小
- 3. 劍道UI數值文本框設置最小值
- 4. 將最小值設置爲減法(AngularJS)
- 5. gtk_window_set_resizable將窗口設置爲最小值
- 6. 如何設置最大整數值爲文本框的值
- 7. 將文本框設置爲文件名
- 8. 將軸的最小值和最大值設置爲棒圖
- 9. 爲文本框設置綁定空值
- 10. 將php會話值設置爲文本框的值
- 11. 文本框未設置值
- 12. 將文本框設置爲必填
- 13. 將焦點設置爲文本框
- 14. Asp.net將文本框1設置爲等於文本框2
- 15. 將文本框文本從設置返回到最後一個好值
- 16. 將ng-model值設置爲div文本
- 17. 如何在AmChart的y軸上將最大值設置爲1並將最小值設置爲0?
- 18. 將Y軸最小值設置爲負值不起作用
- 19. 寫入Cookie並將Cookie值設置爲文本框選擇Vlaue
- 20. 我們如何將文本框的值設置爲dropdownlist?
- 21. 將預定義值設置爲另一個文本框
- 22. 如何將文本框的值設置爲隱藏字段
- 23. 將WPf Datagrid Combobox值設置爲各自的文本框
- 24. 如何將查詢中的值設置爲輸入文本框
- 25. 如何將datetimepicker設置爲綁定到的文本框的值
- 26. 如何將蒙面文本框值設置爲十進制數?
- 27. 將ASP.NET密碼文本框值自動設置爲「密碼」
- 28. 將文本框的默認值設置爲查詢結果
- 29. 如何將文本框值設置爲其綁定源在c#
- 30. jquery將正確的usercontrol文本框值設置爲0
看看TextBox1_KeyDown或Keypress事件。在這種情況下,您可以檢查另一個文本框的值,如果尚未設置,則保釋。 – MatthewD