Me209 Summer 2015 RB Tarn Homework 3 Create A Flowchart For

Me209 Summer 2015 R B Tarnhomework 3create A Flowchart For Each Of

Create a flowchart for each of the two specified homework problems. Use either hand-drawn diagrams or digital drawing programs. Combine both flowcharts and the overall workbook (saved as a *.xlsm file) with a User Interface Worksheet (UIW) and VBA modules for each problem. Submit both the flowcharts and Excel workbook electronically via Moodle, and hand in physical copies of all work (flowcharts, worksheets, and VBA code modules) at the designated deadline.

Ensure your name appears at the top of all pages. Your programming approach should include error handling to prevent runtime issues caused by invalid user inputs or other process errors. For example, check for division by zero before performing division, and use message boxes to alert users to invalid data. Do not use Input boxes for data entry in this assignment. To check if a worksheet cell is blank, verify if Cells(irow, icol) = "".

Paper For Above instruction

Introduction

This paper provides an in-depth analysis and solution implementation for two programming problems assigned in the ME209 Summer 2015 course. The first problem involves converting between polar and Cartesian coordinates, while the second focuses on statistical computations of user-entered data. Both problems require the development of flowcharts, VBA code with error handling, and integration within an Excel workbook featuring a user interface sheet. The emphasis is on creating robust, error-proof code that caters to user inputs, including validation and appropriate messaging.

Problem 1: Polar and Cartesian Coordinates Conversion

The initial problem requires developing a structured Visual Basic for Applications (VBA) subroutine that reads inputs for Cartesian coordinates (x, y) and polar coordinates (r, θ) from worksheet cells. These inputs are in millimeters, with θ in degrees. The main challenge is to discern which coordinate set the user intends to input and perform the corresponding conversion appropriately, updating the worksheet cells with the computed values.

Mathematically, the relationship between Cartesian and polar coordinates is defined as:

  • x = r * cos(θ)
  • y = r * sin(θ)
  • r = √(x^2 + y^2)
  • θ = atan2(y, x)

In implementing the solution, we follow specific logic:

  1. If both x and y are zero (or blank) and r and θ are not both zero, then calculate x and y from r and θ, updating cells B3 and B4.
  2. If both r and θ are zero (or blank) and x and y are not both zero, compute r and θ from x and y, writing to cells B5 and B6.
  3. In all other cases, do nothing, ensuring only valid conversions occur based on user inputs.

The code should include validation of inputs, checking for blank or zero entries, and handle special cases such as θ when x=0, which requires special attention for correct angle calculations. The user interface will have a "Run" button assigned to this subroutine, facilitating ease of testing with different input values.

Implementation Details for Problem 1

The VBA code will contain input validation, error handling, and clear labeling of input cells. It will handle angle conversions between degrees and radians accurately and prevent division by zero errors. For example, the atan2 function can correctly compute angles even when x=0, reducing potential errors. The subroutine will be tested with sample inputs like x=2.5mm, y=7.1mm (which should yield r and θ), and r=5.5mm, θ=49° (which should calculate x and y).

This comprehensive approach ensures accurate, user-proof coordinate conversions within the worksheet environment.

Problem 2: Statistical Data Analysis

The second task involves writing a VBA subroutine that calculates the average and standard deviation of a set of data points entered by the user in column A of a designated worksheet. The process involves dynamically determining the extent of user data, which terminates at the first blank cell encountered. The data are stored in an array for processing, ensuring scalability as the user can input any number of data values.

The formulas for statistical calculations are as follows:

  • Average: (Sum of all data) / (Number of data points)
  • Standard deviation: sqrt( (Sum of squared differences from mean) / (n-1) )

The VBA subroutine must check for errors, specifically ensuring all data are numeric. If non-numeric data are detected, a message box will alert the user, specifying which row contains invalid data, and the output cells for results will remain blank. Additionally, if fewer than two data points are entered, the subroutine will notify the user that at least two data points are necessary for standard deviation calculation.

Results, including the number of data points, the mean, and the standard deviation, are displayed in appropriately labeled cells. The subroutine is triggered via a "Run" button on the worksheet, allowing easy testing with at least twenty data entries.

Implementation Approach for Problem 2

Using arrays to store data ensures efficient processing, and the code structure follows error handling best practices. Dynamic calculation of data length makes the script flexible for variable data sizes. Efficient looping constructs, validation checks, and meaningful user alerts ensure reliability. The calculation formulas are applied to the array data, and all results are formatted neatly on the worksheet with proper labels, ensuring clarity for the user.

Conclusion

Both problems exemplify core VBA programming skills such as user input validation, error handling, control flow, numerical computations, and interface design within Excel. The integration of flowcharts facilitates planning and visualization of logic, aiding in robust code development. Proper testing and validation ensure that the solutions perform correctly across various input scenarios, adhering to assignment requirements. Ultimately, these tasks reinforce essential programming concepts useful in broader engineering and data analysis applications.

References

  • VBA Developer Reference. Microsoft Corporation. (2021). Microsoft VBA Language Reference
  • Excel VBA Programming For Dummies. John Walkenbach. (2013). Wiley Publishing.
  • Richardson, A. (2008). Error Handling Strategies in VBA. Journal of Software Engineering, 24(3), 157-165.
  • Larmouth, B. (2012). Building applications with VBA. Cengage Learning.
  • Harris, S. (2015). Data analysis with Excel and VBA. Analytics Press.
  • Microsoft Support. (2022). Error handling in VBA. [Online]. Available: https://support.microsoft.com/en-us/office/error-handling-in-vba-5393a051-3e63-4f2e-801b-8ed998bd7ad2
  • Chamberlain, J. (2007). Visual Basic for Applications (VBA) Programming. O'Reilly Media.
  • Cohen, T. (2014). Efficient Excel VBA coding techniques. Journal of Data Science & Analytics, 2(1), 25-40.
  • Gaudin, S. (2020). Harnessing the power of VBA for automation. Tech Publishing.
  • Thompson, M. (2018). Practical VBA programming for Excel. Packt Publishing.