我有一个应用程序,您需要在英语和西班牙语之间切换。
这些按钮效果很好,但是当我点击存储特定食品的按钮并且出现错误的语言时,我遇到了一个问题。它不会在语言之间翻转并坚持使用。
我知道你必须修改AddToList()
程序,但我肯定会被卡住。
Public Class Form1
Structure MenuItem
Dim itemName As String
Dim price As Decimal
End Structure
Dim English As Boolean = False
Const MAX_FOOD_ITEMS As Integer = 9 'number of items on interface
'Processes orders by showing selected items in a list and maintaining a current total
'
'post: A total price has been displayed and selected items have been displayed
'in a list if menu items were selected. The list has been cleared and the
'price has been cleared if the New Order button was clicked.
'
Private Sub ProcessOrder(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewOrder.Click, btnItem0.Click, btnItem1.Click, btnItem2.Click,
btnItem3.Click, btnItem4.Click, btnItem5.Click, btnItem6.Click, btnItem7.Click, btnItem8.Click
Static lucyMenu(MAX_FOOD_ITEMS) As MenuItem
Static totalPrice As Decimal
Dim menuItem As Integer
Dim btnButtonClicked As Button = sender
Select Case btnButtonClicked.Tag
Case "NewOrder"
'Load menu items and display on buttons
If English = False Then
Call EnglishMenu(lucyMenu)
Call LoadButtons(lucyMenu)
ElseIf English = True Then
Call SpanishLoadMenu(lucyMenu)
Call LoadButtons(lucyMenu)
End If
'Initialize price and clear total from interface
totalPrice = 0
Me.lblTotal.Text = Nothing
'Clear list of existing items and show list
Me.lstItemsOrdered.Items.Clear()
Me.lstItemsOrdered.Visible = True
Case Else
menuItem = Val(btnButtonClicked.Tag)
Call AddToList(lucyMenu(menuItem), Me.lstItemsOrdered)
totalPrice += lucyMenu(menuItem).price
Call ShowTotal(totalPrice, Me.lblTotal)
End Select
End Sub
'Stores item names and prices in Menu() array.
'
'post: Menu item names and prices have been stored in an array.
'
Sub SpanishLoadMenu(ByRef Spanishmenu() As MenuItem)
Spanishmenu(0).itemName = "Arroz con Pollo"
Spanishmenu(0).price = 9.95
Spanishmenu(1).itemName = "Ropa Vieja"
Spanishmenu(1).price = 9.95
Spanishmenu(2).itemName = "Masitas"
Spanishmenu(2).price = 8.95
Spanishmenu(3).itemName = "Cuban Sandwich"
Spanishmenu(3).price = 6.95
Spanishmenu(4).itemName = "Moros"
Spanishmenu(4).price = 2.75
Spanishmenu(5).itemName = "Yuca"
Spanishmenu(5).price = 2.75
Spanishmenu(6).itemName = "Cafe con Leche"
Spanishmenu(6).price = 1.75
Spanishmenu(7).itemName = "Flan"
Spanishmenu(7).price = 2.5
Spanishmenu(8).itemName = "Pudin de Pan"
Spanishmenu(8).price = 2.95
End Sub
'Displays menu item names on interface
'
'post: Menu item names have been displayed on buttons.
'
Sub LoadButtons(ByRef menu() As MenuItem)
Me.btnItem0.Text = menu(0).itemName
Me.btnItem0.Visible = True
Me.btnItem1.Text = menu(1).itemName
Me.btnItem1.Visible = True
Me.btnItem2.Text = menu(2).itemName
Me.btnItem2.Visible = True
Me.btnItem3.Text = menu(3).itemName
Me.btnItem3.Visible = True
Me.btnItem4.Text = menu(4).itemName
Me.btnItem4.Visible = True
Me.btnItem5.Text = menu(5).itemName
Me.btnItem5.Visible = True
Me.btnItem6.Text = menu(6).itemName
Me.btnItem6.Visible = True
Me.btnItem7.Text = menu(7).itemName
Me.btnItem7.Visible = True
Me.btnItem8.Text = menu(8).itemName
Me.btnItem8.Visible = True
End Sub
'Adds selected menu item to a list
'
'post: Selected menu item and price have been added to list
'
Sub AddToList(ByVal item As MenuItem, ByRef lstOrderList As ListBox)
lstOrderList.Items.Add(item.itemName & vbTab & Format(item.price, "Currency"))
End Sub
'Displays a total price for the current order in a label
'
'post: A price has been displayed in a label.
'
Sub ShowTotal(ByVal amount As Decimal, ByRef lblAmount As Label)
lblAmount.Text = "Total:" & Format(amount, "Currency")
End Sub
Sub EnglishMenu(ByRef menuEnglish() As MenuItem)
menuEnglish(0).itemName = "Chicken and Yellow rice"
menuEnglish(0).price = 9.95
menuEnglish(1).itemName = "Shredded Beef"
menuEnglish(1).price = 9.95
menuEnglish(2).itemName = "Pork and Plantains"
menuEnglish(2).price = 8.95
menuEnglish(3).itemName = "Cuban Bread with Meat and Cheese"
menuEnglish(3).price = 6.95
menuEnglish(4).itemName = "Black Bean and Rice"
menuEnglish(4).price = 2.75
menuEnglish(5).itemName = "Cassava"
menuEnglish(5).price = 2.75
menuEnglish(6).itemName = "Coffee with milk"
menuEnglish(6).price = 1.75
menuEnglish(7).itemName = "Baked Custard"
menuEnglish(7).price = 2.5
menuEnglish(8).itemName = "Bread Pudding"
menuEnglish(8).price = 2.95
End Sub
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnglish.Click
Static lucyMenu(MAX_FOOD_ITEMS) As MenuItem
If English = False Then
Me.btnEnglish.Text = "Spanish"
Call EnglishMenu(lucyMenu)
Call LoadButtons(lucyMenu)
English = True
ElseIf English = True Then
Me.btnEnglish.Text = "English"
Call SpanishLoadMenu(lucyMenu)
Call LoadButtons(lucyMenu)
English = False
End If
End Sub
End Class