vb貨幣轉換成數字
A. vb怎麼轉換成數字型
用函數val,val("12345")等於數值12345。但是必須是整型。它的逆函數(數值變字元串是str)
B. VB字母轉換成數字的問題
'把字母轉換成ASCII碼
'小寫
for i = asc("a") to asc("z")
print chr(i) & i
next
'大寫
for i = asc("A") to asc("Z")
print chr(i) & i
next
'把字母轉換成1~26
Private Sub Command1_Click()
For i = 1 To 26
Print i & Chr(i + 96) & Chr(i + 64)
Next
End Sub
C. VB 如何將數字字元串轉換成數字用以計算
用val就可以了,比如a是字元型的變數
a="1500"
b=val(a)
這時候b就是1500(數值)了。
D. vb字母轉化為數字
Private Function ChangeStr(ByVal strTemp As String) As String
Dim i As Integer
Dim str1 As String
str1 = ""
'如果字元串全是數字
If IsNumeric(strTemp) Then
For i = 1 To Len(strTemp)
str1 = str1 & Chr(Asc("a") + Val(Mid(strTemp, i, 1)) - 1)
Next
'如果字元串全是字母
ElseIf IsZimu(strTemp) Then
For i = 1 To Len(strTemp)
If Asc(Mid(strTemp, i, 1)) >= Asc("A") And Asc(Mid(strTemp, i, 1)) <= Asc("Z") Then
str1 = str1 & "(" & Asc(Mid(strTemp, i, 1)) - Asc("A") + 1 & ")"
Else
str1 = str1 & Asc(Mid(strTemp, i, 1)) - Asc("a") + 1
End If
Next
'如果都不是
Else
str1 = "字元串中必須完全是字母或者完全是數字"
End If
Text2.Text = str1
End Function
'判斷字元串是不是全是字母
Private Function IsZimu(ByVal strTemp As String) As Boolean
Dim i As Integer
strTemp = UCase(strTemp)
For i = 1 To Len(strTemp)
If Asc(Mid(strTemp, i, 1)) < Asc("A") Or Asc(Mid(strTemp, i, 1)) > Asc("Z") Then
Exit For
End If
Next
If i > Len(strTemp) Then
IsZimu = True
Else
IsZimu = False
End If
End Function
Private Sub Command1_Click()
ChangeStr Text1.Text
End Sub
E. 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
F. 求用VB實現的數字轉換英文的程序,不是貨幣轉換,只數字就OK了,包括0的,跪求代碼啊~~
Option Explicit
'Main Function
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp, Cents1
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "
' 字元串表示的金額。
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.小數點後的位置0如果沒有。
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.MyNumber轉換美分和設置,金額。
If DecimalPlace > 0 Then
Cents = Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2)
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Cents1 = GetCents(Cents)
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dollars
Case ""
Dollars = ""
Case "One"
Dollars = "One"
Case Else
Dollars = Dollars
End Select
Select Case Cents1
Case ""
Cents1 = ""
Case "One"
Cents1 = " point One"
Case Else
Cents1 = " point " & Cents1
End Select
SpellNumber = Dollars & Cents1
Do While InStr(SpellNumber, " ") > 0
SpellNumber = Replace(SpellNumber, " ", " ")
Loop
End Function
' Converts a number from 100-999 into text轉換數字100 - 999進入文本
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.轉換百的地方。
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred and "
End If
' Convert the tens and ones place.轉換千的地方。
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function
' Converts a number from 10 to 99 into text.轉換數字從10到99成文本。
Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.空出暫時的函數值。
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result & GetDigit _
(Right(TensText, 1)) ' Retrieve ones place.檢索的地方。
End If
GetTens = Result
End Function
' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function
Function GetCents(ByVal Cents)
Dim Result As String
Result = ""
If Val(Left(Cents, 1)) = 1 Then
Select Case Val(Cents)
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
ElseIf Val(Mid(Cents, 2, 1)) = 0 Then
Select Case Val(Left(Cents, 1))
Case 2: Result = "Two"
Case 3: Result = "Three"
Case 4: Result = "Four"
Case 5: Result = "Five"
Case 6: Result = "Six"
Case 7: Result = "Seven"
Case 8: Result = "Eight"
Case 9: Result = "Nine"
Case Else
End Select
Else
Select Case Val(Left(Cents, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result & GetDigit _
(Right(Cents, 1))
End If
GetCents = Result
End Function
G. 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
H. 用VB編寫一款貨幣轉換程序
構思可能不錯,好像可能沒有人為5個網路分化這樣的精力吧。
I. 在VB中怎麼把字元型轉化成數字型
用val(),如val("12")如果是要獲取字元的Ascii碼,就用asc(),如asc("A")
J. vb.net 如何把大寫金額轉換成阿拉伯數字金額
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