设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 980|回复: 6
打印 上一主题 下一主题

[Access本身] 关于货币转化的问题

[复制链接]
跳转到指定楼层
1#
发表于 2003-8-29 01:02:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是我的一段货币转化的代码,我在调用时money这个变量用的string类型,在用一段时间后就出现问题,说类型不匹配,但我在开始用时是好的,我想是不是这里出了问题。这个问题在windows 98下一直存在,在我的windows2000下好像没有问题。
Public Function MoneyConv(Money As Currency) As String
On Error GoTo Doerr

Dim CN(9) As String
Dim CU(15) As String
Dim Temp As String, strNum As String
Dim CM As String
Dim tFirst As String, tEnd As String
Dim i As Long, j As Long, k As Long
CN(0) = "零"
CN(1) = "壹"
CN(2) = "贰"
CN(3) = "叁"
CN(4) = "肆"
CN(5) = "伍"
CN(6) = "陆"
CN(7) = "柒"
CN(8) = "捌"
CN(9) = "玖"

' CU(0) = "分"
' CU(1) = "角"
CU(0) = "圆"
CU(1) = "拾"
CU(2) = "佰"
CU(3) = "仟"
CU(4) = "万"
CU(5) = "拾"
CU(6) = "佰"
CU(7) = "仟"
CU(8) = "亿"
CU(9) = "拾"
CU(10) = "佰"
CU(11) = "仟"

If Money = 0 Then
CM = "零圆整"
GoTo Complete
End If
strNum = Trim(Str(FormatCurrency(Money, 2, vbTrue, vbFalse, vbFalse)))
If left(strNum, 1) = "-" Then
tFirst = "负"
strNum = right(strNum, Len(strNum) - 1)
Else
tFirst = ""
End If

i = InStrRev(strNum, ".")
If i <> 0 Then
Temp = right(strNum, i)
If Len(strNum) - i = 1 Then Temp = Temp + "0"
CM = CN(CInt(left(right(Temp, 2), 1))) + "角" + CN(CInt(right(Temp, 1))) + "分"
tEnd = ""
strNum = left(strNum, i - 1)
Else
tEnd = "整"
End If

i = 0
For j = Len(strNum) To 1 Step -1
k = CInt(right(left(strNum, j), 1))
If k = 0 Then
If i <> 0 And i <> 4 And i <> 8 Then
CM = CN(k) + CM
Else
CM = CN(k) + CU(i) + CM
End If
Else
CM = CN(k) + CU(i) + CM
End If
' CM = CN(k) + CU(i) + CM
i = i + 1
Next j

CM = tFirst + CM + tEnd
CM = Replace(CM, "零零", "零")
CM = Replace(CM, "零零", "零")
CM = Replace(CM, "亿零万零圆", "亿圆")
CM = Replace(CM, "亿零万", "亿零")
CM = Replace(CM, "万零圆", "万圆")
CM = Replace(CM, "零亿", "亿")
CM = Replace(CM, "零万", "万")
CM = Replace(CM, "零圆", "圆")
CM = Replace(CM, "零零", "零")
CM = Replace(CM, "零零", "零") '重复替换一次

Complete:
Gerr = 0 '操作成功,无错误发生
MoneyConv = CM
Exit Function
Doerr:
Gerr = -1 '未知错误
Errexit:
MoneyConv = ""
End Function
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2003-9-1 18:33:00 | 只看该作者
请大家帮帮忙
3#
 楼主| 发表于 2003-9-1 22:43:00 | 只看该作者

下面是个例子

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
4#
 楼主| 发表于 2003-9-4 18:13:00 | 只看该作者
请大家帮帮忙
5#
 楼主| 发表于 2003-9-11 17:45:00 | 只看该作者
斑竹帮帮忙吧
6#
发表于 2003-9-11 17:53:00 | 只看该作者
见http://www.accessoft.com/cgi-bin/dispbbs.asp?boardID=14&replyID=199&ID=156&skin=1
7#
发表于 2003-9-11 21:03:00 | 只看该作者
好像没有问题啊!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-11 01:34 , Processed in 0.081020 second(s), 31 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表