Visual Basic 2008 Help

BoSoxFan900

CAGiversary!
Feedback
8 (100%)
I'm taking my first programming class and everything has been going pretty smoothly until now. We have to do the following:

Write a Visual Basic program that will convert a numeric check amount into text.
The check amount can be any value between $.01 and $499.99. This program uses SELECT/CASE and IF statements.

Example:
If you enter $197.18, it will spell out the check amount as
One Hundred Ninety Seven and 18/100 dollars.

Additional info:

First the Calculation.

If I have either of the following statements in a program, what is the answer?

1. 197.18 \ 100 Or
2. Int(197.18 / 100)

The answer to Item #1 is 1. The \ is the symbol for Integer Division. Integer Division is discussed on page 70, item #9.

The answer to Item #2 is 1. 197.18 / 100 equals 1.9718. The Int function will round the 1.9718 to the lowest whole number, which is 1.

If the answer is 1, you concatenate to a string "100 hundred". If you answered had been 2, then you would concatenate to a string "200 hundred", etc.

To do this, use a select case

example:

Case 1:
strAmount = strAmount + "One Hundred "
case 2:
strAmount = strAmount + "Two Hundred "
etc.

After you determine the Hundreds amount, you then deduct it from your check amount.

amount = amount - numberofhundreds * 100

if amount was 197.18 and the number of hundreds was 1, what is the answer to the formula?

amount = 197.18 - 1 * 100 -- 1 * 100 is done first, which your formula now becomes amount = 197.18 - 100 -- then amount would be
amount = 97.18

Next, determine the number of tens remaining in the check amount.

1. 97.18 \ 10 OR
2. int(97.18 / 10)

Answer #1 is 9
Answer #2 is 9.

9 means Ninety; use select to concatenate "Ninety" to the strAmount

then like previous example, subtract the number of tens from the check amount.

Finally, you will end up with only cents.

You will use the select/case to build the check amount as a string.



Does anyone have experience doing things like this? I would really appreciate any help you could give me because I'm completely lost. We're only supposed to use Select Case and If statements in completing the program.
 
As they say, first do a Select Case for the hundreds digit using the calculation they give you. Then do a Select Case for the tens digit after subtracting the hundreds. Then do a Select Case for the ones digit after subtracting the tens. And finally just throw anything after the decimal onto the string.
 
Should it look something like this?

Select Case amount
Case 1:
numberofhundreds = amount \ 100
newamount = amount - numberofhundreds * 100

?

I'm completely new to using Select Case. Also, how do I actually concatenate the word to the amount? (In other words, how do I concatenate "Ninety" to 90?) Do you simply use the & symbol? Thanks a lot for the quick response.
 
[quote name='BoSoxFan900']Should it look something like this?

Select Case amount
Case 1:
numberofhundreds = amount \ 100
newamount = amount - numberofhundreds * 100

?

I'm completely new to using Select Case. Also, how do I actually concatenate the word to the amount? (In other words, how do I concatenate "Ninety" to 90?) Do you simply use the & symbol?
Thanks a lot for the quick response.[/QUOTE]
You could setup your Select Case like what you've provided; given that your amount, numberofhundreds, and newamount are declared of a numeric type (i.e., Integer, Short, Long) w/o error.

If you just want to Print the concatenation of the word to the amount, you can use the '&'. However, if you want to assign the concatenation [of the word to the amount] to a variable, then you should make sure that both the variable and the results of the concatenation (or the word and/or amount) are of the same type. Otherwise, you'll run into an error.

P.S. - I don't know if you came across error-handling in your course yet. However, you may want to check for the validity of your input value(s), before the rest of your program executes. For example:

If the input value satisfies the given range,
continue the rest of the program.
Else,
"Invalid input."
 
bread's done
Back
Top