240 likes | 389 Views
Chapter-1 Introduction to Visual Basic GUI-
E N D
Chapter-1 Introduction to Visual Basic GUI- 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.
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.
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.
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.
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
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.
ErrorsinVB- 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 rule Ex. 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
Run Time Errors- If your project halts during execution then it’s runtime error Common runtime errors- • Divide by zero • Performing an arithmetic operation on nonnumeric data • Find a square root of negative number • Illegal use of object Logical Error- ?
Naming rules and conventions for objects – Rules- Begin with a letter 40 char long Letter, 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, optColor For name with multiple word ,capitalize first letter of each word frmDataEntry, chkPrintForm
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
Project Execution and debugging- Execution- F5 Start Start with full compilation Debugging-F8
Variables & Constant Variables- Memory location that holds the data that can be changed during program execution is called Variable. Constant Memory location that holds the data that can not changed during program execution is called Constant. Identifier When you declare a variable VB reserves memory space & assigns a name called identifier.
Naming Rules & conventions for Variable & Constant- Rules- • 1 to 255 chars long • Combination of digits, alphabets & underscores • They may not be reserved words Conventions- • 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
Data types in VB Boolean 2 bytes True/False Byte 1 byte 0 to 255 Currency 8 bytes Decimal fractions (dollars,Rs.) Date 8 bytes mm/dd/yyyy Double ----”---- floating point number Integer 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.
Examples- Dim s as string*3 S=“VBProgramming” Print s Output-VBP Dim s as variant S=10 Print s=10 S=“hello” Print s
Variable declaration- Dim identifier as [type] Dim-Dimensions (size) Type is optional if omitted default is variant
OPERATORS : Arithmetic Operators :
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
Comparison Operators :<,>,<=,>=,<> Used to compare expressions Example : This example shows various uses of comparison operators, which you use to compare expressions. Dim MyResult MyResult = (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.
Case statement Syntax- Select Case VARIABLE Case expression1 : ------- Case expression2:-------- . . . [Case else: ] End select *Expression can be any numeric or string value
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
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
Example- Select case with Relational Operator • WAP to print grade for given percentage • Dim per As Integer • per = 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