Presentation is loading. Please wait.

Presentation is loading. Please wait.

Preparing for Assignment 3. Setup Assignment 3 builds on Assignment 2, and we are using the same basic scenario. Save the spreadsheet you used for Assignment.

Similar presentations


Presentation on theme: "Preparing for Assignment 3. Setup Assignment 3 builds on Assignment 2, and we are using the same basic scenario. Save the spreadsheet you used for Assignment."— Presentation transcript:

1 Preparing for Assignment 3

2 Setup Assignment 3 builds on Assignment 2, and we are using the same basic scenario. Save the spreadsheet you used for Assignment 2 as YourNameAssignment3, making sure it’s a macro-enabled workbook You will again have a model Ice Cream Order to follow along with, building on the first version used for Assignment 2

3 Before Writing the Code: Requirements Remember, writing is the third step of the process, not the first! Start by reviewing the requirements and making up some use cases and tests. You will need at least five or six tests to do a good job Think about the process. What should happen first? What next? Work through a typical use case on paper

4 Before Writing the Code: Specification Start by making a plan. If you don’t want to do a flowchart for the whole program, write down the major steps in English (this is called “pseudo code”) Think about what variables and constants you might need We used our pseudo code steps as major comments in our code; you can write these first and then fill in You will need to hand in a flow chart for the conditionals that control what happens with the option buttons

5 Writing the Code It is a HUGE mistake to write all the code and then try to debug it Write a small piece and run it to make sure it works. Then write another small piece This way if there is a bug you know it is probably in the small piece of new code you just wrote. You don’t have to hunt for it through the new program If you get a runtime error, click on debug and VBA will highlight the line where the error occurred. You can also step through your code.

6 Give Yourself Enough Time Things may go well but when writing code it is common to get a hard-to-find bug or two Start early so you have plenty of time to hunt them down Use the TA and the message boards, but please don’t post large chunks of code on the boards; you can mail code to the TA if you want him or her to look at it

7 A FEW NEW TOOLS…

8 The UserForm_Initialize Event UserForm_Initialize is similar to Workbook_Open; it’s an event routine that is called when the form is loaded into memory We used named constants to define the various prices for options; the labels for the buttons and check boxes are completed using these at load time This allows us to provide the information in one place only, so it is easy to change if we need to

9 Formatting We used formatting functions to make our numbers print nicely Format(TIPPERCENT, "Percent") formats the number TIPPERCENT, which is a constant equal to.15, as 15% We also used the “Currency” format. Note: if you bought your computer in another country, it may format in a currency other than dollars. This is OK; you don’t have to change it.

10 Error Handling In a well-written program, user mistakes are caught and the user is given a chance to correct them Often this type of code is a large, even major, part of the program We haven’t done much in this regard yet but we did catch the mistake if no commission option is selected

11 Note error handling in the Else clause If optVanilla.Value = True Then flavorName = "vanilla" flavorPrice = VANILLAPRICE ElseIf optChocolate.Value = True Then flavorName = "chocolate" flavorPrice = CHOCOLATEPRICE ElseIf optStrawberry.Value = True Then flavorName = "strawberry" flavorPrice = STRAWBERRYPRICE Else 'no option chosen MsgBox ("You need to select a flavor") Exit Sub End If


Download ppt "Preparing for Assignment 3. Setup Assignment 3 builds on Assignment 2, and we are using the same basic scenario. Save the spreadsheet you used for Assignment."

Similar presentations


Ads by Google