當前位置:首頁 » 股市行情 » 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