jg 的成员数是否大于等于 List2 的列表数,另外,它的 Index 是否基于 0?还有 jg 存的是什么东西?如果用 Long 型数可以表示,就用不着了,可以将这些内容保存在 List2 的 ItemData 中。List2.AddItem strOrder List2.ItemData(List2.NewIndex) = Int(jg * 100)Form3.Print "已点菜清单", "价格" For I = 0 To List2.ListCount - 1 Form3.Print List2.List(I), List2.ItemData(I)/100 Next I Form3.Print "-------------------" Form3.Print "合计", Text1.Text
本帖最后由 bcrun 于 2012-06-21 09:57:24 编辑
你的程序架构可能要有一点点小的变动:1 首先将一个菜单及价格表导入一个 ListBox:Private Sub Form_Load() Dim fileno As Integer, strLine As String, strItem() As String fileno = FreeFile Open App.Path & "\菜单.txt" For Input As #fileno Do While Not EOF(fileno) Input #fileno, strLine strItem = Split(strLine, ",") If Ubound(strItem) = 1 Then List1.AddItem Replace(strItem(0), """, "") '保存菜品 List1.ItemData(List1.NewIndex) = strItem(1) '保存价格 End If Loop Close #fileno End Sub2 点菜时,将菜品和价格同时复制过去List2.AddItem List1.List(List1.ListIndex) List2.ItemData = List1.ItemData(List1.ListIndex)3 结算时直接从点菜清单的 ListBox 中取得菜品和价格Private Sub Command5_Click() Dim sum As Long Form3.Show Form3.Print "已点菜清单", "价格" sum = 0 For I = 0 To List2.ListCount - 1 Form3.Print Form2.List2.List(I), Form2.List2.ItemData(I) sum = sum + Form2.List2.ItemData(I) Next I Form3.Print "-------------------" Form3.Print "合计", sum End Sub
List2.ItemData(List2.NewIndex) = Int(jg * 100)Form3.Print "已点菜清单", "价格"
For I = 0 To List2.ListCount - 1
Form3.Print List2.List(I), List2.ItemData(I)/100
Next I
Form3.Print "-------------------"
Form3.Print "合计", Text1.Text
Dim fileno As Integer, strLine As String, strItem() As String
fileno = FreeFile
Open App.Path & "\菜单.txt" For Input As #fileno
Do While Not EOF(fileno)
Input #fileno, strLine
strItem = Split(strLine, ",")
If Ubound(strItem) = 1 Then
List1.AddItem Replace(strItem(0), """, "") '保存菜品
List1.ItemData(List1.NewIndex) = strItem(1) '保存价格
End If
Loop
Close #fileno
End Sub2 点菜时,将菜品和价格同时复制过去List2.AddItem List1.List(List1.ListIndex)
List2.ItemData = List1.ItemData(List1.ListIndex)3 结算时直接从点菜清单的 ListBox 中取得菜品和价格Private Sub Command5_Click()
Dim sum As Long
Form3.Show
Form3.Print "已点菜清单", "价格"
sum = 0
For I = 0 To List2.ListCount - 1
Form3.Print Form2.List2.List(I), Form2.List2.ItemData(I)
sum = sum + Form2.List2.ItemData(I)
Next I
Form3.Print "-------------------"
Form3.Print "合计", sum
End Sub
不如把Form3.Print Form2.List2.List(I), Str(jg(List2.ListIndex))拆成多个语句来执行Form3.Print Form2.List2.List(I),
temp=List2.ListIndex
temp=jg(List2.ListIndex)
temp=Str(jg(List2.ListIndex))
Form3.Print Str(jg(List2.ListIndex))插入的语句如果没有问题,那么组合起来应该没有问题了,除非你拼写错误了