?? form1.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 + -