当前位置:首页 » 股市行情 » vb怎么转换货币

vb怎么转换货币

发布时间: 2022-08-07 04:45:20

❶ vb 数字转换为中文大写钱币转换程序

给出一个例子,以求抛砖引玉~~~~~~

建两个Text控件:text1,text2
建三个Command控件:
Command1:转换
Command2:退出
Command3:清除
在text1中输入金额,点Command1进行转换,text2显示大写金额结果。

'写代码如下:
Function daxie(money As String) As String '
Dim x As String, y As String
Const zimu = ".sbqwsbqysbqwsbq" '定义位置代码
Const letter = "0123456789sbqwy.jzf" '定义数字及汉字缩写
Const upcase = "零壹贰叁肆伍陆柒捌玖拾佰仟万亿圆角整分" '定义大写汉字
Dim temp As String
temp = money
If InStr(temp, ".") > 0 Then temp = Left(temp, InStr(temp, ".") - 1)

If Len(temp) > 16 Then MsgBox "数目太大,无法换算!请输入一亿亿以下的数字", 64, "错误提示": Exit Function '只能转换一亿亿元以下数目的货币!

x = Format(money, "0.00") '格式化货币
y = ""
For i = 1 To Len(x) - 3
y = y & Mid(x, i, 1) & Mid(zimu, Len(x) - 2 - i, 1)
Next
If Right(x, 3) = ".00" Then
y = y & "z" '***元整
Else
y = y & Left(Right(x, 2), 1) & "j" & Right(x, 1) & "f" '*元*角*分
End If
y = Replace(y, "0q", "0") '避免零千(如:40200肆万零千零贰佰)
y = Replace(y, "0b", "0") '避免零百(如:41000肆万壹千零佰)
y = Replace(y, "0s", "0") '避免零十(如:204贰佰零拾零肆)
y = Replace(y, "0j", "0") '避免零角
y = Replace(y, "0f", "整")

Do While y <> Replace(y, "00", "0")
y = Replace(y, "00", "0") '避免双零(如:1004壹仟零零肆)
Loop
y = Replace(y, "0y", "y") '避免零亿(如:210亿 贰佰壹十零亿)
y = Replace(y, "0w", "w") '避免零万(如:210万 贰佰壹十零万)
y = IIf(Len(x) = 5 And Left(y, 1) = "1", Right(y, Len(y) - 1), y) '避免壹十(如:14壹拾肆;10壹拾)
y = IIf(Len(x) = 4, Replace(y, "0.", ""), Replace(y, "0.", ".")) '避免零元(如:20.00贰拾零圆;0.12零圆壹角贰分)

For i = 1 To 19
y = Replace(y, Mid(letter, i, 1), Mid(upcase, i, 1)) '大写汉字
Next
daxie = y
End Function

Private Sub Command1_Click()
Text2.Text = daxie(Val(Text1.Text)) ' (如return: 贰玖仟叁佰贰拾贰圆叁角贰分
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
End Sub

❷ 将VB文本框内输入的数字转为货币形式

用数字格式函数format(12000,"#,##0.00")就可以了

❸ 将VB输入的值转为货币形式

Private Sub cmdCommand1_Click()
Print Format(Val(txtText1.Text), "#,#")
End Sub

Private Sub cmdCommand1_Click()
Print Format(Val(txtText1.Text), "#.00%")
End Sub

❹ 求VB编程:货币兑换,输入人民币,兑换成美元,比例1:8.25

控件如下:
1.人民币后面的文本框 Text1
2.兑换后 后面的文本框 Text2
3.退出按钮 Command1
4.兑换按钮 Command2
5.清除按钮 Command3
6.美元单选框 Option1
7.港元单选框 Option2

代码如下

Private Sub Command1_Click()
End
End Sub

Private Sub Command2_Click()
Dim HuiLv As Currency
If Option1.Value = True Then
HuiLv = 1 / 8.25 '美元汇率
Else
HuiLv = 1 / 1.15 '港元
End If
Text2 = CCur(Text1) * HuiLv
End Sub

Private Sub Command3_Click()
Text1 = ""
Text2 = ""
Text1.SetFocus
End Sub

❺ vb6.0进行100元换成零钱的算法

问题有两点:

1、你把for x=0 to 20这一行注释掉了,估计是笔误;

2、窗体的AutoRedraw属性为默认值或False的时候,Print输出是临时性的(也即是窗口刷新后Print输出的内容将被擦除),所以要么Print前把窗体拉倒足够大,要么设置AutoRedraw属性为True,这样Print的内容将转换为持续性的。


OptionExplicit

PrivateSubForm_Click()
Me.Cls
Me.AutoRedraw=True
Dimx%,y%,z%,n%
Print"5元的张数","10元的张数","20元的张数"
Forx=0To20'设置5元张数最多20张
Fory=0To10'设置10元最多张数为10张
Forz=0To5'设置20元最多张数为5张
If5*x+y*10+z*20=100Then'满足三种货币金额为100元
n=n+1'满足条件的数值加1
Printx,y,z'输出结果
EndIf
Next
Next
Next

Print"100元换成20元、10元、5元共有"&n&"种办法"
EndSub

PrivateSubForm_Click()
Dimx%,y%,z%,n%
Print"5元的张数","10元的张数","20元的张数"
Forx=0To20
Fory=0To(100-x*5)10
Forz=0To(100-x*5-y*10)20
If5*x+y*10+z*20=100Then
n=n+1
Printx,y,z
EndIf
Next
Next
Next

Print"100元换成20元、10元、5元共有"&n&"种办法"
EndSub

❻ 编写一个VB程序设计,使得输入一个数字,当点击按钮后转换为中文大写的货币表示。 谢谢了,急需

说明:该函数属于本人2002年独创,后流传于网络各站,现今稍有改动,更正了大于9百万亿不能转换的问题。

'将数字转换为大写金额的函数,最大正负极限:922337203685477
Function CurrencyToStr(ByVal Number As Double) As String
Number = Val(Trim(Number))
If Number = 0 Then Exit Function
Dim str1Ary As Variant, str2Ary As Variant
str1Ary = Split("零 壹 贰 叁 肆 伍 陆 柒 捌 玖")
str2Ary = Split("分 角 元 拾 佰 仟 万 拾 佰 仟 亿 拾 佰 仟 万 拾 佰")
Dim a As Long, b As Long
Dim tmp1 As String
Dim tmp2 As String
Dim Point As Long
If Number <= -922337203685477# Then Number = -922337203685477#
If Number >= 922337203685477# Then Number = 922337203685477#
tmp1 = Round(Number, 2)
tmp1 = Replace(tmp1, "-", "")
Point = InStr(tmp1, ".")

If Point = 0 Then
b = Len(tmp1) + 2
Else
b = Len(Left(tmp1, Point + 1))
End If
For a = 9 To 0 Step -1
tmp1 = Replace(Replace(tmp1, a, str1Ary(a)), ".", "")
Next
For a = 1 To b
b = b - 1
If Mid(tmp1, a, 1) <> "" Then
If b > UBound(str2Ary) Then Exit For
tmp2 = tmp2 & Mid(tmp1, a, 1) & str2Ary(b)
End If
Next
If tmp2 = "" Then CurrencyToStr = "": Exit Function
For a = 1 To Len(tmp2)
tmp2 = Replace(tmp2, "零亿", "亿零")
tmp2 = Replace(tmp2, "零万", "万零")
tmp2 = Replace(tmp2, "零仟", "零")
tmp2 = Replace(tmp2, "零佰", "零")
tmp2 = Replace(tmp2, "零拾", "零")
tmp2 = Replace(tmp2, "零元", "元")
tmp2 = Replace(tmp2, "零零", "零")
tmp2 = Replace(tmp2, "亿万", "亿")
Next
If Point = 1 Then tmp2 = "零元" + tmp2
If Number < 0 Then tmp2 = "负" + tmp2
If Point = 0 Then tmp2 = tmp2 + "整"
CurrencyToStr = tmp2
End Function

❼ 用vb编写 人民币汇率

保存下面的代码到一个后缀名为FRM的文件中,再用VB打开即可。
============
VERSION
5.00
Begin
VB.Form
Form1
Caption
=
"人民币转换工具"
ClientHeight
=
3195
ClientLeft
=
60
ClientTop
=
345
ClientWidth
=
4680
LinkTopic
=
"Form1"
ScaleHeight
=
3195
ScaleWidth
=
4680
StartUpPosition
=
3
'窗口缺省
Begin
VB.OptionButton
Option1
Caption
=
"转换成欧元"
Height
=
495
Index
=
3
Left
=
1680
TabIndex
=
4
Top
=
1200
Width
=
1335
End
Begin
VB.OptionButton
Option1
Caption
=
"转换成日元"
Height
=
495
Index
=
2
Left
=
240
TabIndex
=
3
Top
=
1200
Width
=
1215
End
Begin
VB.OptionButton
Option1
Caption
=
$"Form2.frx":0000
Height
=
495
Index
=
1
Left
=
1680
TabIndex
=
2
Top
=
720
Width
=
1335
End
Begin
VB.OptionButton
Option1
Caption
=
"转换成美元"
Height
=
495
Index
=
0
Left
=
240
TabIndex
=
1
Top
=
720
Width
=
1215
End
Begin
VB.TextBox
Text1
Height
=
375
Left
=
240
TabIndex
=
0
Top
=
120
Width
=
1455
End
Begin
VB.Label
Label1
Height
=
375
Left
=
480
TabIndex
=
5
Top
=
1800
Width
=
3015
End
End
Attribute
VB_Name
=
"Form1"
Attribute
VB_GlobalNameSpace
=
False
Attribute
VB_Creatable
=
False
Attribute
VB_PredeclaredId
=
True
Attribute
VB_Exposed
=
False
Option
Explicit
Private
Sub
Option1_Click(Index
As
Integer)
Dim
t
As
Single
t
=
Val(Text1.Text)
Label1.Caption
=
FormatNumber(Choose(Index
+
1,
t
/
7.7,
t
/
15.47,
t
/
0.081,
t
/
10.8),
,
vbTrue)
End
Sub

❽ VB语言中如何将阿拉伯数字转换成大写人民币金额

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)) + "角"
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 = mystr1 & "万"
Else
If Right(mystr1, 1) <> "零" And Right(money, 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

❾ vb 如何进行类型转换

字符串、数字的转换,很通用的有
将数字转换成字符串: str
将字符串转换为数字: val

下面是强制转换,强制转换,特点是以C开头
强制转换为布尔类型:CBool
强制转换为字节类型: CByte
强制转换为货币类型:CCur
强制转换为日期类型: CDate
强制转换为双精度浮点数:CDbl
强制转换为整形:CInt
强制转换为长整形:CLng
强制转换为单精度浮点数:CSng

以上是最常用的,还有一些,用的比较少,如CDec,CVar等,就不介绍了。

热点内容
如何遇见基金大跌 发布:2025-06-18 00:08:05 浏览:855
重阳投资哪个基金好 发布:2025-06-17 23:52:40 浏览:91
2021上海总市值多少 发布:2025-06-17 23:41:06 浏览:962
阿尔特股票历史行情 发布:2025-06-17 23:37:53 浏览:270
微信理财没有了怎么投诉 发布:2025-06-17 23:26:23 浏览:560
派瑞科技股票代码 发布:2025-06-17 22:58:01 浏览:639
布加迪的市值是多少 发布:2025-06-17 22:45:05 浏览:197
迎丰科技股票股东 发布:2025-06-17 22:22:34 浏览:787
美国股票对金银影响 发布:2025-06-17 22:17:42 浏览:762
如何从金融方面去分析一个公司 发布:2025-06-17 22:13:30 浏览:501