Als Antwort auf diesen Beitrag
Hi,
mit Array ~
Modul:
Option Explicit
'Control-Variablen müssen Public sein, wenn sie für die Dauer der Ausführung gelten sollen
'Option Private Module
Public t() As clsTextbox
Public lngTnr As Long
Public Function newControl(ByRef pvobjParent As Object, ByVal pvstrNamen As String, ByVal pvstrType As String, _
Optional ByVal pvsngLeft, Optional ByVal pvsngTop, Optional ByVal pvsngHeight, Optional ByVal pvsngWidth, _
Optional ByVal pvintSFX, Optional ByVal pvintBorderStyle, Optional ByVal pvlngHGFarbe, Optional ByVal pvlngVGFarbe, Optional ByVal pvstrCaption) As Control
Set newControl = pvobjParent.Controls.Add("Forms." & pvstrType & ".1", pvstrNamen, True)
Set t(lngTnr) = New clsTextbox
With newControl
Set t(lngTnr).TxtBox = newControl
If Not IsMissing(pvsngLeft) Then .Left = pvsngLeft
If Not IsMissing(pvsngTop) Then .Top = pvsngTop
If Not IsMissing(pvsngHeight) Then .Height = pvsngHeight
If Not IsMissing(pvsngWidth) Then .Width = pvsngWidth
If Not IsMissing(pvintSFX) Then .SpecialEffect = pvintSFX
If Not IsMissing(pvintBorderStyle) Then .BorderStyle = pvintBorderStyle
If Not IsMissing(pvlngHGFarbe) Then .BackColor = pvlngHGFarbe
If Not IsMissing(pvlngVGFarbe) Then .ForeColor = pvlngVGFarbe
If Not IsMissing(pvstrCaption) Then
On Error Resume Next
.Caption = pvstrCaption
.Text = pvstrCaption
On Error GoTo 0
End If
End With
'Aktuelle Box hochzählen
lngTnr = lngTnr + 1
'
End Function
Userform:
Option Explicit
Private Sub UserForm_Initialize()
'Beispielwerte, ersetzen hier den jeweiligen .Count der Datenklassen:
Const mRows = 3
Const mCols = 3
With Me
.Height = mRows * 20 + 40
.Width = mCols * 60 + 20
.StartUpPosition = 0
.Caption = "GridEditor"
End With
'Aktuelle Box initialisieren
lngTnr = 0
'Anzahl Boxen
ReDim t((mRows * mCols) - 1)
Call fillTbGrid(mRows, mCols)
End Sub
Private Sub fillTbGrid(mRows As Long, mCols As Long)
Dim X As Long, Y As Long
For X = 1 To mRows
For Y = 1 To mCols
Call newControl(Me, "Tb" & CStr(X) & "-" & CStr(Y), _
"TextBox", (Y * 60 - 60), (X * 20 - 20), 23, 63, , 1)
Next Y
Next X
End Sub
Klasse:
Option Explicit
Public WithEvents TxtBox As MSForms.TextBox
Private Sub TxtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
' Select Case TxtBox.Name
' Case "Tb1-1"
'
' Case "Tb3-1"
' '.....
' End Select
MsgBox Me.TxtBox.Name
End Sub
hth
Ulf