Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a visual basic program that requires the user to enter an integer from 20

ID: 3639421 • Letter: W

Question

Write a visual basic program that requires the user to enter an integer from 20 to 99 in numeric form. The program should output the equivalent number in words. For example, an input of 58 would result in output of "fifty-eight." Generate each of the two words separately to avoid 80 alternatives in the case statement. Use select case statements only, no if statements.

Explanation / Answer

Private Sub Form_Load() Dim varInt, varText As String 10 varInt = InputBox("Enter an integer between 20 and 99") varInt = Val(varInt) Select Case varInt Case 0 Me.Label1.Caption = "Nothing Entered" 'Label1 will display integer(s) Me.Label2.Caption = "No Conversion asked for" 'Label2 will display integers into words Exit Sub Case Is < 20, Is > 99 MsgBox "Only integers between 20 and 99 are valid", vbCritical, "Invalid integers" & varInt GoTo 10 End Select Select Case Left(varInt, 1) Case 2 varText = "Twenty" Case 3 varText = "Thirty" Case 4 varText = "Forty" Case 5 varText = "Fifty" Case 6 varText = "Sixty" Case 7 varText = "Seventy" Case 8 varText = "Eighty" Case Else varText = "Ninety" End Select Select Case Mid(varInt, 2, 1) Case 1 varText = varText & " One" Case 2 varText = varText & " Two" Case 3 varText = varText & " Three" Case 4 varText = varText & " Four" Case 5 varText = varText & " Five" Case 6 varText = varText & " Six" Case 7 varText = varText & " Seven" Case 8 varText = varText & " Eight" Case Else varText = varText & " Nine" End Select Me.Label1.Caption = varInt Me.Label2.Caption = varText End Sub
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote