本帖最后由 bcrun 于 2012-06-21 10:01:42 编辑

解决方案 »

  1.   

    我感觉貌似是错在Str(jg(List2.ListIndex))这个上面了谁能帮帮我
      

  2.   

    检查jg这个数组的索引,在出错的时候点击调试,然后点击下jg光标停留在jg上右击选择监视,看看这个数组的情况。
      

  3.   

    Str(jg(List2.ListIndex))需要读的是与Form2.List2.List(I)相对应的值,那么这种写法对是不对?
      

  4.   

    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
      

  5.   

    本帖最后由 bcrun 于 2012-06-21 09:57:24 编辑
      

  6.   

    你的程序架构可能要有一点点小的变动: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
      

  7.   

    楼主贴的代码里面少了点菜过程——即list2怎么来的,你贴出来大家看下就知道了
      

  8.   

    本帖最后由 bcrun 于 2012-06-21 09:56:31 编辑
      

  9.   

    如果你还是没有单步调试,或者单步调试了却没有发现问题,
    不如把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))插入的语句如果没有问题,那么组合起来应该没有问题了,除非你拼写错误了