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

📄 form1.vb

📁 Visual.Basic.NET实用编程百例-47.6M.zip
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(64, 16)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(150, 21)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = ""
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(64, 56)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(150, 21)
        Me.TextBox2.TabIndex = 1
        Me.TextBox2.Text = ""
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(88, 96)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(100, 30)
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "转换"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(40, 23)
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "金额"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(56, 23)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "大写金额"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(256, 141)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Name = "Form1"
        Me.Text = "金额大写转换"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox2.Text = ChMoney(Val(TextBox1.Text))
    End Sub

    Private Function CCh(ByVal N1) As String   '得到一位数字 N1 的汉字大写,0 返回 ""
        Select Case N1
            Case 0
                CCh = "零"
            Case 1
                CCh = "壹"
            Case 2
                CCh = "贰"
            Case 3
                CCh = "叁"
            Case 4
                CCh = "肆"
            Case 5
                CCh = "伍"
            Case 6
                CCh = "陆"
            Case 7
                CCh = "柒"
            Case 8
                CCh = "捌"
            Case 9
                CCh = "玖"
        End Select
    End Function

    Public Function ChMoney(ByVal N1) As String  '得到数字 N1 的汉字大写,最大为千万位,O 返回 ""
        Dim tMoney As String
        Dim lMoney As String
        Dim tn '小数位置
        Dim s1 As String '临时STRING 小数部分
        Dim s2 As String '1000 以内
        Dim s3 As String '10000
        Dim ST1, t1 As String
        If N1 = 0 Then
            ChMoney = " "
            Exit Function
        End If
        If N1 < 0 Then
            ChMoney = "负" + ChMoney(Math.Abs(N1))
            Exit Function
        End If
        tMoney = Trim(Str(N1))
        tn = InStr(tMoney, ".")  '小数位置
        s1 = ""
        If tn <> 0 Then
            ST1 = Microsoft.VisualBasic.Right(tMoney, Len(tMoney) - tn)
            If ST1 <> "" Then
                t1 = Microsoft.VisualBasic.Left(ST1, 1)
                ST1 = Microsoft.VisualBasic.Right(ST1, Len(ST1) - 1)
                If t1 <> "0" Then
                    s1 = s1 + CCh(Val(t1)) + "角"
                End If
                If ST1 <> "" Then
                    t1 = Microsoft.VisualBasic.Left(ST1, 1)
                    s1 = s1 + CCh(Val(t1)) + "分"
                End If
            End If
            ST1 = Microsoft.VisualBasic.Left(tMoney, tn - 1)
        Else
            ST1 = tMoney
        End If
        s2 = ""
        If ST1 <> "" Then
            t1 = Microsoft.VisualBasic.Right(ST1, 1)
            ST1 = Microsoft.VisualBasic.Left(ST1, Len(ST1) - 1)
            s2 = CCh(Val(t1)) + s2
        End If
        If ST1 <> "" Then
            t1 = Microsoft.VisualBasic.Right(ST1, 1)
            ST1 = Microsoft.VisualBasic.Left(ST1, Len(ST1) - 1)
            If t1 <> "0" Then
                s2 = CCh(Val(t1)) + "拾" + s2
            Else
                If Microsoft.VisualBasic.Left(s2, 1) <> "零" Then s2 = "零" + s2
            End If
        End If
        If ST1 <> "" Then
            t1 = Microsoft.VisualBasic.Right(ST1, 1)
            ST1 = Microsoft.VisualBasic.Left(ST1, Len(ST1) - 1)
            If t1 <> "0" Then
                s2 = CCh(Val(t1)) + "佰" + s2
            Else
                If Microsoft.VisualBasic.Left(s2, 1) <> "零" Then s2 = "零" + s2
            End If
        End If
        If ST1 <> "" Then
            t1 = Microsoft.VisualBasic.Right(ST1, 1)
            ST1 = Microsoft.VisualBasic.Left(ST1, Len(ST1) - 1)
            If t1 <> "0" Then
                s2 = CCh(Val(t1)) + "仟" + s2
            Else
                If Microsoft.VisualBasic.Left(s2, 1) <> "零" Then s2 = "零" + s2
            End If
        End If
        s3 = ""
        If ST1 <> "" Then
            t1 = Microsoft.VisualBasic.Right(ST1, 1)
            ST1 = Microsoft.VisualBasic.Left(ST1, Len(ST1) - 1)
            s3 = CCh(Val(t1)) + s3
        End If
        If ST1 <> "" Then
            t1 = Microsoft.VisualBasic.Right(ST1, 1)
            ST1 = Microsoft.VisualBasic.Left(ST1, Len(ST1) - 1)
            If t1 <> "0" Then
                s3 = CCh(Val(t1)) + "拾" + s3
            Else
                If Microsoft.VisualBasic.Left(s3, 1) <> "零" Then s3 = "零" + s3
            End If
        End If
        If ST1 <> "" Then
            t1 = Microsoft.VisualBasic.Right(ST1, 1)
            ST1 = Microsoft.VisualBasic.Left(ST1, Len(ST1) - 1)
            If t1 <> "0" Then
                s3 = CCh(Val(t1)) + "佰" + s3
            Else
                If Microsoft.VisualBasic.Left(s3, 1) <> "零" Then s3 = "零" + s3
            End If
        End If
        If ST1 <> "" Then
            t1 = Microsoft.VisualBasic.Right(ST1, 1)
            ST1 = Microsoft.VisualBasic.Left(ST1, Len(ST1) - 1)
            If t1 <> "0" Then
                s3 = CCh(Val(t1)) + "仟" + s3
            End If
        End If
        If Microsoft.VisualBasic.Right(s2, 1) = "零" Then s2 = Microsoft.VisualBasic.Left(s2, Len(s2) - 1)
        If Len(s3) > 0 Then
            If Microsoft.VisualBasic.Right(s3, 1) = "零" Then s3 = Microsoft.VisualBasic.Left(s3, Len(s3) - 1)
            s3 = s3 & "万"
        End If
        ChMoney = IIf(s3 & s2 = "", s1, s3 & s2 & "元" & s1)
    End Function

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

⌨️ 快捷键说明

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