Re: can't load a textbox array at runtime
- From: catharinus <csvanderwerf@xxxxxxxxx>
- Date: Thu, 30 Jul 2009 01:07:58 -0700 (PDT)
On 30 jul, 02:39, "Schmidt" <s...@xxxxxxxxx> wrote:
"catharinus" <csvanderw...@xxxxxxxxx> schrieb im Newsbeitragnews:a5d852ce-bd10-4e6a-ad8d-399f788f0273@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 29 jul, 14:27, "Jim Mack" <jm...@xxxxxxxxxxxxxxx> wrote:
no, I want to use this method witout the textbox on the form, ...
Then you will need a bit of "class-vodoo" -
take a look at the following...:
'***first you will need a small class-wrapper for each of the TextBoxes:
'***(name of the class: cTBWrap) ... to receive the TB-Events
Option Explicit
Private mParentArr As cTBArray 'store a ref to the parent-array
Private WithEvents mTB As TextBox
Private mIndex As Long
Friend Sub Init(ParentArr As cTBArray, _
TB As TextBox, ByVal Index As Long)
Set mParentArr = ParentArr
Set mTB = TB
mIndex = Index
End Sub
Public Property Get TB() As TextBox
Set TB = mTB
End Property
Private Sub mTB_Change()
mParentArr.RaiseChange mIndex
End Sub
Private Sub mTB_Validate(Cancel As Boolean)
mParentArr.RaiseValidate mIndex, Cancel
End Sub
Private Sub Class_Terminate()
If mTB Is Nothing Then Exit Sub
mTB.Parent.Controls.Remove "TBArr_" & mIndex
End Sub
'***then you will need an "Array-Class" for the above instances
'***of cTBWrap - name this Array-Class: cTBArray
Option Explicit
'redefine Array-Events as needed here (in our case for the TextBox)
'always with a leading Index-Param (the rest of params as in orig.)
Event Change(ByVal Index As Long)
Event Validate(ByVal Index As Long, Cancel As Boolean)
Private mCol As Collection
Private Sub Class_Initialize()
Set mCol = New Collection
End Sub
Public Sub Add(F As Form, ByVal Index As Long, Left, _
Optional Top, Optional Width, Optional Height)
Dim TB As TextBox, NewTBWrap As cTBWrap
Set TB = F.Controls.Add("VB.TextBox", "TBArr_" & Index)
TB.Visible = True
TB.Move Left, Top, Width, Height
Set NewTBWrap = New cTBWrap
NewTBWrap.Init Me, TB, Index
mCol.Add NewTBWrap, CStr(Index)
End Sub
Public Property Get Item(ByVal Index As Long) As TextBox
Set Item = mCol(CStr(Index)).TB
End Property
Public Sub Remove(ByVal Index As Long)
mCol.Remove CStr(Index)
End Sub
Public Sub RemoveAll()
Set mCol = New Collection
End Sub
'and here the centralized Event-Delegation in appropriate Subs
Friend Sub RaiseChange(ByVal Index As Long)
RaiseEvent Change(Index)
End Sub
Friend Sub RaiseValidate(ByVal Index As Long, Cancel As Boolean)
RaiseEvent Validate(Index, Cancel)
End Sub
'***and finally some Test-Code into a Form:
Option Explicit
Private WithEvents TBArray As cTBArray
Private Sub Form_Load()
Dim i&
Me.ScaleMode = vbTwips
Set TBArray = New cTBArray
For i = 0 To 9
TBArray.Add Me, i, i * 900, 0, 900
Next i
End Sub
Private Sub Form_Click()
TBArray.Remove 1 'just a small remove-test...
MsgBox "TB(1) was removed..."
TBArray.Add Me, 1, 900, 0, 900 '..followed by a re-add
MsgBox "...and now readded."
End Sub
'here we handle the Array-Events
Private Sub TBArray_Change(ByVal Index As Long)
Caption = "TB(" & Index & "): " & TBArray.Item(Index).Text
End Sub
Private Sub TBArray_Validate(ByVal Index As Long, Cancel As Boolean)
Caption = "TB(" & Index & "): Validate-Event"
End Sub
Private Sub Form_Unload(Cancel As Integer)
TBArray.RemoveAll 'make sure, to call that on Form-Unload
End Sub
Olaf
OKE Olof, very, very nice. That's it. I needed other events as well,
they can easily be inserted.
Thanks
Catharinus van der Werf
csvanderwerf@xxxxxxxxx
.
- Follow-Ups:
- Re: can't load a textbox array at runtime
- From: Ralph
- Re: can't load a textbox array at runtime
- From: Mark
- Re: can't load a textbox array at runtime
- References:
- can't load a textbox array at runtime
- From: catharinus
- Re: can't load a textbox array at runtime
- From: Jim Mack
- Re: can't load a textbox array at runtime
- From: catharinus
- Re: can't load a textbox array at runtime
- From: Jim Mack
- Re: can't load a textbox array at runtime
- From: catharinus
- Re: can't load a textbox array at runtime
- From: Schmidt
- can't load a textbox array at runtime
- Prev by Date: Re: Why does vb 6 seem to be getting more expensive?
- Next by Date: Re: It's finally here! midistreamingv104.zip with full VB6 source code
- Previous by thread: Re: can't load a textbox array at runtime
- Next by thread: Re: can't load a textbox array at runtime
- Index(es):
Relevant Pages
|