| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 962 人关注过本帖
标题:求助纠错小程序,求各位大侠们的帮助
只看楼主 加入收藏
winorange
Rank: 1
来 自:浙江宁波
等 级:新手上路
威 望:1
帖 子:136
专家分:0
注 册:2008-3-29
收藏
 问题点数:0 回复次数:6 
求助纠错小程序,求各位大侠们的帮助
本来刚学没多久,想做个从数字转化为中文大写的小程序,可是当我输入“1”时,结果为 “壹拾壹” “2”时,结果为“贰拾贰”“123”时结果为 “壹仟壹佰贰拾”叁 。
Dim f, l, i As Integer
        Dim y As String
        Dim b As String
        Dim t As String
        f = Val(TextBox3.Text) ’先将输入框转成数字,以便将字符去除
        b = Str(f)  ’再将数字转为文
        l = Len(b)  ’求输入文本的长度
        For i = 1 To l ’对输入文本的最后一位开始,一位一位的转为中文大写的中文字符
            Select Case Mid$(b, l - i + 1, 1)
                Case 0
                    y = "零"
                Case 1
                    y = "壹"
                Case 2
                    y = "贰"
                Case 3
                    y = "叁"
                Case 4
                    y = "肆"
                Case 5
                    y = "伍"
                Case 6
                    y = "陆"
                Case 7
                    y = "柒"
                Case 8
                    y = "捌"
                Case 9
                    y = "玖"
                Case 10
                    y = "拾"
            End Select
            t = t & y ’将转换后的中文字符以原字符的最后一位为开始,一个一个相接,若输入时为“123”,则t为“叁贰壹”

        Next i

        Select Case Len(t) ‘对不同的输入长度作不同的输出判断
            Case 1
                TextBox4.Text = t
            Case 2
                TextBox4.Text = Mid$(t, 2, 1) & "拾" & Mid$(t, 1, 1)
            Case 3
                TextBox4.Text = Mid$(t, 3, 1) & "佰" & Mid$(t, 2, 1) & "拾" & Mid$(t, 1, 1)
            Case 4
                TextBox4.Text = Mid$(t, 4, 1) & "仟" & Mid$(t, 3, 1) & "佰" & Mid$(t, 2, 1) & "拾" & Mid$(t, 1, 1)
            Case 5
                TextBox4.Text = Mid$(t, 5, 1) & "万" & Mid$(t, 4, 1) & "仟" & Mid$(t, 3, 1) & "佰" & Mid$(t, 2, 1) & "拾" & Mid$(t, 1, 1)
            Case 6
                TextBox4.Text = Mid$(t, 6, 1) & "拾" & Mid$(t, 5, 1) & "万" & Mid$(t, 4, 1) & "仟" & Mid$(t, 3, 1) & "佰" & Mid$(t, 2, 1) & "拾" & Mid$(t, 1, 1)
            Case 7
                TextBox4.Text = Mid$(t, 7, 1) & "佰" & Mid$(t, 6, 1) & "拾" & Mid$(t, 5, 1) & "万" & Mid$(t, 4, 1) & "仟" & Mid$(t, 3, 1) & "佰" & Mid$(t, 2, 1) & "拾" & Mid$(t, 1, 1)
            Case 8
                TextBox4.Text = Mid$(t, 8, 1) & "仟" & Mid$(t, 7, 1) & "佰" & Mid$(t, 6, 1) & "拾" & Mid$(t, 5, 1) & "万" & Mid$(t, 4, 1) & "仟" & Mid$(t, 3, 1) & "佰" & Mid$(t, 2, 1) & "拾" & Mid$(t, 1, 1)
            Case 9
                TextBox4.Text = Mid$(t, 9, 1) & "亿" & Mid$(t, 8, 1) & "仟" & Mid$(t, 7, 1) & "佰" & Mid$(t, 6, 1) & "拾" & Mid$(t, 5, 1) & "万" & Mid$(t, 4, 1) & "仟" & Mid$(t, 3, 1) & "佰" & Mid$(t, 2, 1) & "拾" & Mid$(t, 1, 1)
        End Select
    End Sub
搜索更多相关主题的帖子: 纠错 
2008-05-05 20:35
winorange
Rank: 1
来 自:浙江宁波
等 级:新手上路
威 望:1
帖 子:136
专家分:0
注 册:2008-3-29
收藏
得分:0 
根据结果,我将后面的一个select的 每一个case结果的第一个mid及其参数去除后,又能显示正确的结果了,但我还是不知道是怎么回事。

处处尽力尽快,一切顺其自然。
2008-05-05 20:45
winorange
Rank: 1
来 自:浙江宁波
等 级:新手上路
威 望:1
帖 子:136
专家分:0
注 册:2008-3-29
收藏
得分:0 
是不是起始位置的后面一位开始取,而不是从起始位置开始取。那样的话,就说的过去了。

处处尽力尽快,一切顺其自然。
2008-05-05 20:48
winorange
Rank: 1
来 自:浙江宁波
等 级:新手上路
威 望:1
帖 子:136
专家分:0
注 册:2008-3-29
收藏
得分:0 
最后一位为时,如何让最后一位不显示出零,不然不合常规,比如“10”的时候,他会显示“壹拾零”

处处尽力尽快,一切顺其自然。
2008-05-05 21:02
fairy4
Rank: 4
等 级:贵宾
威 望:10
帖 子:738
专家分:267
注 册:2007-11-1
收藏
得分:0 
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim strTemp01, intStr, NumStr, TrunStr As String
        Dim strLen As Integer
        Dim ZeroFlag As Boolean = False
        dim ZeroTooFlag as Boolean=False
        strTemp01 = Me.TextBox3.Text.Trim()
        strLen = strTemp01.Length
        For intX As Integer = 1 To strLen
            Select Case Mid(strTemp01, intX, 1)
                Case 0
                    intStr = "零"
                Case 1
                    intStr = "壹"
                Case 2
                    intStr = "贰"
                Case 3
                    intStr = "叁"
                Case 4
                    intStr = "肆"
                Case 5
                    intStr = "伍"
                Case 6
                    intStr = "陆"
                Case 7
                    intStr = "柒"
                Case 8
                    intStr = "捌"
                Case 9
                    intStr = "玖"
                    'Case 10
                    '    y = "拾"
            End Select
            NumStr = NumStr & intStr
        Next
        For intI As Integer = 1 To NumStr.Length
            If Mid(NumStr, intI, 1) <> "零" Then
                ZeroFlag = False
                TrunStr = TrunStr & Mid(NumStr, intI, 1) & FindDanwei(NumStr.Length - intI)
            Else
                If ZeroFlag = False Then

                    If NumStr.Length - intI = 4 Or NumStr.Length - intI = 8 Then
                        If intI <> NumStr.Length Then
                            TrunStr = TrunStr & FindDanwei(NumStr.Length - intI)
                        End If
                    Else
                        If intI <> NumStr.Length Then
                            TrunStr = TrunStr & Mid(NumStr, intI, 1)
                        End If
                    End If
                Else
                    If NumStr.Length - intI = 4 Or NumStr.Length - intI = 8 Then
                        If intI <> NumStr.Length Then
                            TrunStr = TrunStr & FindDanwei(NumStr.Length - intI)
                        End If
                    Else
                        If intI <> NumStr.Length Then
                            TrunStr = TrunStr
                        End If
                    End If
                End If
                ZeroFlag = True

            End If
        Next
        If TrunStr.Substring(TrunStr.Length - 1, 1) = "零" Then
            TrunStr = TrunStr.Substring(0, TrunStr.Length - 1)
        End If
        Me.TextBox4.Text = TrunStr
    End Sub
    Private Function FindDanwei(ByVal intX As Int32) As String
        Select Case intX
            Case 1
                Return "拾"
            Case 2
                Return "佰"
            Case 3
                Return "仟"
            Case 4
                Return "万"
            Case 5
                Return "拾"
            Case 6
                Return "佰"
            Case 7
                Return "仟"
            Case 8
                Return "亿"
            Case 9
                Return "拾"
            Case 10
                Return "佰"
            Case 11
                Return "仟"

        End Select
    End Function
你看看這個吧

一个人只有一个心脏,却有两个心房。一个住着快乐;一个住着悲伤。不要笑得太大声,不然会吵醒旁边的悲伤
2008-05-06 13:27
fairy4
Rank: 4
等 级:贵宾
威 望:10
帖 子:738
专家分:267
注 册:2007-11-1
收藏
得分:0 
當然,這個程序也有一些小問題,比如1000001這樣的數字,處理出來的結果就不是我想要的看到的,
我也沒時間去改了,呵呵

一个人只有一个心脏,却有两个心房。一个住着快乐;一个住着悲伤。不要笑得太大声,不然会吵醒旁边的悲伤
2008-05-06 13:29
winorange
Rank: 1
来 自:浙江宁波
等 级:新手上路
威 望:1
帖 子:136
专家分:0
注 册:2008-3-29
收藏
得分:0 
谢谢兄弟。

处处尽力尽快,一切顺其自然。
2008-05-06 14:44
快速回复:求助纠错小程序,求各位大侠们的帮助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019170 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved