Question

Microsoft Excel VBA (Visual Basic for Applications) Programming Language Objectives: Create an array and redim it...

Microsoft Excel VBA (Visual Basic for Applications) Programming Language

Objectives: Create an array and redim it to a size equal to an assigned value of a variable, populate the array with a series of random numbers, output the array to a message box and to a worksheet.

Instructions:

- Review the variables already declared. You won't need others.

- See comments in the code that will act as your guide. Add new code directly after each comment.

- Assign a value of intRandom. (start with 20, change it later, if desired)

- ReDim the array to be of a size equal to the previous variable.

- Fill the array with random numbers using RND function.

- Loop through the array and create a message string.

- Also, create a title that pulls the value of the sixth elements.

- Display the title and message in a Msgbox.

- Output the array to the output sheet with index value in column A and the random number in column B.

Lines of code needed: about 16 including 3 for each of 3 loops

The message box should like like the following:

0?ui=2&ik=186360e1dd&attid=0.2&permmsgid

________________________________________________________

Option Explicit

Option Base 1

' ******** DSS 620 TEMPLATE ---- Created by John A. Michl [email protected] ********

' **

' **    Module 4        Exercise 2

' **    Template Revision: 01/12/2018 v1.1 by John A. Michl

' **    Note:   Professor's comments preceeded by '[

' **            Instructions / hints preceeded by '>>

' **    Student comments should use apostrophe only

' **

' **    Assignment modified by STUDENT NAME on DATE

' **

' ******************************************************************************

Sub RandomList()

    ' all variables needed for Part A have been declared

    Dim i As Integer        ' number of random numbers to make

     Dim intRandom As Integer ' number of random numbers to make

     Dim arrRandom() As Single    ' array in which to store numbers

    Dim strMsg As String

     Dim strTitle As String

   

     Randomize   ' this initializes the random number generator

   

     Debug.Print Rnd   ' just to show how easy it is to create a

   

     Worksheets("Output").Range("A:B").Clear         ' remove old results

   

     ']vvvvv Student code below vvvvvv

   

     '] assign a value to intRandom

   

    

     '] redim the array to be the appropriate size

   

    

     '] fill the array with random numbers using a loop

       

    

    

     '] create the list of numbers for the message string using a loop

     '] be sure to include both the index value i and the contents of the array

  

    

     '] create the message title to show the random number in position 6 of the array

     '] see the screen shot but note the random numbers will be different

   

    

    

     '] display the message box

   

    

     '] output the array to the output worksheet showing the index number in

     '] column A and the random number in column B

   

    

    

    '^^^^ Student code above

End Sub

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sub RandomList()

' all variables needed for Part A have been declared

Dim i As Integer ' number of random numbers to make
Dim intRandom As Integer ' number of random numbers to make
Dim arrRandom() As Single ' array in which to store numbers
Dim strMsg As String
Dim strTitle As String

Randomize ' this initializes the random number generator

Debug.Print Rnd ' just to show how easy it is to create a

Worksheets("Output").Range("A:B").Clear ' remove old results

']vvvvv Student code below vvvvvv

'] assign a value to intRandom
intRandom = 20

'] redim the array to be the appropriate size
ReDim arrRandom(intRandom)

'] fill the array with random numbers using a loop
For i = 1 To intRandom
arrRandom(i - 1) = Int((25 - 10 + 1) * Rnd + 10)
Next i


'] create the list of numbers for the message string using a loop
'] be sure to include both the index value i and the contents of the array
For i = 1 To intRandom
strMsg = strMg + Str(arrRandom(i - 1)) + " "
Next i


'] create the message title to show the random number in position 6 of the array
'] see the screen shot but note the random numbers will be different
strTitle = Str(arrRandom(6))

'] display the message box
MsgBox strMsg, vbInformation, strTitle


'] output the array to the output worksheet showing the index number in
'] column A and the random number in column B
For i = 1 To intRandom
Sheets("Output").Cells(i, 1) = i
Sheets("Output").Cells(i, 2) = arrRandom(i - 1)
Next i

'^^^^ Student code above

End Sub

________________________________________________________________________________________________

image screenshot

Book1 Microsoft Excel Home Insert Page LayoutFomulas Data Review View Developer 齒E-aaRecord Mae References 昂 KE Properties E

thank you !

Add a comment
Know the answer?
Add Answer to:
Microsoft Excel VBA (Visual Basic for Applications) Programming Language Objectives: Create an array and redim it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone please help, third time I'm asking. I need a basic javascript with no push...

    Can someone please help, third time I'm asking. I need a basic javascript with no push or splice command. Please don't post a picture of the code,because my vision is poor and I won't be able to see it. Also, I need breakdown of what's in HTMLand what' s in javascript. All requirements are below. Thanks for your help. This is a 2 part assignment, but both parts can be completed in one program. Also, please follow ALL Required Programming...

  • Variable Size Array with Classes, Testing. Study Code and Object Definition Windows of Microsoft ...

    Variable Size Array with Classes, Testing. Study Code and Object Definition Windows of Microsoft Visual Studio described here. As you work on the below project, demonstrate to the instructor the usage of this feature. Create a project titled Lab11_VarArrayTest. Implement the dynamically expanding and contracting array of doubles described in the previous lab as a class. You should use this class definition. The class attributes are a pointer to the dynamically allocated array dAarray and the array size size This...

  • Must be done in C# please! Thanks! In this assignment you will create a program named...

    Must be done in C# please! Thanks! In this assignment you will create a program named Test Scores that displays the average of all tests; average midterm score; average final score; and displays the midterm or final score of a particular student. Create a class level two dimensional integer array named Grades initialized with the following data: 897 242 301 987 116 450 865 128 992 109 88 75 94 70 90 87 81 79 97 79 78 80 92...

  • Create a program that uses a Jagged Array. The program will create an array with 50...

    Create a program that uses a Jagged Array. The program will create an array with 50 rows. Each of the values for each element of the array will be randomly generated. The random values will be between 1 and 20. Depending on the value generated for each row, you will create an array with that number of columns for that row. Each column created will contain the value to the left plus 1. After you create and populate the entire...

  • Create a Raptor Flowchart and Pseudocode for the following: That searches an array of size 15...

    Create a Raptor Flowchart and Pseudocode for the following: That searches an array of size 15 that holds a collection of numbers, for the value 7. First we take input from the user to fill each element in the array. Then we search the array for value 7. If value 7 is not found we output: "Value 7 is not contained in array[]", otherwise if the value 7 is found output: "Value 7 is contained in array[] at index" and...

  • Visual Basic: Create an application that simulates a tic tac toe game. The form uses 9...

    Visual Basic: Create an application that simulates a tic tac toe game. The form uses 9 large labels to display the x's and o's. The application should use a two dimensional integer array to simulate the game board in memory. When the user clicks the "New Game" button the application should step throguh the array storing a random number of 0 to 1 in each element. The numer 0 represent the letter o and the number 1 reprsents the letter...

  • Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...

    Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort    Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...

  • Write a c++ program that does the following Create an integer array of size 30. Assign...

    Write a c++ program that does the following Create an integer array of size 30. Assign -1 to each location in the array indicating that the array is empty. Populate half of the array with random integer values between 100 and 500 inclusive. Use the following formula in order to hash and store each number in its proper position/location. Generated Number Table Size: Should a collision occurs, use linear probing to find next available position location. Use the following probing...

  • Array processing Create a program that processes two-dimensional array according to task variant Additional requirements 1....

    Array processing Create a program that processes two-dimensional array according to task variant Additional requirements 1. 2. 3. 4. Input dimensions of array form keyboard (use dynamic memory allocation) Fill array with random numbers in range R. Processing of array should be implemented as function (using indices). Displaying the content of array should be implemented as function (using pointers) 5 12 8 2 8 3 3 16 1 22 215 34 0 11 88 13 22 6 5 81 76...

  • Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb...

    Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb Public Class frmNewItem Public InvItem As InvItem Private Sub frmNewItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.LoadComboBox() End Sub Private Sub LoadComboBox() cboSizeOrManufacturer.Items.Clear() If rdoPlant.Checked Then cboSizeOrManufacturer.Items.Add("1 gallon") cboSizeOrManufacturer.Items.Add("5 gallon") cboSizeOrManufacturer.Items.Add("15 gallon") cboSizeOrManufacturer.Items.Add("24-inch box") cboSizeOrManufacturer.Items.Add("36-inch box") Else cboSizeOrManufacturer.Items.Add("Bayer") cboSizeOrManufacturer.Items.Add("Jobe's") cboSizeOrManufacturer.Items.Add("Ortho") cboSizeOrManufacturer.Items.Add("Roundup") cboSizeOrManufacturer.Items.Add("Scotts") End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then InvItem = New InvItem(CInt(txtItemNo.Text),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT