| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 451 人关注过本帖
标题:求高手讲解下这段大小写转换的代码 帮忙写上注释通俗易懂点 我没齿难忘
只看楼主 加入收藏
a13582220882
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2013-9-20
结帖率:0
收藏
 问题点数:0 回复次数:2 
求高手讲解下这段大小写转换的代码 帮忙写上注释通俗易懂点 我没齿难忘
Private Sub Text2_Change()  '小写转大写
    Dim i As Integer
    Dim j As Integer
    Dim myint As Integer
    Dim myint1 As Integer
    Dim mydoub As Double
    Dim mystr As String
    Dim mystr1 As String
    Dim mystr2 As String
    Dim mystr3 As String
    Dim mystr4 As String
    Dim money As Long
    Dim money1 As Integer
    Dim money2 As Long
    mystr = Text2.Text
    myint = InStr(mystr, ".")
    If myint = 0 Then
        mystr = Text2.Text
    Else
        mystr3 = Right(Text2.Text, Len(Text2.Text) - myint)
        If mystr3 <> "" Then       '转换小数位
            mystr4 = Left(mystr3, 1)
            mystr3 = Right(mystr3, Len(mystr3) - 1)
            If mystr4 <> "0" Then
                mystr2 = mystr2 + setdata(Val(mystr4)) + "角"
            Else
                mystr2 = mystr2 + "零"
            End If
            If mystr3 <> "" Then
                mystr4 = Left(mystr3, 1)
                mystr2 = mystr2 + setdata(Val(mystr4)) + "分"
            End If
        End If
        mystr = Left(Text2.Text, myint - 1)
    End If
    j = Len(mystr)
    For i = 1 To Len(mystr)      '转换整数位
        money2 = Left(mystr, i)
        money1 = Right(money2, 1)
        If money1 = 0 Then
            If j = 5 Then
                If Right(mystr1, 1) = "零" Then mystr1 = Left(mystr1, Len(mystr1) - 1)
                If Right(mystr1, 1) <> "万" Then mystr1 = mystr1 & "万"
            Else
                If Right(mystr1, 1) <> "零" And Right(mystr, j) > 0 Then mystr1 = mystr1 & "零"
            End If
        Else
            mystr1 = mystr1 & setdata(money1) + chang(j)
        End If
        j = j - 1
    Next i
    Text1.Text = mystr1 & "元" & mystr2  '显示大写
End Sub
搜索更多相关主题的帖子: money 
2014-03-31 18:04
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:653
专家分:3402
注 册:2008-5-7
收藏
得分:0 
用这个函数吧,n年前写的
Function Je_daxie(a As Double) As String
  Dim c As String, d As Integer, i As Integer
  Dim e As String, g As String, h As String
  Je_daxie = ""
  If a <= 0 Then Exit Function
  g = "零壹贰叁肆伍陆柒捌玖"
  h = "圆拾佰仟万拾佰仟亿拾佰仟兆"
  c = Trim(Str(Int(a)))
  d = (a - Int(a)) * 100
  e = ""
  For i = 1 To Len(c)
    e = e & Mid(g, Val(Mid(c, i, 1)) + 1, 1) & Mid(h, Len(c) - i + 1, 1)
  Next
  c = Left(e, Len(e) - 1)
  While Right(c, 1) = "零"
    e = Left(e, Len(e) - 2)
    c = Left(e, Len(e) - 1)
  Wend
  If Right(e, 1) <> "圆" Then e = e & "圆"
  c = ""
  For i = 1 To Len(e)
    c = c + Mid(e, i, 1)
    If Mid(e, i, 1) = "零" Then i = i + 1
  Next
  e = c
  If d > 10 Then c = Trim(d)
  If d < 10 And d > 0 Then c = "0" & Trim(d)
  If d = 0 Then
    e = e & "整"
  Else
    e = e & Mid(g, Val(Mid(c, 1, 1)) + 1, 1) & "角" & Mid(g, Val(Mid(c, 2, 1)) + 1, 1) & "分"
  End If
  Je_daxie = e
End Function

调用方法和结果如下:
?Je_daxie(123456.78)
壹拾贰万叁仟肆佰伍拾陆圆柒角捌分
2014-03-31 20:16
chen3523
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:33
帖 子:223
专家分:1165
注 册:2013-2-12
收藏
得分:0 

    mystr = Text2.Text
    myint = InStr(mystr, ".") ‘从左边顺数到“.”有几位数(包括“.”)
    If myint = 0 Then
        mystr = Text2.Text
    Else
        mystr3 = Right(Text2.Text, Len(Text2.Text) - myint)  ’小数点后有几位数
        If mystr3 <> "" Then       '转换小数位 保证小数点后有数字
            mystr4 = Left(mystr3, 1) ‘小数点后第一位
            mystr3 = Right(mystr3, Len(mystr3) - 1) ‘小数点后第二位
            If mystr4 <> "0" Then  ‘转换小数点后第一位,如果不为0,则
                mystr2 = mystr2 + setdata(Val(mystr4)) + "角" ’setdata(Val(mystr4)) 数字转换为大写,setdata(m)是数组,你没有上传
            Else  ‘转换小数点后第一位,如果为0,则
                mystr2 = mystr2 + "零"
            End If
            If mystr3 <> "" Then   ‘转换小数点后第二位,如果不为0,则
                mystr4 = Left(mystr3, 1)
                mystr2 = mystr2 + setdata(Val(mystr4)) + "分"
            End If
        End If
        mystr = Left(Text2.Text, myint - 1)  ’小数点左边的数字(整数位)
    End If
    j = Len(mystr)  ‘整数位的长度
    For i = 1 To Len(mystr)      '转换整数位 这里Len(mystr)也只可以用j代替 从左边第一位读起,读到整数结束
        money2 = Left(mystr, i)  ’从左边第一位读起,依次向右增加一位数,读到整数结束
        money1 = Right(money2, 1) ‘保证每次只要最后一位数
       ’后面的不作注解,自己想啦

[ 本帖最后由 chen3523 于 2014-4-2 16:05 编辑 ]

调试失败3次后,关机睡觉,当醒来时多有收获。
2014-04-02 16:04
快速回复:求高手讲解下这段大小写转换的代码 帮忙写上注释通俗易懂点 我没齿难 ...
数据加载中...
 
   



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

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