是不是该建立起一个什么变量什么的 不懂啊
请指教
Option Explicit Public Type 货物类型 名称 As String 价格 As Single 会员价 As Single 选择 As Boolean End Type Public 货物(1 To 12) As 货物类型 Const 货物文件名 = "货物.txt" Public Path As String Public Sub init() Path = App.Path If Right(Path, 1) <> "\" Then Path = Path & "\" End If Dim fr As Long fr = FreeFile Dim i As Long Dim fj() As String Dim s As String i = 0 Open Path & 货物文件名 For Input As #fr Do While Not EOF(fr) Line Input #fr, s '读一行 s = Trim(s) '去掉空格 If Len(s) > 0 Then '如果不为空行 If Left(s, 1) <> ";" Then '如果不是分号,分号做为注释用 If InStr(1, s, ",") > 0 Then '如果最少可以分为二段 fj = Split(s, ",") i = i + 1 '数据有效,计数 + 1 With 货物(i) .名称 = fj(0) .价格 = CSng(fj(1)) If UBound(fj) > 1 Then '存在第三段,会员价 .会员价 = CSng(fj(2)) Else .会员价 = Int(.价格 * 0.85) End If End With End If End If End If If i = 12 Then Exit Do Loop Close #fr End Sub Public Sub main() '该函数是本程序的第一个执行的过程 Call init '程序初始化 Load Form1 '载入窗体1 Form1.Show '显示窗体1 End Sub
Option Explicit Private Sub Command1_Click() Dim i As Long For i = 0 To 11 If Check1(i).Value = 1 Then '如果选择了 货物(i + 1).选择 = True '则设置为选择了 Else 货物(i + 1).选择 = False '否则设置为没选择。因为清选择时,没清这个位置,所以这里必须要给否 End If Next i Load Form2 '加载窗体 Form2.Show '显示 End Sub Private Sub Command2_Click() Call 清除选择 '调用清除选择,如果窗体外调用就是 call form1.清除选择 End Sub Private Sub Form_Load() Dim i As Long For i = 0 To 11 '显示每个的内容 Check1(i).Caption = "¥" & Format(货物(i + 1).价格, "0.00") & " " & 货物(i + 1).名称 Next i End Sub Public Sub 清除选择() Dim i As Long For i = 0 To 11 Check1(i).Value = 0 '设置为不选择 Next i End Sub
Option Explicit Private Sub Form_Load() Dim s As String Dim i As Long Dim zj1 As Single Dim zj2 As Single s = "选择了:" '第一行 For i = 1 To 12 '所有的货物 With 货物(i) If .选择 Then '如果选择了 s = s & vbCrLf & .名称 & " 价格¥" & .价格 & " 会员价:¥" & .会员价 '组合成显示部分 zj1 = zj1 + .价格 '计算普通价合计 zj2 = zj2 + .会员价 '计算会员价合计 End If End With Next i Text1.Text = s '显示 Text2.Text = zj1 Text3.Text = zj2 End Sub Private Sub Form_Unload(Cancel As Integer) '退出时,自动清 选择 Call Form1.清除选择 End Sub