標題:
[發問]
在表單如何建立物件的矩陣
[打印本頁]
作者:
mobo
時間:
2012-12-21 10:53
標題:
在表單如何建立物件的矩陣
請問各位大大,
我在表單設計上,如何建立物件的矩陣呢?
如 : 我需要建立 10 個 TextBox ,如何讓這10個TextBox 變成矩陣,以方便讀寫
感謝
作者:
kimbal
時間:
2012-12-22 10:58
回復
1#
mobo
你的意思是否這樣?
[attach]13651[/attach]
效果 (按其中一button)
[attach]13652[/attach]
Private Sub CommandButton1_Click()
For i = 0 To 9
If TypeName(Me.Controls(i)) = "TextBox" Then
Me.Controls(i) = i + 1
End If
Next
End Sub
Private Sub CommandButton2_Click()
For i = 1 To 10
Me.Controls("textbox" & Trim(Str(i))) = i
Next
End Sub
複製代碼
作者:
GBKEE
時間:
2012-12-22 13:17
本帖最後由 GBKEE 於 2012-12-22 13:58 編輯
回復
1#
mobo
Option Explicit
Dim Ar()
Private Sub CommandButton1_Click()
Dim E As Variant, i As Integer
[A1].Resize(, UBound(Ar) + 1) = Ar
For i = 1 To UBound(Ar) + 1
Cells(2, i) = Ar(i - 1)
Next
End Sub
Private Sub UserForm_Initialize()
Dim E As MSForms.Control, i As Integer
For Each E In Controls
If TypeName(E) = "TextBox" Then
ReDim Preserve Ar(i)
Set Ar(i) = E
i = i + 1
End If
Next
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)