110 likes | 230 Views
13 – Control Arrays & Container Controls. Assignment. Object naming conventions: txt – text box btn – command button pic – picture box Appropriate use of: indentation remarks constants (no magic numbers) variables (module level, and local) procedures/functions arrays structures
E N D
Assignment • Object naming conventions: txt – text box btn – command button pic – picture box • Appropriate use of: • indentation • remarks • constants (no magic numbers) • variables (module level, and local) • procedures/functions • arrays • structures • enumerate data types
Project Files • Ensure that you submit: • project file (*.vbp) • all form files (*.frm, and *.frx) • all module files (*.bas)
Session Aims & Objectives • Aims • To introduce the idea of control arrays • To introduce the idea of container controls • Objectives,by end of this week’s sessions, you should be able to: • Create and use a control array • Create and use a container control
Control Arrays • Several controls have same name • Distinguished by unique index • Very similar to a variable array • Makes it easier to do same thing to all controls – using for loop
Example: Ships - UI • Four controls share same name (picMain): picMain(1) picMain(0) picMain(2) picMain(3) lblMooringID
Example: Ships - Code Option Explicit Sub Draw() Dim i As Long For i = 0 To 3 picMain(i).DrawWidth = 3 picMain(i).Line (1000, 1000)-(2000, 1000) picMain(i).Line -Step(-200, 200) picMain(i).Line -Step(-600, 0) picMain(i).Line -Step(-200, -200) Next End Sub Private Sub picMain_Click(Index As Integer) lblMooringID.Caption = Index Draw End Sub
Control Arrays - How • To create a control array, either: • Create a control with the same name as an existing control (VB will ask you if you want to create a control array) Or: • Create a control and type a value into its index property (e.g. 0)
Container Controls • Some controls can contain other controls: • Picture boxes • Frames • The container (parent) control clips the contained (child) controls • The child controls will not be displayed outside the boundary of their parent
Example – Pic Container • The inner picture box is clipped: picOuter picInner