⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 采用VB6编制的小小程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmmain 
   Caption         =   "数字转换"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command2 
      Caption         =   "退出"
      Height          =   495
      Left            =   2760
      TabIndex        =   3
      Top             =   2400
      Width           =   975
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1560
      TabIndex        =   1
      Top             =   480
      Width           =   2415
   End
   Begin VB.CommandButton Command1 
      Caption         =   "显示结果"
      Height          =   495
      Left            =   840
      TabIndex        =   0
      Top             =   2400
      Width           =   975
   End
   Begin VB.Label Label2 
      Height          =   975
      Left            =   360
      TabIndex        =   4
      Top             =   1200
      Width           =   3615
   End
   Begin VB.Label Label1 
      Caption         =   "请输入数字"
      Height          =   375
      Left            =   360
      TabIndex        =   2
      Top             =   600
      Width           =   1095
   End
End
Attribute VB_Name = "frmmain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const Divvy = " "   '是否分开显示


Public Function Number_To_Chinese(ByVal Number As Double) As String
Dim Number_string As String
Dim Dot_pos As Integer
Dim Result_string As String
Dim Is_Zero As Boolean
Dim This_Class_NoNumber As Boolean
Dim Dig_string As String
Dim Integer_Len As Integer, Decimal_Len As Integer
Dim Class_val As Integer


Digit = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "点")
Digit_Format = Array("", "拾", "佰", "仟")
Class = Array("", "万", "亿", "兆")

Is_Zero = False

Number_string = CStr(Number)
Dot_pos = InStr(Number_string, ".")
If Dot_pos = 0 Then
    ' 该数为整数
    Integer_Len = Len(Number_string)
    If Integer_Len Mod 4 = 0 Then
        Class_val = Int(Integer_Len / 4) - 1
    Else
        Class_val = Int(Integer_Len / 4)
    End If
    
    
    For i = 1 To Integer_Len
        
        If (Integer_Len - i - Class_val * 4) = -1 Then
            If This_Class_NoNumber = False Then
                Result_string = Result_string & Class(Class_val) & Divvy
            End If
            Class_val = Class_val - 1
            Is_Zero = False
            This_Class_NoNumber = True
        End If
        Dig_string = Mid(Number_string, i, 1)
        If CInt(Dig_string) = 0 Then

            Is_Zero = True
        Else
            If Is_Zero = True Then
                Result_string = Result_string & Digit(0) & Divvy
            End If
            
            Result_string = Result_string & Digit(Dig_string) & Divvy
            If (Integer_Len - i) Mod 4 <> 0 Then
                Result_string = Result_string & Digit_Format(((Integer_Len - i) Mod 4)) & Divvy
            End If
            Is_Zero = False
            This_Class_NoNumber = False
        End If
        
    Next
Else
    ' 该处为整数部分
    Integer_Len = Dot_pos - 1
    If Integer_Len Mod 4 = 0 Then
        Class_val = Int(Integer_Len / 4) - 1
    Else
        Class_val = Int(Integer_Len / 4)
    End If
    
    
    For i = 1 To Integer_Len
        
        If (Integer_Len - i - Class_val * 4) = -1 Then
            If This_Class_NoNumber = False Then
                Result_string = Result_string & Class(Class_val) & Divvy
            End If
            Class_val = Class_val - 1
            Is_Zero = False
            This_Class_NoNumber = True
        End If
        Dig_string = Mid(Number_string, i, 1)
        If CInt(Dig_string) = 0 Then
            Is_Zero = True
        Else
            If Is_Zero = True Then
                Result_string = Result_string & Digit(0) & Divvy
            End If
            
            Result_string = Result_string & Digit(Dig_string) & Divvy
            If (Integer_Len - i) Mod 4 <> 0 Then
                Result_string = Result_string & Digit_Format(((Integer_Len - i) Mod 4)) & Divvy
            End If
            Is_Zero = False
            This_Class_NoNumber = False
        End If
        
    Next
    
    If Integer_Len = 0 Then   '纯小数
        Result_string = Result_string & Digit(0) & Divvy
    End If

    
    Result_string = Result_string & Digit(10) & Divvy
    ' 该处为小数部分
    For i = Dot_pos + 1 To Len(Number_string)
        Result_string = Result_string & Digit(Mid(Number_string, i, 1)) & Divvy
    Next
    
End If
Number_To_Chinese = Result_string
End Function

Private Sub Command1_Click()
On Error GoTo NotNumber
    Label2.Caption = (Number_To_Chinese(CDbl(Text1.Text)))
    Exit Sub
NotNumber:
    Label2.Caption = "请输入数字"
    
End Sub

Private Sub Command2_Click()
    frmabout.Show
    Unload frmmain
End Sub

⌨️ 快捷键说明

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