1 / 10

Controls and Events

Controls and Events. The Next Step. In the first module, we discussed general problem solving In this module, we’ll apply what we learned, from specification to design to implementation and testing, on a very simple process

salaam
Télécharger la présentation

Controls and Events

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. Controls and Events

  2. The Next Step • In the first module, we discussed general problem solving • In this module, we’ll apply what we learned, from specification to design to implementation and testing, on a very simple process • Later we’ll gradually introduce VB features that let us implement more complex processes

  3. But First… • We have to learn enough about VBA and Excel to write an interesting program! • So our goal in this module is to learn those basics and apply them to a problem

  4. Relating VBA to Processes • We will typically represent the objects in our process specification by Excel or VBA controls and other Excel and VBA objects • Objects and controls have events associated with them • The process events will be translated into control events for which we will write procedures

  5. Writing a Macro • We’re going tostart by writing (not recording) a small macro with a button to control it • This will introduce a number of basic concepts

  6. The Code Option Explicit '***************************************** ' Turn the active cell red '***************************************** SubRedCell() ActiveCell.Interior.Color = vbRed End Sub

  7. The Video • You can watch the steps of writing the macro and adding the button on the video called Button Demo • The workbook is available on the class site • After you watch, try writing your own macro, say GreenButton, in the same worksheet. Give it a button and/or a piece of clip art to activate it

  8. Events • Clicking the button or the clip art is an event that triggers the execution of the macro • This is a pattern we will continue to follow: our macros will be triggered by events that happen in the spreadsheet • Later we will also write macros that can be called by other macros

  9. Referring to Objects and Properties • Consider the expression ActiveCell.Interior.Color = vbRed • ActiveCell is an object recognized by Excel: the cell that has been selected in the active worksheet • Interior is a subobject of the ActiveCell: it’s just the interior of the cell • Color is a property of the Interior, and as such can be set to a value by an assignment statement

  10. Properties vs Variables • We’ll often be setting the values of properties of objects • Cells in particular have a property called the Value: ActiveCell.Value = 5 will make the number 5 show up in the cell • Besides properties of objects, we’ll also use more general variables for quantities we want our program to remember and work with

More Related