1 / 18

Visual Basic for Applications - The Environment

Visual Basic for Applications - The Environment. What is an event-driven program? A user interface? What are Access/Accelerator Keys? NOTE: Important material on VBA is in the Course Guide at the start of this lecture slide section, so read those pages soon!.

lyris
Download Presentation

Visual Basic for Applications - The Environment

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 for Applications - The Environment • What is an event-driven program? • A user interface? • What are Access/Accelerator Keys? • NOTE: Important material on VBA is in the Course Guide at the start of this lecture slide section, so read those pages soon!

  2. What we learn in the next part of CS105 How can we program computers? Making decisions How to create functions and procedures CS 105 Fall 2005

  3. Why Learn Visual Basic for Applications? • Business College wants you to learn flow charts and the kind of thinking that programmers use • Extremely powerful -- lets non-professionals to do some heavy-duty programming CS 105 Fall 2005

  4. Why Learn Visual Basic for Applications? • Widely used to create applications for the PC and to jazz up Windows, Browsers, etc. • Excel and Access can be modified by Visual Basic for Applications (VBA is built in) • FUN to do--you can see your results quickly CS 105 Fall 2005

  5. What is a software program? "As a rule, software systems do not work well until they have been used, and have failed repeatedly, in real applications." (Dave Parnas) CS 105 Fall 2005

  6. Visual Basic for Applications: BASICstands for Beginner’s All-purpose Symbolic Instruction Code. • Developed in the 1960s. Microsoft developedVisualBasicin 1991. • Lets you make stand-alone programs Visual Basicfor Applications • Allows you to program in Microsoft applications, to create or improve macros, to create user interfaces, and even make your own programs. CS 105 Fall 2005

  7. Programming Languages: Visual Basic for Applications • A program’s ability to respond to events forms the basis of event-driven programming • Responds to user-initiated events such as keystroke or click, or even opening up a workbook examples: Visual Basic for Applications, Java • Uses Objects such as command buttons, cells, pictures, charts, spreadsheets. CS 105 Fall 2005

  8. What is an Event? • An event is any action to an object that is recognized by an application such as Excel. • Opening or closing an Excel workbook • Clicking on a command button • Changing the data in a cell • An event procedure is code that runs in response to the event. CS 105 Fall 2005

  9. What does a procedure look like? Private Sub cmdFormat_Click() Range("F8").Value = Range(“C8").Value Range(“C8").ClearContents End Sub CS 105 Fall 2005

  10. Calling Event Procedures You can run one procedure from another procedure. You "call" it, even if it is stored in another module/worksheet. You call a subprocedure by writing its name: Private Sub cmdRun_Click() FormatSheet End Sub CS 105 Fall 2005

  11. Graphical User Interface • You create the GUI (graphical user interface)/ CHI (computer-human interface) You create prompts, questions to the user Key entry, Mouse Click, Menu Selection, Text or data entry You decide the program responses to user actions Including Computations, Change of Interface, etc. CS 105 Fall 2005

  12. What happens when you use VBA • You create Input Boxes or use controls to gain input from the user. • You insert code behind spreadsheet, in the VISUAL BASIC EDITOR, to process the information. • The basic building block of a VBA program is the procedure (subroutine = sub procedure = sub) CS 105 Fall 2005

  13. Assignment Statement • [Let] Object.property = a color or quantity, etc. • Either of these works: • Let Range("B2").Value = 33 • Range("B2").Value = 33 • The = sign means "take the value on the right side of the equal sign and assign it to a place in the computer’s memory named on the left side of the = sign." CS 105 Fall 2005

  14. A FLAWED assignment statement 33 = Range(“C3”).Value CS 105 Fall 2005

  15. How the computer reads a line of code • In C language, the ; character tells the computer to stop reading each separate statement • C Language -- Range(“C2”).Value = 4 + 5; • In VBA, the end of the line is considered to be the end of the statement (like a period in English) Range(“C2”).Value= 5 + 5 • In order to force the computer to consider the next line part of the first, we use (space)(underline) as seen on the next slide. CS 105 Fall 2005

  16. Errors in continuing lines of code We use an underscore in VBA: __ BAD: Range(“C2”).Value = "Me Tarzan, you _" & Range(“A1”).Value Range(“C2”).Value = "Me Tarzan, you"_ & Range(“A1”).Value Don’t put inside the quote Leave a space! CS 105 Fall 2005

  17. Java code—what does it look like? // create board s = new Space[grid.width][grid.height]; // download images this.showStatus("Downloading images..."); tracker = new MediaTracker(this); mine = this.getImage(this.getDocumentBase(),"images/mine.gif"); tracker.addImage(mine, 0); Note: comments start with//, lines end with; CS 105 Fall 2005

  18. To summarize: What is • an event-driven program? • a user interface? • an assignment statement? • Your moment of Zen http://youtube.com/watch?v=nyeR7bmvjco CS 105 Fall 2005

More Related