我正在为我的Visual Basic类开发一个项目,即创建数字检查。作业要求我们输入一个支票金额,用于翻译成单词。例如,$ 1,200.00需要输出"一千二百美元"
在大多数情况下,我的代码有效。我正在使用switch语句。最初的任务是让我们的支票价值达到9,999,但是随着我们继续建立,我们需要能够转换为99,999。
正如我所说,我一直在使用一系列案例陈述,但意识到这是一个非常严格的代码"这样做的方法,并希望创建一个方法,可以为我检查这些类型的东西,但我仍然是Visual Basic的新手,并没有真正的好主意从哪里开始或适用于什么这种情况(我们真的没有一个例子可以过去。)
这是我的WriteCheck方法,它主要进行分配/转换。
'Convert check value from a text field to a double' Try checkValue = checkInput.Text Catch ex As InvalidCastException MessageBox.Show("You must enter a numbers to write a check.") End Try 'Operation to convert number to String' thousands = checkValue \ 1000 hundreds = checkValue Mod 1000 hundreds = hundreds \ 100 tens = checkValue Mod 100 tens = tens \ 10 ones = checkValue Mod 10 ones = ones \ 1 'Case for thousands' Select Case thousands & hundreds & tens Case 1 tempStringT = "One" Case 2 tempStringT = "Two" Case 3 tempStringT = "Three" Case 4 tempStringT = "Four" Case 5 tempStringT = "Five" Case 6 tempStringT = "Six" Case 7 tempStringT = "Seven" Case 8 tempStringT = "Eight" Case 9 tempStringT = "Nine" End Select 'Case for hundreds' Select Case hundreds Case 1 tempStringH = "one" Case 2 tempStringH = "two" Case 3 tempStringH = "three" Case 4 tempStringH = "four" Case 5 tempStringH = "five" Case 6 tempStringH = "six" Case 7 tempStringH = "seven" Case 8 tempStringH = "eight" Case 9 tempStringH = "nine" End Select 'Case for tens' Select Case tens Or ones Case 1 tempStringTens = "one" Case 2 tempStringTens = "twenty" Case 3 tempStringTens = "thirty" Case 4 tempStringTens = "fourty" Case 5 tempStringTens = "fifty" Case 6 tempStringTens = "sixty" Case 7 tempStringTens = "seventy" Case 8 tempStringTens = "eighty" Case 9 tempStringTens = "ninety" End Select If tempStringTens <> "one" Then 'Case for ones' Select Case ones Case 1 tempStringO = "one" Case 2 tempStringO = "two" Case 3 tempStringO = "three" Case 4 tempStringO = "four" Case 5 tempStringO = "five" Case 6 tempStringO = "six" Case 7 tempStringO = "seven" Case 8 tempStringO = "eight" Case 9 tempStringO = "nine" End Select lblConverted.Text = tempStringT & " thousand " & tempStringH & " hundred " & tempStringTens & " " & tempStringO & " dollars " & change & "/100" End If If tempStringTens = "one" Then Select Case ones Case 1 tempStringO = "eleven" Case 2 tempStringO = "twelve" Case 3 tempStringO = "thirteen" Case 4 tempStringO = "fourteen" Case 5 tempStringO = "fifteen" Case 6 tempStringO = "sixteen" Case 7 tempStringO = "seventeen" Case 8 tempStringO = "eighteen" Case 9 tempStringO = "nineteen" End Select lblConverted.Text = tempStringT & " thousand " & tempStringH & " hundred " & tempStringO & " dollars" End If End Sub
答案 0 :(得分:1)
这是我解决问题的方法。通过在declare
l_seq_value number;
begin
l_seq_value := sequenceid.nextval;
insert into table1 (column1, column2, column3)
values (l_seq_value, 'text', 54576);
insert into table2 (column1, column2, column3, column4)
values (l_seq_value, sequenceid.nextval, 'Something else', 54576);
end;
/
中添加或删除项目并在必要时将BigNumbers
的范围提高到num
以上,可以轻松扩展或缩小解决方案。 (如上所述,它适用于最高999,999,999,999,999的数字。)
Long
由于这是针对学校的,您可能希望将我的部分代码改编为您自己的代码,而不是复制整个代码。 (教师通常可以判断您何时从互联网上获取代码,特别是如果您无法解释每一行。)如果您对此有任何疑问,请将其发送到我的个人资料中列出的电子邮件。