Hello folks,
I have been working with VB.NET for about two months now and have run into a wall. Up to this point I have been able to do everything my professor has asked without too much difficulty. The term is winding up and professor has asked me to work on a couple of problems during the break. One of these problems is to:
- have the user input a number into a text box
- using only integers, display the user’s input in reverse order as a result of a button’s click event
- in addition to reversing the order of the input, I need to display the result in words
Example: User’s input = 1234, I then display 4321 and four three two one
My professor was pleased with the following solution but asked me to try the same problem using arrays:
[/font]
Now to get to the point… I am unable to figure out how to get the users input into an array. Once I get the input into the array I should be able to use the reverse method to display the results and a select statement to assign and display the output as words. I know this is probably trivial, but if I could solicit any assistance I would greatly appreciate it.
Thanks,
Bill
I have been working with VB.NET for about two months now and have run into a wall. Up to this point I have been able to do everything my professor has asked without too much difficulty. The term is winding up and professor has asked me to work on a couple of problems during the break. One of these problems is to:
- have the user input a number into a text box
- using only integers, display the user’s input in reverse order as a result of a button’s click event
- in addition to reversing the order of the input, I need to display the result in words
Example: User’s input = 1234, I then display 4321 and four three two one
My professor was pleased with the following solution but asked me to try the same problem using arrays:
VB.NET:
[font=Courier New][color=green]'declarations[/color][/font]
[font=Courier New][color=blue]Dim[/color] origNum [color=blue]As[/color] [color=blue]Integer[/color][/font]
[font=Courier New][color=blue]Dim[/color] revNum [color=blue]As[/color] [color=blue]Integer[/color][/font]
[font=Courier New][color=blue]Dim[/color] numWord [color=blue]As[/color] [color=blue]String[/color][/font]
[font=Courier New][color=blue]Try[/color][/font]
[font=Courier New][color=green]'assignment[/color][/font]
[font=Courier New]origNum = Convert.ToInt32([color=blue]Me[/color].uiInputTextBox.Text)[/font]
[font=Courier New][color=green]'conversion[/color][/font]
[font=Courier New][color=blue]Do[/color] [color=blue]While[/color] origNum > 0[/font]
[font=Courier New]revNum = (revNum * 10) + (origNum [color=blue]Mod[/color] 10) [/font]
[font=Courier New]origNum = origNum \ 10 [/font]
[font=Courier New][color=blue]Loop[/color][/font]
[font=Courier New][color=green]'display reversed number[/color][/font]
[font=Courier New][color=blue]Me[/color].uiRevInputLabel.Text = revNum.ToString()[/font]
[font=Courier New][color=green]'convert the reversed number to words[/color][/font]
[font=Courier New]numWord = [color=blue]Me[/color].uiRevInputLabel.Text[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"9"[/color], [color=maroon]"Nine "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"8"[/color], [color=maroon]"Eight "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"7"[/color], [color=maroon]"Seven "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"6"[/color], [color=maroon]"Six "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"5"[/color], [color=maroon]"Five "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"4"[/color], [color=maroon]"Four "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"3"[/color], [color=maroon]"Three "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"2"[/color], [color=maroon]"Two "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"1"[/color], [color=maroon]"One "[/color])[/font]
[font=Courier New]numWord = numWord.Replace([color=maroon]"0"[/color], [color=maroon]"Zero "[/color])[/font]
[font=Courier New][color=green]'display reversed number as words[/color][/font]
[font=Courier New][color=blue]Me[/color].uiRevWordsLabel.Text = numWord[/font]
[font=Courier New][color=blue]Catch[/color] exFormat [color=blue]As[/color] FormatException[/font]
[font=Courier New]MessageBox.Show([color=maroon]"Only integer values allowed."[/color], [color=maroon]"Reverse _[/color][/font]
[color=maroon][font=Courier New]Numbers"[/font][/color][font=Courier New], MessageBoxButtons.OK, MessageBoxIcon.Information)[/font]
[font=Courier New][color=blue]Catch[/color] ex [color=blue]As[/color] Exception[/font]
[font=Courier New]MessageBox.Show(ex.Message, [color=maroon]"Reverse Numbers"[/color], _[/font]
[font=Courier New]MessageBoxButtons.OK, MessageBoxIcon.Information)[/font]
[font=Courier New][color=blue]End[/color] [color=blue]Try[/color][/font]
[font=Courier New][color=green]'sends focus to the uiInputTextBox[/color][/font]
[font=Courier New][color=blue]Me[/color].uiInputTextBox.Focus()[/font]
[font=Courier New]
Now to get to the point… I am unable to figure out how to get the users input into an array. Once I get the input into the array I should be able to use the reverse method to display the results and a select statement to assign and display the output as words. I know this is probably trivial, but if I could solicit any assistance I would greatly appreciate it.
Thanks,
Bill
Last edited: