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

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

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

§Ú³]­p¤@­Óªí³æ ¨ä¤¤TextBox§@¬°¿é¤J¤¶­± ¥Ñ©ó¸Ó°Ñ¼Æ¥²¶·¬°¥¿¾ã¼Æ¸Ó¦p¦ó­­¨îTextBox¤§®æ¦¡
§Ú§Æ±æ¼g¦¨·í¿é¤J¬°¥¿¾ã¼Æ¥H¥~¦r¤¸«hÅã¥Ü"¥²¶·¬°¥¿¾ã¼Æ"
ÁÂÁÂ

¦^´_ 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

¸Ó¼gªkÁöµM¥i¥H¸Ñ¨M«D¾ã¼Æªº°ÝÃD ¦ý¦pªG¹J¨ì¨Ï¥ÎªÌ¿é¤J¼Æ¦r¥H¥~¦r¤¸¨Ò¦p"h","¦n"
¸Ó¦p¦óÅýµ{¦¡¦Û°Ê§P§O³o¨Ç«D¼Æ¦r¦r¤¸¤Î¦Û°Ê¸õ¥X¦Ó¤£­Pµo¥Íµ{¦¡¿ù»~?

TOP

¦^´_ 3# acdx
TextBox1 = ""    ¤w¸gµ¹§Aµª®×¤F¡I

TOP

¦^´_ 4# c_c_lai
¤£¦n·N«ä §Ú¤W­±¥i¯à¨Sªí¹F²M·¡
²{¦b¹J¨ìªº°ÝÃD¬OTextBox©Ò¿é¤Jªº­È³Q»{©w¬°¤å¦r
°²³]§Ú¿é¤J5 «hTextBox="5"(¥ÑºÊ¬Ý¦¡¸Ì¬Ý¨ìªº­È) ¦ÓTextBox¦bµ{¦¡¤¤¥²¶·¬O¥¿¾ã¼Æ¤~¥i¥¿±`°õ¦æ §Ú§Æ±æ§Úªºµ{¦¡¯à°÷§P§O/´£¿ô¨Ï¥ÎªÌ¡A·íTextBox¿é¤J¬°­t¼Æ©Î¤p¼Æ®É«h·|¥X²{ĵ§iµøµ¡¦]¦¹§Ú¼g¦¨³o¼Ë: (·íTextBox1¿é¤J8,TextBox2¿é¤J12)
If IsNumeric(TextBox1) = False Or IsNumeric(TextBox2) = False Then
    MsgBox "½Ð¿é¤J¼Æ¦r"
    Exit Sub
        ElseIf TextBox1 <> Abs(Int(TextBox1)) Or TextBox2 <> Abs(Int(TextBox2)) Then
            MsgBox "½Ð¿é¤J¾ã¼Æ"
            Exit Sub
End If
ÂŦ⬰¨ä°õ¦æµ²ªG
¥ÑºÊ¬Ý¦¡¸Ì: TextBox1="8", Abs(Int(TextBox1)) =8, TextBox2 ="12", Abs(Int(TextBox2)) =12
¬G:TextBox1 ¤£µ¥©óAbs(Int(TextBox1)) ©Ò¥Hµ{¦¡¸õ¶}-->³o¸Ó¦p¦ó¸Ñ¨M?
¥t¥~µ{¦¡¤¤¥²¶·TextBox1<TextBox2©Ò¥H§ÚÁÙ¼g¤F±ø¥ó¦¡½T«O³oÃö«Y¦¨¥ß¦ý«o³Q§PÂ_¬° "8">"12"-->©Ò¥Hµ{¦¡¤S¸õ¶}  ³o¨Ç°ÝÃD§xÂZ§Ú¦n´X¤Ñ¤F

TOP

¦^´_ 5# acdx
  1. Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  2. If CStr(Val(TextBox1)) <> TextBox1 Or Val(TextBox1) < 0 Then MsgBox "¥²¶·¬°¥¿¾ã¼Æ": Exit Sub
  3. MsgBox TextBox1
  4. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 5# acdx
  1. Sub Test()
  2.     '  °²³] [B1] Äæ¦ìÄݩʬ°¤å¦r¡F¿é¤J­È: 10¡B©Î¬O 10ABC
  3.     '  «h¦¹®É [B1] ¬° Not IsNumeric([B1])
  4.     If IsNumeric([B1]) Then
  5.         [B3] = Abs(Int([B1]))
  6.     Else
  7.         If Val([A1]) > 0 Then
  8.             [B3] = Abs(Int(Val([B1])))     ' ¨ú±o¼Æ­È 10
  9.         Else
  10.             [B3] = ""         ' ¸ÓÄæ¦ì­È¬°«D¼Æ­È¤§¤å¦r¦ê
  11.             MsgBox "½Ð¿é¤J¼Æ¦r"
  12.         End If
  13.     End If
  14. End Sub
½Æ»s¥N½X
¦p¦¹Á|¨Ò¡A¤F¸Ñ§_¡H

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

¸Ñ¨M¤F
ÁÂÁ¤j®aªºÀ°¦£

TOP

        ÀR«ä¦Û¦b : Ä@­n¤j¡B§Ó­n°í¡B®ð­n¬X¡B¤ß­n²Ó¡C
ªð¦^¦Cªí ¤W¤@¥DÃD