For Visual Basic: Write an event procedure with the header Private Sub btnComput
ID: 641330 • Letter: F
Question
For Visual Basic: Write an event procedure with the header Private Sub btnCompute_Click(...) Handles btnCompute.Click, and having one line for each step. Lines that display data should use the given variable names. The following steps calculate the amount of a stock purchase:
(a) Declare all variables as type Double.
(b) Assign the value 25.625 to the variable costPerShare.
(c) Assign the value 400 to the variable numberOfShares.
(d) Assign the product of costPerShare and numberOfShares to the variable amount.
(e) Display the value of the variable amount in a list box.
Explanation / Answer
Create a new Standard Exe project in VB. A default form named Form1 is automatically created.
Place a Command button on the form.
Right click on the command button->Go to properties.
Change caption to Compute Amount.
Change name to btnCompute.
Place a list box on the form.
Double-click on the Compute Amount button to open the code window.
Go to the General Declaration section of Form1 and enter the following code:
Dim costPerShare, numberOfShares, amount As Double
Write the following code between the Private Sub btnCompute_Click() and the End Sub command:
costPerShare = 25.625
numberOfShares = 400
amount = costPerShare * numberOfShares
List1.AddItem (amount)
Execute the VB program and press the Compute Amount button. The amount will be displayed in the list box.
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.