Introduction to Computing Dr. Nadeem A Khan
Lecture 13
► Properties Name Max Min Value Large Change Small Change etc. Scroll Bar (Horizontal and Vertical)
► Events Change Scroll etc. Scroll Bar (Horizontal and Vertical) - (Contd.)
► Read about them in the book Timer, Line, Shape
► Try out various formatting commands in the Format Menu the Format Menu The Format Menu
States of Visual Basic Three states of Visual Basic: ► Design State ► Execution State and and ► Break State
States of Visual Basic (Contd.) ► Break State: Execution interrupted temporarily Press F5 to resume or choose Run > Continue Immediate Window is activated Can edit code, Issue commands in the immediate window, Cannot edit the user-interface
► Useful for debugging ► Tryout commands in the break state like: Print Label1.Caption Print ( )/5 Label1.Caption= “Hello World” Picture1.Print “Hello” The Immediate Window
What is Focus ?
► The ability of a control to receive user input ► Related Events GotFocus LostFocus ► Related Properties TabIndex TabStop Focus
► Related Methods SetFocus ► The statement Text1.SetFocus‘shift focus to Text1 Text Box => Access Key can also be used to get focus Focus (Contd.)
► Names ► Appearance: (Flat look/3-D look etc.) ► BackColor ► ForeColor ► Font ► Caption ► Text ► Width, Height ► Left, Top VB Objects and Properties
► Enabled: True/False False: ► Cannot accept user input ► Cannot get focus ► Visible: True/False False: Control is invisible etc. VB Objects and Properties (Contd.)
Methods are actions that objects can carry out ► Print: e.g: Picture1.Print Printer.Print Form1.Print ► Cls: Contents are discarded e.g: Picture1.Cls‘ to clear the text in the picture box Form1.Cls ‘ to clear the text on the form VB Objects and Methods
► Move: For moving and resizing objects e.g: Control.Move left, top, width, height =>more on Methods in book or use help VB Objects and Methods (Contd.)
Event is a control’s response to an external action ► Change: e.g: VScroll1_Change (Value property of the Scroll Bar is changed) Text1_Change (each time a new character is typed in or deleted in the Text Box) Check1_Change (each time the user changes the status of the Check Box by clicking it VB Objects and Events
► Click, DblClick: events related to pressing left mouse button ► KeyPress: Events related to pressing a key VB Objects and Events (Contd.)
► More Events related to Mouse ► MouseDown, MouseUp, MouseMove etc. related to keyboard ► KeyDown, Keyup etc. more on Events in book or use help VB Objects and Events (Contd.)
► Event procedures implement the user-response Sub Label1_DblClick( ) Rem An event procedure with no arguments …. End Sub Sub Text1_KeyPress(KeyAscii As Integer) Rem An event procedure with an argument KeyAscii ….. End Sub VB Objects and Events (Contd.)
Application does not determine the flow; Events caused by the user determine the flow Event-Driven Programming
Object Oriented Programming?
Built-in Functions ► Take one or more input values ► Return an output value ► Already seen: Val(..), Str$(..), Asc(..), Chr(..)
Built-in Numeric Functions ► Sqr: calculates square-root and returns the value as double data type e.g: e.g: Sqr(9) is 3 Sqr(0) is 0 Sqr(2) is Sqr(30*2+4) is 8
Built-in Numeric Functions ► Int: Greatest integer less than and equal to a number e.g: e.g: Int(2.7) is 2 Int(3) is 3 Int(-2.7) is -3
Built-in String Functions ► Left$, Mid$, Right$, UCase$, Trim$ Left$(“fanatic”, 3) is “fan”Right$(“fanatic”, 3) is “tic” Left$(“12/15/93”,2) is “12”Right$(“12/15/93”, 2) is “93” Mid$(“fanatic”, 5,1) is “t”Mid$(“12/15/93”,4, 2) is “15” Ucase(“Disk”) is “DISK”Ucase(“12two”) is “12TWO” Trim$(“ 1 2 ”) is “1 2”Trim$(“-12 ”) is “-12”
Remember Assignment 4 ► It has been posted: See the Website
Refer to: ► Schneider: Section 3.6 ► Brown: Chapter 3(p76-104; p115-p127)