920 likes | 942 Views
VISUAL BASIC PRESENTATION. Visual Basic Made Easy. Lecture 1 - What's Visual Basic About?. This lecture focuses on the main components of the Visual Basic environment. By the end of this session you should be able to
E N D
VISUAL BASIC PRESENTATION Visual Basic Made Easy
Lecture 1 - What's Visual Basic About? This lecture focuses on the main components of the Visual Basic environment. By the end of this session you should be able to • navigate competently and use many of the functions that are important in the development of an application.
Applications of Vb software Visual Basic is used to develop 'rapid applications' inside a windows environment Visual Basic is a high level programming paradigm. Its concepts are based upon Event driven programming. The environment to edit, delete and write code as well as develop windows based applications is known as the 'Integrated Development Environment' (IDE). Visual basic can do the following; • Develop commercial applications, for example databases and the internet • Links to other products such as Word, Excel and Access • Multimedia applications
IDE Cont…. From the diagram it can be seen that the IDE is divided into separate areas or 'windows'. We have the Toolbox control which allows us to add objects on to Form window. We can change the properties using the properties windows for all the objects on the form. We can also edit/create the event handlers using the Code Window. When creating applications in Visual Basic it is quite common to use multiple forms, modules etc. The project explorer window is used to keep track of all the additional files used.
TOOL BOX • COMPONENTS OF A TOOL BOX EXPLAINED
View Code View Object Toggle Folders Project Name Forms Folder Form & modules Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Name Property Must begin with a letter Can contain letters, numbers, and the underscore character only Must not contain punctuation characters or spaces (!,~,`,@,#,$,%,^,&,*,(,),-,=,+,|,\,/,>,<, ,,; ,:) Must not exceed 40 characters Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Hungarian Notation Use the three-character IDs shown in Figure 1-10 Palitha Baddegama , Computer Resource Centre, Hingurakgoda Figure 1-10
Statements • Procedures • Event Procedures • Sub Procedures • General Procedures • Functional Procedures • Comments • Using single quotation (‘) • REM Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Arithmetic Operators Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Conditional Operators Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Logical Operators Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Variable and Data Types • Variable Names • The following are the rules when naming the variables in Visual Basic • It must be less than 255 characters • No spacing is allowed • It must not begin with a number • Period is not permitted • Reserved Word not allowed Ex. Sub, Private, • End Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Data Types • Integer • Long • Integer • Floating point • Currency • Byte • Single • Double Numeric String Date Boolean Object Variant Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Numeric Data Types Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Nonnumeric Data Types PalithaBaddegama , Computer Resource Centre, Hingurakgoda
Variable Scope There are three levels of scope: project-level (also called "global" or "application" scope; the variable is accessible to all procedures in all modules of the project) module-level (the variable is accessible to all procedures in the module in which it is declared) local-level(the variable is accessible only to the procedure in which it is declared) Palitha Baddegama , Computer Resource Centre, Hingurakgoda
The Code Window • The Code window is little more than a text editor with which you write the programming statements that tie the application together. • An alternative technique to view the code is to double click anywhere on the form or the object and view the code for that particular object. The diagram shows the Code Window for the form Example Private Sub txtJAN_KeyPress(KeyAscii As Integer) Call TEST(KeyAscii, txtFEB) End Sub
Code window cont…. • When you or another user compiles or runs the source program, VB translates the program into an executable program. You cannot make changes directly to an executable program. If you see bugs when you run the program, you must change the source application (which might contain multiple files in the project) and rerun or recompile the source.
The Project Explorer Window • Gives you a tree-structured view of all the files in the application. Microsoft changed the formal name from Project window to Project Explorer window
The Properties Window • The property window represents an objects associated properties. Each property of a control such as a Label, command button etc. has its own unique set of properties. • A different list appears in the Properties window every time you click over a different Form window object. The Properties window describes properties (descriptive and functional information) about the form and its controls. Many properties exist for almost every object in Visual Basic. The Properties window lists all the properties of the Form window's selected control. • The property window is activated by pressing the shortcut keyF4.
Running the Application • To run the application F5
Variable Scope Module1 Public X as Integer Form1 Form2 Dim Y as Integer Dim Z as Integer Sub procedure 1 () Dim A as Double . . . . End Sub Sub procedure 3 () Dim C as Double . . . . End Sub Sub procedure 2 () Static B as Double . . . . End Sub PalithaBaddegama , Computer Resource Centre, Hingurakgoda
MsgBox ( ) Function A=MsgBox(Prompt, Style Value, Title) Example: A=MsgBox( "Click OK to Proceed", 1, "Startup Menu") A=Msgbox("Click OK to Proceed". vbOkCancel,"Startup Menu") Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Style Values Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Return Values and Command Buttons Palitha Baddegama , Computer Resource Centre, Hingurakgoda
testmsg = MsgBox("Click to test", 1, "Test message") testMsg2 = MsgBox("Click to Test", vbYesNoCancel + vbExclamation, "Test Message") Palitha Baddegama , Computer Resource Centre, Hingurakgoda
The Icons displayed in the message box are here Palitha Baddegama , Computer Resource Centre, Hingurakgoda
InputBox( ) Function A=InputBox(Prompt, Title, default_text, x-position, y-position) B= InputBox("What is your message?", "Message Entry Form", "Enter your message here", 500, 700) Palitha Baddegama , Computer Resource Centre, Hingurakgoda
The numeric functions • a) IntInt(2.4)=2, Int(4.8)=4, Int(-4.6)= -5, Int(0.032)=0 and so on. • b) SqrSqr(4)=2, Sqr(9)=3 and etc. • c) AbsAbs(-8) = 8 and Abs(8)= 8. • d) ExpExp(1)=e1 = 2.7182818284590 • e) Fix and Int Fix(-6.34)= -6 while Int(-6.34)=-7 • f)RoundRound (7.2567, 2) =7.26 • g)LogLog 10= 2.302585 Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Len (“welcome to VB tutorial”) = 22 • Right("Visual Basic", 4) = asic • Left ("Visual Basic", 4) = Visu • Ltrim (" Visual Basic")= Visual basic • Rtrim ("Visual Basic ") = Visual basic • Trim (" Visual Basic ") = Visual basic • Mid("Visual Basic", 3, 6) = sual B • Instr(1, "Visual Basic"," Basic")=8 • Chr(65)=A, Chr(122)=z, Chr(37)=% , • Asc(“B")=66, Asc(“&")=38 PalithaBaddegama , Computer Resource Centre, Hingurakgoda
Date format Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Number format Number = 456.6768 Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Format (n, "style argument") • Format (8972.234, "General Number") • Format (8972.2, "Fixed") • Format (6648972.265, "Standard") • Format (6648972.265, "Currency") • Format (0.56324, "Percent") Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Control Structures • Looping • While -Wend • Do while-Loop • Do-Loop while • Do Until-Loop • Do-Loop Until • For next • Branching • IF • IF Then • IF Then – End IF • IF Then Else – End IF • IF Then Else IF • Nested IF • Select Case • Goto Palitha Baddegama , Computer Resource Centre, Hingurakgoda
IF Then Branching Condition True Statement1 False Palitha Baddegama , Computer Resource Centre, Hingurakgoda
IF Then – End IF Condition True Statement 1 Statement 2 Statement 3 Statement 4 …………….. Statement n False Palitha Baddegama , Computer Resource Centre, Hingurakgoda
IF Then Else – End IF Condition True Statement 1 Statement 2 Statement 3 Statement 4 …………….. Statement n False Statement 1 Statement 2 Statement 3 Statement 4 …………….. Statement n Palitha Baddegama , Computer Resource Centre, Hingurakgoda
IF <Condition> Then Statement 1 Statement 2 Statement 3 …………….. Statement n A Else Statement 1 Statement 2 Statement 3 …………….. Statement n B End IF Statement 1 Statement 2 Statement 3 …………….. Statement n C Palitha Baddegama , Computer Resource Centre, Hingurakgoda
IF Then Else IF Condition True Statement 1 Statement 2 Statement 3 …………….. Statement n False Condition True False Statement 1 Statement 2 Statement 3 …………….. Statement n Statement 1 Statement 2 Statement 3 …………….. Statement n Statement 1 Statement 2 Statement 3 …………….. Statement n Palitha Baddegama , Computer Resource Centre, Hingurakgoda
IF <Condition> Then Statement 1 Statement 2 …………….. Statement n A ElseIF <Condition> Then Statement 1 Statement 2 …………….. Statement n B Else Statement 1 Statement 2 …………….. Statement n C End IF Statement 1 Statement 2 …………….. Statement n D Palitha Baddegama , Computer Resource Centre, Hingurakgoda
Nested Loop Condition True Statement 1 Statement 2 Statement 3 …………….. Statement n False Condition True False Statement 1 Statement 2 Statement 3 …………….. Statement n Statement 1 Statement 2 Statement 3 …………….. Statement n Statement 1 Statement 2 Statement 3 …………….. Statement n Palitha Baddegama , Computer Resource Centre, Hingurakgoda
IF <Condition 1> Then Statement 1 Statement 2 …………….. Statement n A Else IF <Condition 2> Then Statement 1 Statement 2 …………….. Statement m Else Statement 1 Statement 2 …………….. Statement p B C End IF Statement 1 Statement 2 …………….. Statement q D PalithaBaddegama , Computer Resource Centre, Hingurakgoda
Select Case Select case TestExpression Case Value1 Statement1 Case Value2 Statement2 Case Value3 Statement3 ………………… Case Else Else Statements End Select
GoTo Statement Label : Goto Label or Goto Label Label :
While -Wend Looping Condition Statement 1 Statement 2 Statement 3 ……………… Statement n True While Condition Statement 1 Statement 2 …………….. Statement m Wend False Palitha Baddegama , Computer Resource Centre, Hingurakgoda