Chapter-1 Introduction to Visual Basic GUI-

23
computer. The term came into existence because the first interactive user interfaces to computers were not graphical; they were text-and-keyboard oriented and usually consisted of commands you had to remember. The command interface of the DOS operating system (which you can still get to from your Windows operating system) is an example of the typical user-computer interface (character/command user interface-CUI) before GUIs arrived. An intermediate step in user interfaces between the command line interface and the GUI was the non-graphical menu-based interface, which let you interact by using a mouse rather than by having to type in keyboard commands. Today's major operating systems provide a graphical user interface.

description

Chapter-1 Introduction to Visual Basic GUI- - PowerPoint PPT Presentation

Transcript of Chapter-1 Introduction to Visual Basic GUI-

Page 1: Chapter-1 Introduction to Visual Basic GUI-

Chapter-1 Introduction to Visual BasicGUI-

A GUI is a graphical (rather than purely textual) user interface to a computer. The term came into existence because the first interactive user interfaces to computers were not graphical; they were text-and-keyboard oriented and usually consisted of commands you had to remember. The command interface of the DOS operating system (which you can still get to from your Windows operating system) is an example of the typical user-computer interface (character/command user interface-CUI) before GUIs arrived. An intermediate step in user interfaces between the command line interface and the GUI was the non-graphical menu-based interface, which let you interact by using a mouse rather than by having to type in keyboard commands.

Today's major operating systems provide a graphical user interface. Applications typically use the elements of the GUI that come with the operating system and add their own graphical user interface elements and ideas.

Page 2: Chapter-1 Introduction to Visual Basic GUI-

Programming languages-There are various types of programming

languages, each was developed to solve a particular kind of problems. 1. Procedural languages-

A computer programming language that follows, in order, a set of commands. Examples of computer procedural languages are BASIC, C, FORTRAN, and Pascal.2. Object Oriented programming language-

A type of programming in which programmers define not only the data type of a data structure, but also the types of operations (functions) that can be applied to the data structure. In this way, the data structure becomes an object that includes both data and functions. In addition, programmers can create relationships between one object and another. For example, objects can inherit characteristics from other objects.

Page 3: Chapter-1 Introduction to Visual Basic GUI-

3. Event Driven programming language-In computer programming, event-driven

programming also known as event-based programming is a programming method in which the flow of the program is determined by user actions such as mouse clicks, key presses.

Page 4: Chapter-1 Introduction to Visual Basic GUI-

VB Environment-VB is event-driven programming language,

which has some of the features of object oriented programming language. In VB you will work with objects, which has properties and methods. Objects-Object is an element from a VB program, such as a control, form or code module that holds programming statement. Properties-A Property helps to differentiate a control from other control because the property shows appearance and behavior of a control. Properties have values such as colors, names, size and location on the form.Methods-Actions associated with the objects are called methods. Some common methods are move, print, show etc. Event- Each action by the user causes an event, Event is an activity that occurs during program execution, such as mouse click, key-press, activate etc.

Page 5: Chapter-1 Introduction to Visual Basic GUI-

VB Environment-An integrated development environment (IDE)

is a programming environment that has been packaged as an application program, typically consisting of a code editor, a compiler, a debugger, and a graphical user interface (GUI) builder.

•Main Window- Title bar, Menu bar & tool bar•Tool Box•Form Window•Project Explorer•Properties window•Form Layout window

Page 6: Chapter-1 Introduction to Visual Basic GUI-

Visual Basic Projects-

•The Project file with extension .vbp•Each form in project saved with extension .frm•Optionally you can have .bas files that contains basic statement accessed from any form of the project. (These files are also called standard code module)•If you include additional controls which are not part of standard control set then the .ocx file names will be included in your project.•After you save a project, VB automatically adds one or more files to your project with extension .vbw(VB project workplace). This file holds information about each of your project’s form.

Page 7: Chapter-1 Introduction to Visual Basic GUI-

Errors in VB-1. Compile time errors- (Occurs when you press

enter key or when you execute code)Project code->m/c code=>Compile time errors if you break syntax ruleEx. if a<b ‘if without then gives

compile time error print a else print b end if If you spelled wrong ennd ‘ennd instead End

Page 8: Chapter-1 Introduction to Visual Basic GUI-

Run Time Errors-Run Time Errors-

If your project halts during execution then it’s If your project halts during execution then it’s runtime errorruntime error

Common runtime errors-Common runtime errors- Divide by zeroDivide by zero Performing an arithmetic operation on Performing an arithmetic operation on

nonnumeric datanonnumeric data Find a square root of negative numberFind a square root of negative number Illegal use of objectIllegal use of object

Logical Error-Logical Error-

??

Page 9: Chapter-1 Introduction to Visual Basic GUI-

Naming rules and conventions for objects –

Rules-Begin with a letter40 char longLetter, digit and underscores

Conventions-Follow this to make project more understandable

Always begin a name with a lowercase three-letter prefix and capitalize the first character after the prefix. EX- cmdShow, lblMessage, optColorFor name with multiple word ,capitalize first letter of each wordfrmDataEntry, chkPrintForm

Page 10: Chapter-1 Introduction to Visual Basic GUI-

Visual Basic Statements-

Remark statement-To add comments,Use apostrophe to start comment.

Assignment Statement-Assign value to variable or value to property.

End Statement-Stops execution of program

Page 11: Chapter-1 Introduction to Visual Basic GUI-

Project Execution and debugging-Project Execution and debugging-

Execution-Execution-

F5F5

StartStart

Start with full compilationStart with full compilation

Debugging-F8 Debugging-F8

Page 12: Chapter-1 Introduction to Visual Basic GUI-

Variables & ConstantVariables & ConstantVariables-Variables-Memory location that holds the data that can be Memory location that holds the data that can be

changed during program execution is called changed during program execution is called Variable.Variable.

ConstantConstantMemory location that holds the data that can not Memory location that holds the data that can not

changed during program execution is called changed during program execution is called Constant.Constant.

IdentifierIdentifierWhen you declare a variable VB reserves memory When you declare a variable VB reserves memory

space & assigns a name called identifier.space & assigns a name called identifier.

Page 13: Chapter-1 Introduction to Visual Basic GUI-

Naming Rules & conventions for Variable & Constant-

Rules- 1 to 255 chars long Combination of digits, alphabets & underscores They may not be reserved wordsConventions- Must be meaningful Choose a name that indicates purpose of

variable/constant Use prefix before name Capitalize First name of the word Ex- intEmpNum dtm B_Date dblPer

Page 14: Chapter-1 Introduction to Visual Basic GUI-

Data types in VBBoolean 2 bytes True/FalseByte 1 byte 0 to 255Currency 8 bytes Decimal fractions

(dollars,Rs.)Date 8 bytes mm/dd/yyyyDouble ----”---- floating

point numberInteger 2 bytes whole

numbers(-32768 to 32767)

Long 4 bytes Long whole numbers

Single 4 bytes floating point with 6 digits accuracy

String fixed or variables 1 to 65000 chrs

Variant 22 bytes Converts data according to value.

Page 15: Chapter-1 Introduction to Visual Basic GUI-

Examples-Dim s as string*3S=“VBProgramming”Print s Output-VBP

Dim s as variant S=10Print s=10S=“hello”Print s

Page 16: Chapter-1 Introduction to Visual Basic GUI-

Variable declaration- Dim identifier as

[type]Dim-Dimensions (size)Type is optional if omitted default is variant

Page 17: Chapter-1 Introduction to Visual Basic GUI-

Operator Example Description

+ A+B Add two values

- A-100 Subtract second val from first

* Total*Fact Multiply two values

/ Tax/a Divide one no by other

Mod Num1 Mod Num2 Divide 2 nos and return only remainder

^ No1 ^ Pow Raises a value to a power

& or + Name1 & Name2 Concatenates 2 strings

OPERATORS : Arithmetic Operators :

Page 18: Chapter-1 Introduction to Visual Basic GUI-

Operator Example Description + A+B Add two values - A-400 Subtract one value from other * Total*fact Multiply two values. / Tax/a Divide one number by another number

Mod Num1 mod num2 Divides two nos. and return only remainder. ^ Num^exp Raises a value to a power

Page 19: Chapter-1 Introduction to Visual Basic GUI-

Comparison Operators :<,>,<=,>=,<>Used to compare expressionsExample : This example shows various uses of comparison operators, which you use to compare expressions.Dim MyResultMyResult = (45<35) 'Returns False.MyResult = (45=45) 'Returns True. MyResult = (4 <> 3) 'Returns True.

Like Operator :Syntax- “string” like “pattern”Dim MyCheck MyCheck = "aBBa" Like "a*a" 'Returns True.MyCheck = "F" Like "[A-Z]" 'Returns True.MyCheack = "CAT123khg" Like "B?T*" 'Returns False.

Page 20: Chapter-1 Introduction to Visual Basic GUI-

Case statement

Syntax-Select Case VARIABLECase expression1 : -------Case expression2:--------...[Case else: ]End select

*Expression can be any numeric or string value

Page 21: Chapter-1 Introduction to Visual Basic GUI-

Select statement can handle a single value, ranges and sets

Example-Select case with single value-

Write a program to add, sub, div and multiply 2 numbers using case statement.

Dim a As Integer, b As Integer, ope As String

a = Val(Text1)

b = Val(Text2)

ope = Text3

Select Case ope

Case "+": Print a + b

Case "-": Print a - b

Case "*": Print a * b

Case "/": Print a / b

Case Else: Print "Wrong selection"

End Select

Page 22: Chapter-1 Introduction to Visual Basic GUI-

Example- Select case with Sets and range of values

WAP to print given letter is an alphabet, a number or a symbol

Dim a As String

a = Text1

Select Case a

Case 0 To 9: Print "Numbers"

Case "A" To "Z", "a" To "z": Print "Alpahabets"

Case Else: Print "Symbol"

End Select

Page 23: Chapter-1 Introduction to Visual Basic GUI-

Example- Select case with Relational OperatorWAP to print grade for given percentage

Dim per As Integerper = Val(Text1)Select Case per

Case Is < 40: Print "FAIL" Case Is < 60: Print "PASS"

Case Is < 70: Print "First"Case Is > 70: Print "DIST"

End Select