手头上没VB,请帮忙:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command3 
      Caption         =   "结束"
      Height          =   495
      Left            =   3240
      TabIndex        =   6
      Top             =   2520
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "选非零元素"
      Height          =   495
      Left            =   1680
      TabIndex        =   5
      Top             =   2520
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "生成数组"
      Height          =   495
      Left            =   240
      TabIndex        =   4
      Top             =   2520
      Width           =   1215
   End
   Begin VB.ListBox List1 
      Height          =   1500
      ItemData        =   "Form93.frx":0000
      Left            =   2400
      List            =   "Form93.frx":0007
      TabIndex        =   3
      Top             =   840
      Width           =   2055
   End
   Begin VB.PictureBox Picture1 
      Height          =   1455
      Left            =   240
      ScaleHeight     =   1395
      ScaleWidth      =   1395
      TabIndex        =   1
      Top             =   840
      Width           =   1455
   End
   Begin VB.Label Label2 
      Caption         =   "非零元素位置"
      Height          =   255
      Left            =   2520
      TabIndex        =   2
      Top             =   360
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "数组:"
      Height          =   255
      Left            =   360
      TabIndex        =   0
      Top             =   360
      Width           =   735
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim i As Integer, j As Integer
Dim a(3, 4) As Integer
 Private Sub Command1_Click()
    For i = 1 To 3
        For j = 1 To 4
            a(i, j) = Int(10 * Rnd)
            Picture1.Print a(i, j);
        Next j
        Picture1.Print
    Next i
End SubPrivate Sub Command2_Click()
    For i = 1 To 3
        For j = 1 To 4
            List1.AddItem a(i, j) & "      " & i & "      " & j & "      "
        Next j
    Next i
End SubPrivate Sub Command3_Click()
    End
End Sub

解决方案 »

  1.   

    Private Sub Command2_Click()
        For i = 1 To 3
            For j = 1 To 4
                If a(i, j) > 0 Then List1.AddItem a(i, j) & "      " & i & "      " & j & "      "
            Next j
        Next i
    End Sub
      

  2.   


    Private Sub Command2_Click()
        For i = 1 To 3
            For j = 1 To 4
                If a(i, j) > 0 Then
                    List1.AddItem a(i, j) & "      " & i & "      " & j & "      "
                End If
            Next j
        Next i
    End Sub