1.16k likes | 1.43k Views
2-3 Weeks 1998. Course Plan. Consepts of Visual Basic Components Of IDE (Integrated Development Environment) First Visual Basic application Coding rules Properties, methods and events Controls Menües. Consepts Of Visual Basic. Type of Windows. Explorer windows (Windows 95)
E N D
2-3 Weeks 1998 Course Plan • Consepts of Visual Basic • Components Of IDE (Integrated Development Environment) • First Visual Basic application • Coding rules • Properties, methods and events • Controls • Menües
Consepts Of Visual Basic Type of Windows • Explorer windows (Windows 95) • Document Window(Word) • Dialog Box(Pop Up Window) • Command buttons, icons, text boxes, menu bar
Consepts Of Visual Basic Events and messages • Windows O.S assigns an unique handler to point each window • window handle hWnd • The system continually monitors each of these windows for signs of activity or events • Events can occur through • user actions(Such as mouse click or a key press) • or even as a result of another window’s action
Consepts Of Visual Basic Events and Messages • Methods can be applied for an object • Result of another event • Each time an event occurs, it couses a message to be sent to O.S • O.S process the message and broadcasts it to the other windows • And each window takes the message and do the necessary process
Consepts Of Visual Basic Windows Message Handler • Windows Message Handler operates this process • Windows Message Handler of Visual Basic do the same process as an interface • Many of these messages are handled automaticaly by Visual Basic • The other messages are left to the user application.
Consepts Of Visual Basic Traditional and Event Driven Model • Traditional or Procedural programming • The application controls • Which portions of code execute • and in what sequence • Event driven programming • The code doesn’t follow a predetermined path • It executes different code sections in response to events
Consepts Of Visual Basic Event Driven Model • Events can be triggered by the user’s actions • The sequence of these events determines the sequence in which the code executes • Which code section Result of an event • In which sequence Result of an event • Your code can also trigger events during execution
Consepts Of Visual Basic Event Driven Model • Example • Changing the text in a text box cause the text box’s Change event to occure • If you assume that this event would only triggered by user interaction , you might see unexpected results • For this reason it is important to understand the event-driven model and keep it in mind when designing your application
Consepts Of Visual Basic Development Phase • The traditional application Writing code, compiling, and testing • Visual Basic uses an interactive approach • Interprets your code as you enter it • Catching and highlighting most syntax or spelling errors on the fly. • Partially compiles the code as it is entered • If the compiler finds an error, it is high lited in your code. Fix the code and continue compiling
Components Of IDE Integrated Development Environment • Title Bar • Menu Bar • Context Menus • Toolbars • Toolbox • Project Explorer window • Properties WIndow
Components Of IDE Integrated Development Environment • Object Browser • Form Designer • Code Editor window • Form layout Window • Immediate, Locals, and Watch Windows
Components Of IDE Title Bar • Displays the title and current process type of the project • Design • Run • Code
Components Of IDE Menü Bar • Displays the commands you use to work with Visual Basic • Standard menües • File, Edit, View, Window, Help • Additional Visual Basic Menues • Project, Format, Debug, Run, Tools, Add-Ins
Components Of IDE Context menu • Contains shortcuts to frequently performed actions. To open this menu , click the right mouse button on the object you’re using • Different menu for each object
Components Of IDE Toolbar • Provide quick access to commonly used commands in programming environment • Standard, debug, edit, form editor tool bars • “Floating” or “dockable”
Components Of IDE Tool Box • Provides a set of tools that you use at design time to place controls on a form • Standard toolbox(controls) • Your own custom layout controls • Add Tab from the context menu and adding controls to the resulting tab
Components Of IDE Project explorer window • Lists the forms and modules in your current project • A project is the collection of files you use to build an application
Components Of IDE Properties Window • Lists the property settings for the selected form or control • Alphabetic • Categorized • A Property is a characteristic of an object(size,caption,color, • name..)
Components Of IDE Object Browser • Lists objects available for use in current project • see what methods and properties are avaible for those objects
Components Of IDE Forms • Serves as a window • Design your application on this window. • Add controls, graphics, pictures etc. • Acts as a container for the various controls
Components Of IDE Code Editor Window • Serves as an editor for entering application code • A separate code editor window is created for each form or code module in your application
Components Of IDE Form Layout Window • Allows you to position the forms in your application using a small graphical representation of the screen
Components Of IDE Immediate window • To see the values of each varibales which is prviously defined • Used for debugging purposes in running mode
Components Of IDE Local window • Used in Break mode • list the values of local variables in the current active procedure
Components Of IDE Watch window • Used in break mode
First Visual Basic Application Steps of an Application • Creating the interface • Set properties • Write code
Steps of an application Creating the interface • First step is to create the Forms that will be the basis for your application’s interface • Chose the necessary objects(controls) from tool box and put them into proper locations on the form • click the tool for the control • move the pointer on the form • Place the control into a proper location • Release the button
Steps of an application Creating the interface • Resizing, moving and locking controls • Sizing handler(small rectentangular box) • Mouse, keyboard(shift+arrow key) • To move a control • Use the mouse to drag the control to a new location on the form • Use properties window to change the Top and Left properties
Steps of an application Creating the interface • To Lock all control positions • This will lock all controls on the form in their current positions • From the Format menu chose Lock Controls
Steps of an application Setting Properties • From View Menu • Click the Properties for a selected object • Object Box • Displays the Name of the object • Sort Tabs • Alphabetical • Categorized
Steps of an application Settings properties • Properties List • Left Column displays all of the properties for the selected object. You can edit and view settings in the right column • Design Time Properties • Execution time properties(“Not available at design time”)
Steps of an application Writing Code • Code editor window is used to write Visual Basic Code(See code Basics chapter 5) • To open code window • Double-click the form or control for which you chose to write code
Steps of an application Writing Code
Steps of an application Writin Code You can see more than one procedure on the same code window
Steps of an application Writing Code Display Only one procedure(Tools(Options(Editor(Procedure view
Steps of an application Objects and events
Starting Visual Basic Sample Application • First Step Using Star Menu
Starting Visual Basic Sample Application • Chose the type of project
First Visual Basic Application Example
First Visual Basic Application Sample application • Design phase(“Hello world!”) • Necessary objects(controls) • Label box(control) • Text box(control) • Command button(control) • Form
Coding Rules • Rules for naming the objects • Constant and variables names • Skip this page
Creating Event Procedure • An event procedure contains code that is executed when an event occurs • An event procedure for a control combines control’s actual name(Specified in Name property), an underscore( _ ), and the event name • Private Sub CmdAdd_Click()
Creating Event Procedure • Format of changing the text property is Object.Property = Property value • Example • Text1.text = “Hello World !” • The event procedure will be • Private Sub Cmd_click() • TxtName.text = “Hello World !” • end sub
Properties, Methods and Events • Properties can be thought of as an object’s attributes • A Methods is a function that acts on a particular object • Events as its responses with the user • An everyday object like a child’s Balloon also has properties
Properties,methods, Events Properties • Visible Attributes • Color,diameter,Height • Other properties • State(inflated or not inflated) • Example • Balloon.Color • Balloon.State
Properties,methods, Events Methods • A Methods is a function that acts on a particular object(Object.method) • Samples • Balloon.Inflate • Balloon.Deflate • Balloon.Rise
Properties,methods, Events Events Events as its responses with the user • A Balloon’s Methods are • Balloon.inflate • Balloon.Deflate • Balloon.Rise 5
Properties,methods, Events Methods • The syntax is similar to the property • Object.Method arguments(if it has) Example : Balloon.inflate Balloon.Rise 5 Some methods will have one or more arguments
Event • The balloon might respond to an event as follows(in this case, the code describes the balloons behavior when a puncture event occurs) • Sub Balloon_Puncture() Balloon.Deflate Balloon.MakeNoise “Bang” Balloon.Inflated = True Balloon.Diameter = 1 End Sub
Designing a Form(properties) • Form objects are the basic building blocks of Visual Basic application. • The actual windows which a user interacts when they run the application • Forms have their own properties, events, and methods with which you can control their appearance and behaviour