vb问题请问怎么做!!十分感谢
先翻译一下:
实验5 子过程,函数,循环和结构
一个零售店有5个柜台,标记为1-5,每个柜台含有一种不同的日用品。在一天的开水,每个柜台里有45件货物,下面表格显示出了每种货物的价格,和那天出售的件数。
写一个程序:
(a)把每个物品的价格和售出件数放入一个结构体数组
(b)显示一个存货表格,和每个柜台的收入
(c)计算总收入
(d)列出一天结束时存货小雨20件的柜台中的存货数
表格:
柜台 每件货物价格 售出件数
整体程序
Private Type list
cost As Currency
sold As Integer
End Type '结构体数组定义
Dim arr(5) As list
Private Sub Command1_Click() '(b)输出存货表格和收入
Dim s As String
s = "Bin" + vbTab + "Cost per Item" + vbTab + "Quantity sold" + vbCrLf
For i = 1 To 5
s = s + CStr(i) + vbTab + Format(CStr(arr(i).cost), "#0.00") + vbTab + vbTab + CStr(arr(i).sold) + vbCrLf
Next
MsgBox s
End Sub
Private Sub Command2_Click() '(c)计算总收入
Dim total As Long
For i = 1 To 5
total = total + arr(i).cost * arr(i).sold
Next
MsgBox CStr(total)
End Sub
Private Sub Command3_Click() '(d)列出存货小于20的柜台存货数
Dim s As String
s = "Bin" + vbTab + "Cost per Item" + vbTab + "Contains left" + vbCrLf
For i = 1 To 5
If arr(i).sold > 25 Then
s = s + CStr(i) + vbTab + Format(CStr(arr(i).cost), "#0.00") + vbTab + vbTab + CStr(45 - arr(i).sold) + vbCrLf
End If
Next
MsgBox s
End Sub
Private Sub Form_Load() '(a)存入结构体数组
arr(1).cost = 3#
arr(1).sold = 10
arr(2).cost = 12.25
arr(2).sold = 30
arr(3).cost = 37.45
arr(3).sold = 9
arr(4).cost = 7.49
arr(4).sold = 42
arr(5).cost = 24.95
arr(5).sold = 17
End Sub
窗体图比较简单,也附上吧
欢迎追问