Presentation is loading. Please wait.

Presentation is loading. Please wait.

CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.

Similar presentations


Presentation on theme: "CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar."— Presentation transcript:

1 CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar

2 Introduction Visual Studio 6.0: Collection of Microsoft Visual development applications (Visual C++, Visual J++, Visual Basic, etc…) Visual Studio 6.0: Collection of Microsoft Visual development applications (Visual C++, Visual J++, Visual Basic, etc…) VB is a programming language. 6 Versions launched since its creation in the 90’s. VB is a programming language. 6 Versions launched since its creation in the 90’s. “Easy and powerful tool for developing Windows applications in Basic.” Bill Gates. “Easy and powerful tool for developing Windows applications in Basic.” Bill Gates.

3 VB Development Environment Integrated Development Environment (IDE): v isual environment to develop, run, test and debug. Integrated Development Environment (IDE): v isual environment to develop, run, test and debug. Controls: generally visual, and readymade components, assigned a set of properties (I.e. Text Box, Button, List Box, etc…). Controls: generally visual, and readymade components, assigned a set of properties (I.e. Text Box, Button, List Box, etc…). IntelliSense: Microsoft’s sophisticated completion technology. It simplifies the coding process. IntelliSense: Microsoft’s sophisticated completion technology. It simplifies the coding process. Event driven programming: f low of the application dictated by the user actions (click of a mouse, keystrokes, etc…). Event driven programming: f low of the application dictated by the user actions (click of a mouse, keystrokes, etc…).

4 VB IDE menu bar Toolbar Project Explorer Properties window Form layout Toolbox Immediate window

5 VB IDE Components Menu Bar: contains all commands needed to run VB (File, Edit, View etc…). Menu Bar: contains all commands needed to run VB (File, Edit, View etc…). Toolbars: quick access to commonly used menu commands. Toolbars: quick access to commonly used menu commands. Project Explorer: displays the project’s components. Project Explorer: displays the project’s components. Toolbox: contains icons of the controls that can be placed on the project’s Forms to create the application’s interface. Toolbox: contains icons of the controls that can be placed on the project’s Forms to create the application’s interface. Properties Window: Shows the property settings of the selected control (size, caption, color, etc…). Properties Window: Shows the property settings of the selected control (size, caption, color, etc…).

6 VB IDE Components (Cont’d) Form Designer: Main window in which one can design and edit the application’s user interface. In this window the user can enter and edit the application’s code. It displays two windows: Form and Code window. Form Designer: Main window in which one can design and edit the application’s user interface. In this window the user can enter and edit the application’s code. It displays two windows: Form and Code window. Form Layout: Shows the initial positions of the forms in the application. It is useful in multiple forms applications. Form Layout: Shows the initial positions of the forms in the application. It is useful in multiple forms applications. Immediate Window: Debugging tool. Immediate Window: Debugging tool.

7 Programming Steps Step 1: Customize the windows that the user sees. I.e. placing controls and components on the layouts of the project’s Forms. Step 1: Customize the windows that the user sees. I.e. placing controls and components on the layouts of the project’s Forms. Step 2: Decide on the events each control should recognize. Step 2: Decide on the events each control should recognize. Step 3: Coding the event procedures for those events. Step 3: Coding the event procedures for those events.

8 Variable Declaration Visual Basic code works in two modes: Visual Basic code works in two modes: – Implicit: does not require variable declaration – Explicit: requires variable declaration Declare variables using Declare variables using Dim VariableName As DataType Example:Dim length As Integer Dim greetings As String

9 Variable Types Numeric: Numeric: stores numbers String: stores text Variant: stores any type of data Boolean: true/false Date Object

10 Implicit/Explicit Implicit Example Implicit Example Public Sub VBImplicit() x = 5 y = “Hello” End Sub Explicit Example Start code window by: Option Explicit […] Public Sub VBExplicit() Dim x As Integer, y As String x = 5 y = “Hello” End Sub Implicit: default VB mode, x and y stored as variants Implicit: default VB mode, x and y stored as variants Explicit: x can only store integers, y only strings Explicit: x can only store integers, y only strings ALWAYS use explicit mode, it reduces errors ALWAYS use explicit mode, it reduces errors

11 Variable Scope Sub1 Sub1 Variables Form 1 Sub2 Sub2 Variables... Form1 Variables Code Form 2 Code

12 Variable Scope (cont’d) Dim x As Integer Public Sub FirstSub() x = 5 Dim y As Integer End Sub Public Sub SecondSub() x = 6 Dim y As String End Sub The same variable x is needed in both subroutines and therefore is defined as a global variable (I.e. declaration outside subs) The same variable x is needed in both subroutines and therefore is defined as a global variable (I.e. declaration outside subs) There is a different local variable y for each subroutine (I.e. declaration inside subs) There is a different local variable y for each subroutine (I.e. declaration inside subs)

13 Variable Generalities Variable names need to be significant for clear coding practice. Don’t be shy of using long names. Usually the first character(s) indicate the variable type (e.g): – –Integer: int…Dim intLength As Integer – –String: str… – –Double: dbl… – –Text Control: txt – –Etc.

14 Constants Constants do not change their value during the execution of the program. Declaration: Const ConstantName As DataType Public Const pi As Double = 3.14159265358979

15 Arrays Arrays hold a set of related data. Declaration: Dim ArrayName(ArraySize) As DataType Dim strNames(15) As String or Dim strNames(1 To 16) As String strNames is an array that holds 16 string values. Multidimensional arrays: Dim dblTemperature(99,99) As Double

16 Dynamic Arrays Size not defined at the beginning of the program: Dim dblMatrix() as Double You can re-dimension the array once you know the size of the array: ReDim dblMatrix(UserCount,UserCount)

17 What’s Next Basic VB syntax Basic VB syntax Functions and Subroutines Functions and Subroutines Common VB controls Common VB controls


Download ppt "CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar."

Similar presentations


Ads by Google