Asked by Lee
This is a visual basics program issue.
The problem is: Table 4.7 contains information on several states. Write a program that requests a state and category (flower, motto and nickname) as input and displays the requested information. If the state or category requested is not in the table, the program should so inform the user.
Table 4.7 State, Flower, Nickname, and Motto
State
Flower
Nickname
Motto
California
Golden Poppy
Golden State
Eureka
Indiana
Peony
Hoosier State
Crossroads of America
Mississippi
Magnolia
Magnolia State
By valor of arms
New York
Rose
Empire State
Ever upward
This is the program I created. It only displays the very last line of the program:
Public Class Ch04_3_32A
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
'Display state and category
Dim state As String
Dim category As String
state = (InputBox("Enter a state", "A State"))
category = (InputBox("Enter a category", "A Category"))
Select Case state.ToUpper
Case "CALIFORNIA"
Select Case category.ToUpper
Case "FLOWER"
txtOutput.Text = "Gold Poppy"
Case "NICKNAME"
txtOutput.Text = "Golden State"
Case "MOTTO"
txtOutput.Text = "Eureka"
End Select
End Select
Select Case state.ToUpper
Case "INDIANA"
Select Case category.ToUpper
Case ("FLOWER")
txtOutput.Text = "Peony"
Case ("NICKNAME")
txtOutput.Text = "Hoosier State"
Case ("MOTTO")
txtOutput.Text = "Crossroads to America"
End Select
End Select
Select Case state.ToUpper
Case "MISSISSIPPI"
Select Case category.ToUpper
Case "FLOWER"
txtOutput.Text = "Magnolia"
Case "NICKNAME"
txtOutput.Text = "Magnolia State"
Case "MOTTO"
txtOutput.Text = "By valor and arms"
End Select
End Select
Select Case state.ToUpper
Case "NEW YORK"
Select Case category.ToUpper
Case "FLOWER"
txtOutput.Text = "Rose"
Case "NICKNAME"
txtOutput.Text = "Empire State"
Case "MOTTO"
txtOutput.Text = "Ever Upward"
End Select
End Select
If state <> "" Then
txtOutput.Text = "Category is not listed"
End If
End Sub
End Class
The problem is: Table 4.7 contains information on several states. Write a program that requests a state and category (flower, motto and nickname) as input and displays the requested information. If the state or category requested is not in the table, the program should so inform the user.
Table 4.7 State, Flower, Nickname, and Motto
State
Flower
Nickname
Motto
California
Golden Poppy
Golden State
Eureka
Indiana
Peony
Hoosier State
Crossroads of America
Mississippi
Magnolia
Magnolia State
By valor of arms
New York
Rose
Empire State
Ever upward
This is the program I created. It only displays the very last line of the program:
Public Class Ch04_3_32A
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
'Display state and category
Dim state As String
Dim category As String
state = (InputBox("Enter a state", "A State"))
category = (InputBox("Enter a category", "A Category"))
Select Case state.ToUpper
Case "CALIFORNIA"
Select Case category.ToUpper
Case "FLOWER"
txtOutput.Text = "Gold Poppy"
Case "NICKNAME"
txtOutput.Text = "Golden State"
Case "MOTTO"
txtOutput.Text = "Eureka"
End Select
End Select
Select Case state.ToUpper
Case "INDIANA"
Select Case category.ToUpper
Case ("FLOWER")
txtOutput.Text = "Peony"
Case ("NICKNAME")
txtOutput.Text = "Hoosier State"
Case ("MOTTO")
txtOutput.Text = "Crossroads to America"
End Select
End Select
Select Case state.ToUpper
Case "MISSISSIPPI"
Select Case category.ToUpper
Case "FLOWER"
txtOutput.Text = "Magnolia"
Case "NICKNAME"
txtOutput.Text = "Magnolia State"
Case "MOTTO"
txtOutput.Text = "By valor and arms"
End Select
End Select
Select Case state.ToUpper
Case "NEW YORK"
Select Case category.ToUpper
Case "FLOWER"
txtOutput.Text = "Rose"
Case "NICKNAME"
txtOutput.Text = "Empire State"
Case "MOTTO"
txtOutput.Text = "Ever Upward"
End Select
End Select
If state <> "" Then
txtOutput.Text = "Category is not listed"
End If
End Sub
End Class
Answers
Answered by
MattsRiceBowl
It's been years, so I forgot a lot. Should this:
If state <> "" Then
Say this:
If state = "" Then
I honestly forget. Let me know if that works.
If state <> "" Then
Say this:
If state = "" Then
I honestly forget. Let me know if that works.
Answered by
Lee
Thank you both. I'll give the line a try and report back...
Answered by
Lee
No I'm afraid the If statement did not work. I'm trying Case Else. But I think all my Select End and Select Case's are the cause.
Answered by
MattsRiceBowl
I'm just waking up, so really tired. I will try to look later, but it is a hard program to follow mentally. Haha
I hope someone can help. Check back again in a while.
I hope someone can help. Check back again in a while.
Answered by
Lee
So do I. This program is a little difficult. Thank you for your help...
Answered by
Helper
Declare these under form.
Dim Mott As String 'To type in which State Motto
Dim Flower As String 'To type in which State Flower
Dim NickName As String 'To type in which State NickName
First Button code.
Private Sub btnmotto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmotto.Click
Motto = CStr(InputBox("Enter a state: California, Indiana, Mississippi, North Dakota, and New York."))
Select Case Motto
Case "California"
txtinfo.Text = "California state motto is 'Eureka'."
Case "Indiana"
txtinfo.Text = "Indiana state motto is 'Crossroads of America'."
Case "Mississippi"
txtinfo.Text = "Mississippi state motto is 'By valor and arms'."
Case "New York"
txtinfo.Text = "New York state motto is 'Ever Upward'."
Case "North Dakota"
txtinfo.Text = "North Dakota state motto is 'Liberty and union, now and forever, one and inseparable'."
Case Else
txtinfo.Text = "Category is not listed."
Dim Mott As String 'To type in which State Motto
Dim Flower As String 'To type in which State Flower
Dim NickName As String 'To type in which State NickName
First Button code.
Private Sub btnmotto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmotto.Click
Motto = CStr(InputBox("Enter a state: California, Indiana, Mississippi, North Dakota, and New York."))
Select Case Motto
Case "California"
txtinfo.Text = "California state motto is 'Eureka'."
Case "Indiana"
txtinfo.Text = "Indiana state motto is 'Crossroads of America'."
Case "Mississippi"
txtinfo.Text = "Mississippi state motto is 'By valor and arms'."
Case "New York"
txtinfo.Text = "New York state motto is 'Ever Upward'."
Case "North Dakota"
txtinfo.Text = "North Dakota state motto is 'Liberty and union, now and forever, one and inseparable'."
Case Else
txtinfo.Text = "Category is not listed."
Answered by
Lee
Thank you Matt and helper. Your help was very useful. I was able to get this program operational. The misstake I seem to have made with putting nested statements in. I had to take out some of the End Selects and change my operation from <> to =.
Answered by
Kwadwo
So what is the full answer to this problem cause I am doing the same thing right now
There are no AI answers yet. The ability to request AI answers is coming soon!