zoukankan      html  css  js  c++  java
  • 让TextBox只输入金额或数字的方法

    Private Sub Form_Load (   )  
          Text1.Tag   =   0
          Text1_LostFocus
    End Sub

    Private Sub Text1_GotFocus (   )  
          Text1.Text   =   Text1.Tag
          Text1.SelStart   =   0
          Text1.SelLength   =   Len ( Text1.Text )  
    End Sub

    Private Sub Text1_KeyPress ( KeyAscii As Integer )  
          If KeyAscii > =   Asc ( "0" )   And KeyAscii < =   Asc ( "9" )   Or KeyAscii   =   8 Or KeyAscii   =   Asc ( "." )   Then
                If KeyAscii   =   Asc ( "." )   And InStr ( 1, Text1.Text, ".", vbTextCompare )   > 0 Then
                      KeyAscii   =   0
                End If
                If Text1.SelStart > =   Len ( Text1.Text )   - 2 And _
                      InStr ( 1, Text1.Text, ".", vbTextCompare )   > 0 And _
                      Len ( Text1.Text )   - InstrRev ( Text1.Text, "."Len ( Text1.Text ) , vbTextCompare )   > =   2 And _
                      KeyAscii <> 8 Then
                       
                      KeyAscii   =   0
                End If
          Else
                KeyAscii   =   0
          End If
    End Sub

    Private Sub Text1_LostFocus (   )  
          Dim SaveNumer As Currency
          If IsNumeric ( Text1.Text )     =   False Then
                SaveNumer   =   0
          Else
                SaveNumer   =   Format ( Text1.Text, "0.00" )  
          End If
          Text1.Tag   =   SaveNumer
          Text1.Text   =   Format ( SaveNumer, "¥0.00" )  
    End Sub

  • 相关阅读:
    leetcode 279. Perfect Squares
    leetcode 546. Remove Boxes
    leetcode 312. Burst Balloons
    leetcode 160. Intersection of Two Linked Lists
    leetcode 55. Jump Game
    剑指offer 滑动窗口的最大值
    剑指offer 剪绳子
    剑指offer 字符流中第一个不重复的字符
    leetcode 673. Number of Longest Increasing Subsequence
    leetcode 75. Sort Colors (荷兰三色旗问题)
  • 原文地址:https://www.cnblogs.com/rosesmall/p/14445195.html
Copyright © 2011-2022 走看看