module_commonprocdure.bas

来自「不错的药房管理系统」· BAS 代码 · 共 40 行

BAS
40
字号
Attribute VB_Name = "Module_CommonProcdure"
Option Explicit

Public Enum InputType
    OnlyInteger = 0
    OnlySingle = 1
    OnlyLetter = 2
End Enum

'限制输入类型
Public Function InputControl(txtBox As Control, KeyCode As Integer, InputTypeIndex As InputType, Optional MaxLength As Integer = 10) As Boolean
    If Len(txtBox) >= MaxLength And KeyCode <> vbKeyBack And KeyCode <> vbKeyReturn Then
        KeyCode = 0
        Exit Function
    End If
    
    Select Case InputTypeIndex
        Case OnlyInteger
            If KeyCode >= 48 And KeyCode <= 57 Or KeyCode = vbKeyBack Or KeyCode = vbKeyReturn Then
                
            Else
                KeyCode = 0
            End If
         Case OnlySingle
            If KeyCode >= 48 And KeyCode <= 57 Or KeyCode = vbKeyBack Or KeyCode = 46 Or KeyCode = vbKeyReturn Then
                
            Else
                KeyCode = 0
            End If
    End Select
End Function

'使文本框得到焦点并全选其中内容
Public Sub SelectTextBoxAll(txtBox As TextBox)
    txtBox.SetFocus
    txtBox.SelStart = 0
    txtBox.SelLength = Len(txtBox)
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?