VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A clean way to add control arrays at runtime

by Trey Smith (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

This code, will add elements to a control array element at runtime. This is very easy to do, as a control array is actually a collection and gives us a count.

Assumes
First off, make SURE you do this trick to VB. copy your control on the form, answer YES to create a control array, delete the new instance. Otherwise the control is not a collection.
Side Effects
New control is EXACTLY where the orginal was.

Rate A clean way to add control arrays at runtime

'Load an new instance of myControl 
'the index is the count, thus making it one
'greater than the prior index as index is 0 based
'and count starts at 1
Load pbVI(pbVI.Count)
'Count is now 1 greater so to address the control 
'you just created reference count -1
With pbVI(pbVI.Count - 1)
'.Left = 100
'.Top = 600
'.Visible = True
End With

Download this snippet    Add to My Saved Code

A clean way to add control arrays at runtime Comments

No comments have been posted about A clean way to add control arrays at runtime. Why not be the first to post a comment about A clean way to add control arrays at runtime.

Post your comment

Subject:
Message:
0/1000 characters