Array_lab7 - Lab-7 Arrays Test Problem-1: Understanding...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Lab-7 Arrays Test Problem-1: Understanding simple one dimensional arrays Problem Statement : Design a VB program to compute the areas of “n” number of squares and circles, given their characteristic dimensions (length of the side for squares or radius for circles). The value of “n” and the dimensions are entered in the spreadsheet as show below: Number of squares/circles Dimension Square_areaCircle_area Use EXCEL to create the above spreadsheet. Setup a command button and enter the following code: Option Explicit Option Base 1 Private Sub Mycode_Click() Dim i As Integer, n As Integer, A As Single Dim result1() As Single, result2() As Single n = Cells(2, 1) ReDim result1(n), result2(n) For i = 1 To n Step 1 A = Cells(3 + i, 1) result1(i) = A ^ 2 result2(i) = 3.14 * A ^ 2 Next i For i = 1 To n Step 1 Cells(3 + i, 2) = result1(i) Cells(3 + i, 3) = result2(i) Next i End Sub Run the code and you will see that your spreadsheet will be updated with the data shown below: Number of squares/circles Dimension Square_areaCircle_area 1 1 3.14 2 4 12.56 3 9 28.26 4 16 50.24 5 25 78.5 6 36 113.04
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 This example is identical to problem-4, except we used one-dimensional arrays results1() and results2() to first store the values internally and then we output the results after finishing all the computations. Arrays Test -2: Working with one-dimensional array variables and multiple subroutines Objectives: Design a VB program to compute the areas of “n” number of squares and circles, given their characteristic dimensions (length of the side for squares or radius for circles). Use multiple subroutines and array variable to complete all the computations and then output the computed values. The value of “n” and the dimensions are entered in the spreadsheet as show below: Number of squares/circles Dimension Square_areaCircle_area Use EXCEL to create the above spreadsheet. Set up a command button to enter the following code: Option Explicit Option Base 1 Private Sub Mycode_Click() Dim i As Integer, n As Integer Dim A() As Single, result1() As Single, result2() As Single n = Cells(2, 1) ReDim A(n) As Single, result1(n) As Single, result2(n) As Single For i = 1 To n Step 1 A(i) = Cells(3 + i, 1) Next i Call Square(n, A(), result1()) Call Circ(n, A(), result2()) For i = 1 To n Step 1 Cells(3 + i, 2) = result1(i) Cells(3 + i, 3) = result2(i) Next i End Sub Sub Square(n as integer, AA() as single, result() as single) Dim i As Integer For i = 1 To n result(i) = AA(i) ^ 2 Next i End Sub Sub Circ(n as integer, AB() as single, result() as single) Dim i As Integer For i = 1 To n result(i) = 3.14 * AB(i) ^ 2
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course CE 3010 taught by Professor Clement during the Fall '09 term at Auburn University.

Page1 / 7

Array_lab7 - Lab-7 Arrays Test Problem-1: Understanding...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online