Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab9 Control Array Print Method Printing VB Output
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 2 Control Array
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 3 Control Array A group of controls of the same type, Name and event procedure. Each control array element has it’s own properties. Each control array element has it’s own INDEX starting with 0.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 4 Control Array …[CONT] Creating Control Array: 1- Giving the control the same name as another control. 2- Copying the control and pasting it the same form. Control Array Methods: Count : Shows the number of controls in the array. Lbound : Shows the lower index. Ubound: Shows the upper index
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 5 Control Array …[CONT] Item: Enables accessing an individual element in the control array. Example: Private Sub Command1_Click() Print Text1.Count Print Text1.LBound Print Text1.Ubound Text1.Item(2).Text = "Ahmad" End Sub
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 6 Print Method
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 7 Placing Text on Forms Print Method: This method enables writing on forms directly. Print applies to Forms, Picturebox, Printer object… syntax: FormName.Print Text
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 8 Format with Print Spc() Function: Skip number of spaces (columns) as specified with Spc function. Example: Form1.Print Spc(10); “Hebron” This statements skips 10 spaces before printing the word “Hebron”
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 9 Tab() Function Starts printing at the specified column with the Tab function. Example: Form1.Print Tab(20); “Hebron”; Tab (30) “PPU” This statement print the word “Hebron” starting at column 20, and the word “PPU” at column 30.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 10 Notes: When the print method ends with semicolon ( ; ): The text is printed and the next text is printed directly at the same line. Form1.Print “Hebron” ; When the print method ends with comma (,): The text is printed and the next text is printed directly in the next position at the same line. When using empty print method: VB prints blank line.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 11 Positioning the Print Method Properties: ScaleMode: Affects how rows and columns are measured on the form. See Table 11.5/345. CurrentX: Specifies the column. CurrentY: Specifies the row. Example: Form1.ScaleMode=4 Form1.CurrentY=2 : Form1.CurrentX=5 Form1.Print “Hebron” Prints Hebron at line 2 column 5
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 12 How Can you Position printing on the form? Private Function P1(Line, Column) Form1.CurrentY = Line Form1.CurrentX = Column End Function Private Sub Command1_Click() Form1.ScaleMode = 4 Print P1(2, 5); "Hebron" Print P1(3, 5); "PPU" End Sub
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 13 Printing VB Output Day 13 Page 405
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 14 Printer Object The printer object allows the programmer to send text and graphics to a printer. Declaring printer object: Dim PrinterName As Printer Printer Object properties: See Table 13.1 page 407 Copies : The number of copies to print. CurrentX, CurrentY : Set X and Y coordination to the next printed character. Page: returns the current page number.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 15 Examples on Printer properties pr.CurrentX = 10 pr.CurrentY = 2 pr.Copies = 4 Fomr1.Print pr.Page pr.FontBold = True pr.ScaleMode = 4 'Character
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 16 Printer Methods
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 17 Printer Method Examples Pr.NewPage pr.Print “bkjxvbkll” Form1.PrintFrom
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 18 Lab Training Design a VB project to: Accept Student names in a list, then lock it. Select student name from the list then accept 3 grades (Grade1, Grade2, Grade3) in a related text boxes for each grade. Perform the required validation to each grade.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 19 Lab Training …. [CONT] Calculate the student average. Sort the student names in ascending order according to their averages. Print the sorted student names and grades and averages on another form End
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 20 Lab9End