ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

TextBox¦p¦ó³]©w¥u¯à¬O¾ã¼Æ?

¦^´_ 1# acdx
Enter¡BExit ¨Æ¥ó
Enter ¥D­nµo¥Í¦b¤@­Ó±±¨î¶µ¡A±q¦P¤@ªí³æ¤Wªº¥t¤@­Ó±±¨î¶µ¨ú±o¾nÂI¤§«e¡FExit ·|¦b¤@­Ó±±¨î¶µ¥¢¥h¾nÂI®Éµo¥Í¡C
  1. Option Explicit
  2. Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  3.     If IsNumeric(TextBox1) Then
  4.         TextBox1 = Abs(Int(TextBox1))
  5.     Else
  6.         TextBox1 = ""
  7.     End If
  8. End Sub
½Æ»s¥N½X

TOP

¦^´_ 5# acdx
  1. Option Explicit
  2. Dim Msg As Boolean          '¹w³]­È: False
  3. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  4.     Msg = True      'ªí³æÃö³¬:ÅܼƳ]©w
  5. End Sub
  6. Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) 'ªí³æÃö³¬«áÁÙ·|°õ¦æ¦¹µ{¦¡
  7.      If Msg = False Then If TextÀˬd(TextBox1) Then Cancel = True
  8.      'Cancel: False ªí¥Ü±±¨î¶µ¤£³B²z¨Æ¥ó¡]¹w³]¡^¡FTrue ªí¥ÜÀ³¥Îµ{¦¡¶·³B²z¦¹¨Æ¥ó¡A¥B¾nÂI¤´«O¯d¦b¥Ø«e±±¨î¶µ¡C
  9. End Sub
  10. Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  11.     If Msg = False Then If TextÀˬd(TextBox2) Then Cancel = True
  12. End Sub
  13. '¦pÁÙ¦³TextBox ¨Ì¼Ëµe¸¬Äª
  14. 'Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  15. '   If Msg = False Then If TextÀˬd(TextBox3) Then Cancel = True
  16. 'End Sub
  17. Private Function TextÀˬd(Box As MSForms.TextBox) As Boolean
  18.     Dim S As Integer
  19.     If Abs((Int(Val(Box))) <> Box Or Box < 0) Then
  20.         S = InStr(Box, ".")
  21.         Box.SelStart = IIf(Mid(Box, 1, 1) = "-", 0, S - IIf(S > 0, 1, 0))
  22.         Box.SelLength = IIf(Mid(Box, 1, 1) = "-", 1, Len(Box) - S + 1)
  23.         MsgBox "»Ý¿é¤J¥¿¾ã¼Æ"
  24.         TextÀˬd = True
  25.     End If
  26. End Function
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ÀR§¤±`®¦¤v¹L¡B¶¢½Í²ö½×¤H«D¡C
ªð¦^¦Cªí ¤W¤@¥DÃD