大家好,Stackflow社区,我正在上Visual Basic的一门课,我需要一些帮助。我正在创建一个使用数组模拟饮料自动售货机的程序。说明如下:创建一个模拟软饮料自动售货机的应用程序。应用程序应该让用户选择以下软饮料之一:
可乐(1.00美元一瓶),根啤酒(1.00美元一瓶),柠檬酸橙苏打水(1.00美元一瓶),葡萄汽水(1.50美元一杯),奶油苏打水(1.50美元一杯)
当应用程序启动时,自动售货机将拥有每种类型的20种软饮料。每次用户选择饮料时,应用程序应从所选饮料的数量中减去1。它还应该更新和显示销售总额。如果用户选择的饮料已售罄,则应显示一条消息,指示已售罄。
在应用程序的代码中,创建一个包含以下数据字段的结构:
饮品名称饮品成本机器饮品数量
程序应该创建一个包含五个structure对象的数组。数组的每个元素都应该保存特定类型的软饮料的数据。
我不知道如何让我的按钮减少数量标签,然后将每次点击添加到标签总数中。请帮帮忙。
Public Class Form1
' Class-level declarations
Const intMAX_SUBSCRIPT As Integer = 4 ' Upper subscript
Dim strProdNames(intMAX_SUBSCRIPT) As String ' Product Names
Dim decPrice(intMAX_SUBSCRIPT) As Decimal ' Drink Price
Dim intProdNums(intMAX_SUBSCRIPT) As Integer ' Product Numbers
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Initialize the arrays with the product data.
InitArrays()
End Sub
Private Sub InitArrays()
' Initialize the arrays.
' First Product
strProdNames(0) = "Cola"
decPrice(0) = 1D
intProdNums(0) = 20
' Second Product
strProdNames(1) = "Root Beer"
decPrice(1) = 1D
intProdNums(1) = 20
' Third Product
strProdNames(2) = "Lemon Lime"
decPrice(2) = 1D
intProdNums(2) = 20
' Fourth Product
strProdNames(3) = "Grape Soda"
decPrice(3) = 1.5D
intProdNums(3) = 20
' Fifth Product
strProdNames(4) = "Cream Soda"
decPrice(4) = 1.5D
intProdNums(4) = 20
End Sub
Private Sub btnCola_Click(sender As Object, e As EventArgs) Handles btnCola.Click
Dim intCount As Integer = 20 ' Loop Counter
intCount -= 1 ' Decrement drink count
If intCount > 0 Then
lblTotal.Text = decPrice(0).ToString("c")
End If
End Sub发布于 2017-04-01 01:38:44
您需要递减数组中的cola计数。
Private Sub btnCola_Click(sender As Object, e As EventArgs)
If intProdNums(0) > 0 Then
intProdNums(0)-=1 ' decrement cola drink count
End If
' show results here...
End Subhttps://stackoverflow.com/questions/43129713
复制相似问题