# Re: 为什么程式跑出来不正确呢?可否帮我看看?Why?

Posted by 战豪 on July 12, 1999 at 07:15:12:

In Reply to: Re: 为什么程式跑出来不正确呢?可否帮我看看?Why? posted by 阿太 on July 11, 1999 at 11:45:51:

'噢!原来是这样,是动态的载入物件矩阵!很简单啰(但也花了我差不多30分锺去实作...真差劲...),看看以下的Coding是否适用?
'表单上有一List1的物件,Index为1,Visible为True,Width=1000,Height=600
'Button物件名为cmdAdd,两个TextBox物件分别为Text1及Text2
'建议你加入栏位及列位数量的检查,否则来个200烂400列.....真不敢想像.....
'另外,最好在Form_Unload事件中,也呼叫ClearAddedObject程序,以交回程式所耗用之记忆体资源!!!

Private Sub cmdAdd_Click()
Dim a As Integer, b As Integer, obj As Integer 'a=栏位数;b=列行数,obj=载入List1物件数
Dim row As Integer, col As Integer '存放物件.Left及.Top之变数
Dim i As Integer, j As Integer '计算器

If IsNumeric(Text1) And IsNumeric(Text2) Then '检查输入TextBox物件内容为数值否
a = Text1: b = Text2
Else
MsgBox "请输入数值以供测试!"
Exit Sub
End If
ClearAddedObject '在重新载入物件前,先清除已载入之ListBox物件

obj = 1: col = List1(1).Left: row = List1(1).Top '初始化各项变数
For i = 1 To a
For j = 1 To b
If obj = 1 Then
List1(obj).AddItem i & vbTab & j '因第一个ListBox为可见物件,所以无需加以处理,直接于此执行各内容及设定
Else
Load List1(obj) '开始载入第二个ListBox物件
With List1(obj)
If obj = ((i - 1) * a) + 1 Then '检查是否需要起始另一新列
col = List1(1).Left
row = row + 600
Else
col = col + 1000
End If
.Move col, row '将新载入之ListBox物件放到应当出现的地方
.AddItem i & vbTab & j '处理ListBox物件内容
.Visible = True
End With
End If
obj = obj + 1 '设定下一个物件变数
Next j
Next i
End Sub

Private Sub ClearAddedObject()
If List1.Count > 1 Then
For i = 2 To List1.Count
Unload List1(i)
Next i
End If
List1(1).Clear '清除旧有List1内容
End Sub

Follow Ups:

- 谢谢你,战豪兄 阿太 08:30:44 7/14/99 (0)