1 / 92

VISUAL BASIC PRESENTATION

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

lhoffman
Download Presentation

VISUAL BASIC PRESENTATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VISUAL BASIC PRESENTATION Visual Basic Made Easy

  2. 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.

  3. 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

  4. The Visual Basic Integrated Development Environment

  5. 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.

  6. TOOL BOX • COMPONENTS OF A TOOL BOX EXPLAINED

  7. View Code View Object Toggle Folders Project Name Forms Folder Form & modules Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  8. 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

  9. Hungarian Notation Use the three-character IDs shown in Figure 1-10 Palitha Baddegama , Computer Resource Centre, Hingurakgoda Figure 1-10

  10. Statements • Procedures • Event Procedures • Sub Procedures • General Procedures • Functional Procedures • Comments • Using single quotation (‘) • REM Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  11. Arithmetic Operators Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  12. Conditional Operators Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  13. Logical Operators Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  14. 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

  15. Data Types • Integer • Long • Integer • Floating point • Currency • Byte • Single • Double Numeric String Date Boolean Object Variant Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  16. Numeric Data Types Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  17. Nonnumeric Data Types PalithaBaddegama , Computer Resource Centre, Hingurakgoda

  18. 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

  19. 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

  20. 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.

  21. 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

  22. 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.

  23. Running the Application • To run the application F5

  24. 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

  25. 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

  26. Style Values Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  27. Return Values and Command Buttons Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  28. testmsg = MsgBox("Click to test", 1, "Test message") testMsg2 = MsgBox("Click to Test", vbYesNoCancel + vbExclamation, "Test Message") Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  29. The Icons displayed in the message box are here Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  30. 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

  31. 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

  32. 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

  33. Date format Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  34. Number format Number = 456.6768 Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  35. 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

  36. 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

  37. IF Then Branching Condition True Statement1 False Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  38. IF Then – End IF Condition True Statement 1 Statement 2 Statement 3 Statement 4 …………….. Statement n False Palitha Baddegama , Computer Resource Centre, Hingurakgoda

  39. 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

  40. 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

  41. 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

  42. 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

  43. 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

  44. 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

  45. Select Case Select case TestExpression Case Value1 Statement1 Case Value2 Statement2 Case Value3 Statement3 ………………… Case Else Else Statements End Select

  46. GoTo Statement Label : Goto Label or Goto Label Label :

  47. 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

More Related