我想在visual basic中将数字转换成单词 [英] I wanna convert number into words in visual basic
问题描述
我使用的软件是Visual Basic。它不是Visual Basic .NET,而是Visual Basic(Visual Studio)。我在Visual Basic中使用控制台应用程序。我想将数字转换成单词。
Ex。数字:555字:五百五十五
所以,请有人帮我这个。
谢谢。
我尝试了什么:
Option Strict在
模块模块1
Sub Main()
Const MILLIONS As整数= 1000000
Const HUNDRED_THOUSANDS As Integer = 100000
Const TEN_THOUSANDS As Integer = 10000
Const THOUSANDS As Integer = 1000
Const HUNDREDS As Integer = 100
Const TENS As Integer = 10
Dim userInput As String
Dim convertedValue As Long
昏暗的结果为长
Dim TextVersion As String =
Dim thousandsFlag As Boolean = False
userInput = InputBox(输入一美元($)金额)
'用于将用户输入更改为Long Integer
convertedValue = Long.Pars e(userInput)
如果convertedValue>百万然后
结束如果
如果convertedValue> HUNDRED_THOUSANDS然后
,000Flag = True
result = convertedValue \ HUNDRED_THOUSANDS
convertedValue = convertedValue - (HUNDRED_THOUSANDS *结果)
如果结果= 9那么
TextVersion = TextVersion +Nine
ElseIf result = 8然后
TextVersion = TextVersion +Eight
ElseIf result = 7然后
TextVersion = TextVersion +Seven
ElseIf结果= 6然后
TextVersion = TextVersion +六
ElseIf结果= 5然后
TextVersion = TextVersion +Five
ElseIf结果= 4然后
TextVersion = TextVersion +四
ElseIf结果= 3然后
TextVersion = TextVersion +Three
ElseIf result = 2然后
TextVersion = TextVersion +Two
Else
TextVersion = TextVersion +One
结束如果
TextVersion = TextVersion +Hundred
结束如果
如果convertedValue> TEN_THOUSANDS然后
,000Flag = True
结束如果
如果convertedValue>成千上那么
,000Flag =真
结束如果
If(thousandsFlag = True)然后
If(convertedValue> 0)然后
TextVersion = TextVersion +千,AND
Else
TextVersion = TextVersion +Thousand
结束如果
结束如果
如果convertedValue>百德然后
result = convertedValue \百万
convertedValue = convertedValue - (HUNDREDS * result)
如果result = 9那么
TextVersion = TextVersion +Nine
ElseIf result = 8然后
TextVersion = TextVersion +Eight
ElseIf result = 7然后
TextVersion = TextVersion +七
ElseIf结果= 6然后
TextVersion = TextVersion +Six
ElseIf result = 5然后
TextVersion = TextVersion +Five
ElseIf result = 4然后
TextVersion = TextVersion +Four
ElseIf结果= 3然后
TextVersion = TextVersion +三
ElseIf结果= 2然后
TextVersion = TextVersion +Two
Else
TextVersion = TextVersion +One
结束如果
TextVersion = TextVersion +Hundred
如果convertedValue> 0然后
TextVersion = TextVersion +和
结束如果
结束如果
如果convertedValue> TENS然后
result = convertedValue \ TENS
convertedValue = convertedValue - (TENS * result)
如果result = 9那么
TextVersion = TextVersion +Ninty
ElseIf result = 8然后
TextVersion = TextVersion +Eighty
ElseIf result = 7然后
TextVersion = TextVersion +七十
ElseIf结果= 6然后
TextVersion = TextVersion +Sixty
ElseIf result = 5然后
TextVersion = TextVersion +Fifty
ElseIf result = 4然后
TextVersion = TextVersion +Fourty
ElseIf结果= 3然后
TextVersion = TextVersion +Thirty
ElseIf result = 2然后
TextVersion = TextVersion +Twenty
Else
TextVersion = TextVersion
结束如果
如果convertedValue> 0然后
TextVersion = TextVersion + -
结束如果
结束如果
如果convertedValue< TENS然后
如果convertedValue = 9则
TextVersion = TextVersion +Nine+Dollars
ElseIf convertedValue = 8然后>
TextVersion = TextVersion +Eight+Dollars
ElseIf convertedValue = 7然后
TextVersion = TextVersion +Seven+Dollars
ElseIf convertedValue = 6然后
TextVersion = TextVersion +六+美元
ElseIf convertedValue = 5然后
TextVersion = TextVersion +Five+Dollars
ElseIf convertedValue = 4然后
TextVersion = TextVersion +Four+Dollars
ElseIf convertedValue = 3然后
TextVersion = TextVersion +三+美元
ElseIf convertedValue = 2然后
TextVersion = TextVersion +两个+美元
ElseIf convertedValue = 1然后
TextVersion = TextVersion +一个+美元
Else
TextVersion = TextVersion +美元
结束如果
结束如果
System.Console.WriteLine(TextVersion)
系统。 Console.ReadLine()
结束子
结束模块
The Software that I use is Visual Basic. It is not Visual Basic .NET, it is Visual Basic (Visual Studio). I use Console Application in the Visual Basic. I want to convert numbers into words.
Ex. Numbers: 555 Words: Five Hundred Fifty Five
So please, could anybody help me with that.
Thank you.
What I have tried:
Option Strict On
Module Module1
Sub Main()
Const MILLIONS As Integer = 1000000
Const HUNDRED_THOUSANDS As Integer = 100000
Const TEN_THOUSANDS As Integer = 10000
Const THOUSANDS As Integer = 1000
Const HUNDREDS As Integer = 100
Const TENS As Integer = 10
Dim userInput As String
Dim convertedValue As Long
Dim result As Long
Dim TextVersion As String = ""
Dim thousandsFlag As Boolean = False
userInput = InputBox("Enter A Dollar ($) Amount ")
' Used to change user input to a Long Integer
convertedValue = Long.Parse(userInput)
If convertedValue > MILLIONS Then
End If
If convertedValue > HUNDRED_THOUSANDS Then
thousandsFlag = True
result = convertedValue \ HUNDRED_THOUSANDS
convertedValue = convertedValue - (HUNDRED_THOUSANDS * result)
If result = 9 Then
TextVersion = TextVersion + "Nine"
ElseIf result = 8 Then
TextVersion = TextVersion + "Eight"
ElseIf result = 7 Then
TextVersion = TextVersion + "Seven"
ElseIf result = 6 Then
TextVersion = TextVersion + "Six"
ElseIf result = 5 Then
TextVersion = TextVersion + "Five"
ElseIf result = 4 Then
TextVersion = TextVersion + "Four"
ElseIf result = 3 Then
TextVersion = TextVersion + "Three"
ElseIf result = 2 Then
TextVersion = TextVersion + "Two"
Else
TextVersion = TextVersion + "One"
End If
TextVersion = TextVersion + " Hundred "
End If
If convertedValue > TEN_THOUSANDS Then
thousandsFlag = True
End If
If convertedValue > THOUSANDS Then
thousandsFlag = True
End If
If (thousandsFlag = True) Then
If (convertedValue > 0) Then
TextVersion = TextVersion + " Thousand, AND "
Else
TextVersion = TextVersion + " Thousand "
End If
End If
If convertedValue > HUNDREDS Then
result = convertedValue \ HUNDREDS
convertedValue = convertedValue - (HUNDREDS * result)
If result = 9 Then
TextVersion = TextVersion + "Nine"
ElseIf result = 8 Then
TextVersion = TextVersion + "Eight"
ElseIf result = 7 Then
TextVersion = TextVersion + "Seven"
ElseIf result = 6 Then
TextVersion = TextVersion + "Six"
ElseIf result = 5 Then
TextVersion = TextVersion + "Five"
ElseIf result = 4 Then
TextVersion = TextVersion + "Four"
ElseIf result = 3 Then
TextVersion = TextVersion + "Three"
ElseIf result = 2 Then
TextVersion = TextVersion + "Two"
Else
TextVersion = TextVersion + "One"
End If
TextVersion = TextVersion + " Hundred "
If convertedValue > 0 Then
TextVersion = TextVersion + " And "
End If
End If
If convertedValue > TENS Then
result = convertedValue \ TENS
convertedValue = convertedValue - (TENS * result)
If result = 9 Then
TextVersion = TextVersion + "Ninty"
ElseIf result = 8 Then
TextVersion = TextVersion + "Eighty"
ElseIf result = 7 Then
TextVersion = TextVersion + "Seventy"
ElseIf result = 6 Then
TextVersion = TextVersion + "Sixty"
ElseIf result = 5 Then
TextVersion = TextVersion + "Fifty"
ElseIf result = 4 Then
TextVersion = TextVersion + "Fourty"
ElseIf result = 3 Then
TextVersion = TextVersion + "Thirty"
ElseIf result = 2 Then
TextVersion = TextVersion + "Twenty"
Else
TextVersion = TextVersion
End If
If convertedValue > 0 Then
TextVersion = TextVersion + "-"
End If
End If
If convertedValue < TENS Then
If convertedValue = 9 Then
TextVersion = TextVersion + "Nine" + " Dollars"
ElseIf convertedValue = 8 Then
TextVersion = TextVersion + "Eight" + " Dollars"
ElseIf convertedValue = 7 Then
TextVersion = TextVersion + "Seven" + " Dollars"
ElseIf convertedValue = 6 Then
TextVersion = TextVersion + "Six" + " Dollars"
ElseIf convertedValue = 5 Then
TextVersion = TextVersion + "Five" + " Dollars"
ElseIf convertedValue = 4 Then
TextVersion = TextVersion + "Four" + " Dollars"
ElseIf convertedValue = 3 Then
TextVersion = TextVersion + "Three" + " Dollars"
ElseIf convertedValue = 2 Then
TextVersion = TextVersion + "Two" + " Dollars"
ElseIf convertedValue = 1 Then
TextVersion = TextVersion + "One" + " Dollar"
Else
TextVersion = TextVersion + " Dollars"
End If
End If
System.Console.WriteLine(TextVersion)
System.Console.ReadLine()
End Sub
End Module
推荐答案
)金额)
'用于将用户输入更改为长整数
convertedValue = Long.Parse(userInput)
如果convertedValue>百万然后
结束如果
如果convertedValue> HUNDRED_THOUSANDS然后
,000Flag = True
result = convertedValue \ HUNDRED_THOUSANDS
convertedValue = convertedValue - (HUNDRED_THOUSANDS *结果)
如果结果= 9那么
TextVersion = TextVersion +Nine
ElseIf result = 8然后
TextVersion = TextVersion +Eight
ElseIf result = 7然后
TextVersion = TextVersion +Seven
ElseIf结果= 6然后
TextVersion = TextVersion +六
ElseIf结果= 5然后
TextVersion = TextVersion +Five
ElseIf结果= 4然后
TextVersion = TextVersion +四
ElseIf结果= 3然后
TextVersion = TextVersion +Three
ElseIf result = 2然后
TextVersion = TextVersion +Two
Else
TextVersion = TextVersion +One
结束如果
TextVersion = TextVersion +Hundred
结束如果
如果convertedValue> TEN_THOUSANDS然后
,000Flag = True
结束如果
如果convertedValue>成千上那么
,000Flag =真
结束如果
If(thousandsFlag = True)然后
If(convertedValue> 0)然后
TextVersion = TextVersion +千,AND
Else
TextVersion = TextVersion +Thousand
结束如果
结束如果
如果convertedValue>百德然后
result = convertedValue \百万
convertedValue = convertedValue - (HUNDREDS * result)
如果result = 9那么
TextVersion = TextVersion +Nine
ElseIf result = 8然后
TextVersion = TextVersion +Eight
ElseIf result = 7然后
TextVersion = TextVersion +七
ElseIf结果= 6然后
TextVersion = TextVersion +Six
ElseIf result = 5然后
TextVersion = TextVersion +Five
ElseIf result = 4然后
TextVersion = TextVersion +Four
ElseIf结果= 3然后
TextVersion = TextVersion +三
ElseIf结果= 2然后
TextVersion = TextVersion +Two
Else
TextVersion = TextVersion +One
结束如果
TextVersion = TextVersion +Hundred
如果convertedValue> 0然后
TextVersion = TextVersion +和
结束如果
结束如果
如果convertedValue> TENS然后
result = convertedValue \ TENS
convertedValue = convertedValue - (TENS * result)
如果result = 9那么
TextVersion = TextVersion +Ninty
ElseIf result = 8然后
TextVersion = TextVersion +Eighty
ElseIf result = 7然后
TextVersion = TextVersion +七十
ElseIf结果= 6然后
TextVersion = TextVersion +Sixty
ElseIf result = 5然后
TextVersion = TextVersion +Fifty
ElseIf result = 4然后
TextVersion = TextVersion +Fourty
ElseIf结果= 3然后
TextVersion = TextVersion +Thirty
ElseIf result = 2然后
TextVersion = TextVersion +Twenty
Else
TextVersion = TextVersion
结束如果
如果convertedValue> 0然后
TextVersion = TextVersion + -
结束如果
结束如果
如果convertedValue< TENS然后
如果convertedValue = 9则
TextVersion = TextVersion +Nine+Dollars
ElseIf convertedValue = 8然后>
TextVersion = TextVersion +Eight+Dollars
ElseIf convertedValue = 7然后
TextVersion = TextVersion +Seven+Dollars
ElseIf convertedValue = 6然后
TextVersion = TextVersion +六+美元
ElseIf convertedValue = 5然后
TextVersion = TextVersion +Five+Dollars
ElseIf convertedValue = 4然后
TextVersion = TextVersion +Four+Dollars
ElseIf convertedValue = 3然后
TextVersion = TextVersion +三+美元
ElseIf convertedValue = 2然后
TextVersion = TextVersion +两个+美元
ElseIf convertedValue = 1然后
TextVersion = TextVersion +一个+美元
Else
TextVersion = TextVersion +美元
结束如果
结束如果
System.Console.WriteLine(TextVersion)
系统。 Console.ReadLine()
结束子
结束模块
) Amount ")
' Used to change user input to a Long Integer
convertedValue = Long.Parse(userInput)
If convertedValue > MILLIONS Then
End If
If convertedValue > HUNDRED_THOUSANDS Then
thousandsFlag = True
result = convertedValue \ HUNDRED_THOUSANDS
convertedValue = convertedValue - (HUNDRED_THOUSANDS * result)
If result = 9 Then
TextVersion = TextVersion + "Nine"
ElseIf result = 8 Then
TextVersion = TextVersion + "Eight"
ElseIf result = 7 Then
TextVersion = TextVersion + "Seven"
ElseIf result = 6 Then
TextVersion = TextVersion + "Six"
ElseIf result = 5 Then
TextVersion = TextVersion + "Five"
ElseIf result = 4 Then
TextVersion = TextVersion + "Four"
ElseIf result = 3 Then
TextVersion = TextVersion + "Three"
ElseIf result = 2 Then
TextVersion = TextVersion + "Two"
Else
TextVersion = TextVersion + "One"
End If
TextVersion = TextVersion + " Hundred "
End If
If convertedValue > TEN_THOUSANDS Then
thousandsFlag = True
End If
If convertedValue > THOUSANDS Then
thousandsFlag = True
End If
If (thousandsFlag = True) Then
If (convertedValue > 0) Then
TextVersion = TextVersion + " Thousand, AND "
Else
TextVersion = TextVersion + " Thousand "
End If
End If
If convertedValue > HUNDREDS Then
result = convertedValue \ HUNDREDS
convertedValue = convertedValue - (HUNDREDS * result)
If result = 9 Then
TextVersion = TextVersion + "Nine"
ElseIf result = 8 Then
TextVersion = TextVersion + "Eight"
ElseIf result = 7 Then
TextVersion = TextVersion + "Seven"
ElseIf result = 6 Then
TextVersion = TextVersion + "Six"
ElseIf result = 5 Then
TextVersion = TextVersion + "Five"
ElseIf result = 4 Then
TextVersion = TextVersion + "Four"
ElseIf result = 3 Then
TextVersion = TextVersion + "Three"
ElseIf result = 2 Then
TextVersion = TextVersion + "Two"
Else
TextVersion = TextVersion + "One"
End If
TextVersion = TextVersion + " Hundred "
If convertedValue > 0 Then
TextVersion = TextVersion + " And "
End If
End If
If convertedValue > TENS Then
result = convertedValue \ TENS
convertedValue = convertedValue - (TENS * result)
If result = 9 Then
TextVersion = TextVersion + "Ninty"
ElseIf result = 8 Then
TextVersion = TextVersion + "Eighty"
ElseIf result = 7 Then
TextVersion = TextVersion + "Seventy"
ElseIf result = 6 Then
TextVersion = TextVersion + "Sixty"
ElseIf result = 5 Then
TextVersion = TextVersion + "Fifty"
ElseIf result = 4 Then
TextVersion = TextVersion + "Fourty"
ElseIf result = 3 Then
TextVersion = TextVersion + "Thirty"
ElseIf result = 2 Then
TextVersion = TextVersion + "Twenty"
Else
TextVersion = TextVersion
End If
If convertedValue > 0 Then
TextVersion = TextVersion + "-"
End If
End If
If convertedValue < TENS Then
If convertedValue = 9 Then
TextVersion = TextVersion + "Nine" + " Dollars"
ElseIf convertedValue = 8 Then
TextVersion = TextVersion + "Eight" + " Dollars"
ElseIf convertedValue = 7 Then
TextVersion = TextVersion + "Seven" + " Dollars"
ElseIf convertedValue = 6 Then
TextVersion = TextVersion + "Six" + " Dollars"
ElseIf convertedValue = 5 Then
TextVersion = TextVersion + "Five" + " Dollars"
ElseIf convertedValue = 4 Then
TextVersion = TextVersion + "Four" + " Dollars"
ElseIf convertedValue = 3 Then
TextVersion = TextVersion + "Three" + " Dollars"
ElseIf convertedValue = 2 Then
TextVersion = TextVersion + "Two" + " Dollars"
ElseIf convertedValue = 1 Then
TextVersion = TextVersion + "One" + " Dollar"
Else
TextVersion = TextVersion + " Dollars"
End If
End If
System.Console.WriteLine(TextVersion)
System.Console.ReadLine()
End Sub
End Module
这是多么令人惊讶设为家庭作业!
所以我经常这样做:将数字转换为等价的单词。 [ ^ ] - 代码是C#,但很容易理解......
或者,Google会为您找到大量其他解决方案。
It's amazing how often this gets set as homework!
So often in fact that I produced this: Converting numbers to the word equivalent. [^] - the code is C#, but it's easy to understand...
Alternatively, Google will find you loads of other solutions.
这篇关于我想在visual basic中将数字转换成单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!