Question

In: Computer Science

Hello, this problem is in the book Microsoft Visual Basic 2015 RELOADED, so you can see...

Hello, this problem is in the book Microsoft Visual Basic 2015 RELOADED, so you can see the problem in chapter 4, case project Multiplication Practice on page 227. Also, I am new to this so I started from chapter 1 and am using Microsoft Visual Studio 2015 to code. Here is the problem: ________________________ Create an application that displays two random integers from 1 through 10 in the interface. The application should allow the user to enter the product of both numbers. It then should check whether the user’s answer is correct. Display an appropriate message when the answer is correct in a Label control. Also display an appropriate message when the answer is incorrect in a Label control. ________________________ So far my design view includes 2 buttons, 1 for the random number generator and 1 that is used as the Answer, when the answer button is pushed, either "Correct!" or "Incorrect" will show in the message Label. Also has 2 text boxes, 1 for each random number generated. Thank you! (Zak 227) Zak, Diane. Microsoft Visual Basic 2015: RELOADED, 6th Edition.

Solutions

Expert Solution

Create a new VB windows application with the name ProductOfNumbers. Add the below code in Form1

Form1.Designer.vb

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.txtNumber1 = New System.Windows.Forms.TextBox()
Me.txtNumber2 = New System.Windows.Forms.TextBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.txtproduct = New System.Windows.Forms.TextBox()
Me.btnGenerate = New System.Windows.Forms.Button()
Me.btnAnswer = New System.Windows.Forms.Button()
Me.lblMessage = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(39, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(53, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Number 1"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(39, 65)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(53, 13)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Number 2"
'
'txtNumber1
'
Me.txtNumber1.Location = New System.Drawing.Point(137, 21)
Me.txtNumber1.Name = "txtNumber1"
Me.txtNumber1.Size = New System.Drawing.Size(100, 20)
Me.txtNumber1.TabIndex = 2
'
'txtNumber2
'
Me.txtNumber2.Location = New System.Drawing.Point(137, 58)
Me.txtNumber2.Name = "txtNumber2"
Me.txtNumber2.Size = New System.Drawing.Size(100, 20)
Me.txtNumber2.TabIndex = 3
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(12, 102)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(106, 13)
Me.Label3.TabIndex = 4
Me.Label3.Text = "What is the product?"
'
'txtproduct
'
Me.txtproduct.Location = New System.Drawing.Point(137, 95)
Me.txtproduct.Name = "txtproduct"
Me.txtproduct.Size = New System.Drawing.Size(100, 20)
Me.txtproduct.TabIndex = 5
'
'btnGenerate
'
Me.btnGenerate.Location = New System.Drawing.Point(17, 177)
Me.btnGenerate.Name = "btnGenerate"
Me.btnGenerate.Size = New System.Drawing.Size(113, 23)
Me.btnGenerate.TabIndex = 6
Me.btnGenerate.Text = "Generate Numbers"
Me.btnGenerate.UseVisualStyleBackColor = True
'
'btnAnswer
'
Me.btnAnswer.Location = New System.Drawing.Point(162, 177)
Me.btnAnswer.Name = "btnAnswer"
Me.btnAnswer.Size = New System.Drawing.Size(75, 23)
Me.btnAnswer.TabIndex = 7
Me.btnAnswer.Text = "Answer"
Me.btnAnswer.UseVisualStyleBackColor = True
'
'lblMessage
'
Me.lblMessage.AutoSize = True
Me.lblMessage.Location = New System.Drawing.Point(42, 139)
Me.lblMessage.Name = "lblMessage"
Me.lblMessage.Size = New System.Drawing.Size(0, 13)
Me.lblMessage.TabIndex = 8
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(297, 235)
Me.Controls.Add(Me.lblMessage)
Me.Controls.Add(Me.btnAnswer)
Me.Controls.Add(Me.btnGenerate)
Me.Controls.Add(Me.txtproduct)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtNumber2)
Me.Controls.Add(Me.txtNumber1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Product Of Numbers"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtNumber1 As System.Windows.Forms.TextBox
Friend WithEvents txtNumber2 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtproduct As System.Windows.Forms.TextBox
Friend WithEvents btnGenerate As System.Windows.Forms.Button
Friend WithEvents btnAnswer As System.Windows.Forms.Button
Friend WithEvents lblMessage As System.Windows.Forms.Label

End Class

Form1.vb

Public Class Form1

Private Sub btnGenerate_Click(sender As System.Object, e As System.EventArgs) Handles btnGenerate.Click
lblMessage.Text = ""
txtproduct.Text = ""
'generate two random numbers between 1 and 10
Dim randomNumber1 As Integer = CInt(Int((10 * Rnd()) + 1))
Dim randomNumber2 As Integer = CInt(Int((10 * Rnd()) + 1))

'display the random numbers in the textboxes
txtNumber1.Text = randomNumber1.ToString()
txtNumber2.Text = randomNumber2.ToString()
End Sub

Private Sub btnAnswer_Click(sender As System.Object, e As System.EventArgs) Handles btnAnswer.Click
'if the answer provided is empty, the display a error message
If txtproduct.Text.Trim() = "" Then
lblMessage.Text = "Enter your answer..."
Else
'else
'get the answer provided by the user into an integer variable product
Dim product As Integer = CInt(txtproduct.Text)

''get the numbers generated into an integer variables randomNumber1 and randomNumber2
Dim randomNumber1 As Integer = CInt(txtNumber1.Text.Trim())
Dim randomNumber2 As Integer = CInt(txtNumber2.Text.Trim())

'check if answer provided is correct
If product = randomNumber1 * randomNumber2 Then
'if correct display correct
lblMessage.Text = "Correct!"
Else
'else display incorrect
lblMessage.Text = "Incorrect"
End If
End If

End Sub
End Class

Sample screen:


Related Solutions

Programming with Microsoft Visual Basic 2017: Discuss the ORDER BY clause in the SELECT statement and...
Programming with Microsoft Visual Basic 2017: Discuss the ORDER BY clause in the SELECT statement and how that can help simplify the data retrieved by the query.
how can i get the code for this problem in visual basic? Create a Windows Forms...
how can i get the code for this problem in visual basic? Create a Windows Forms applications called ISP (Internet Service Provider) Project. You must enter the number of hours for the month and select your desire ISP package. An ISP has three different subscription packages for it's customers: Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2 per hours. Package B: For $13.95 per month 20 hours of access are provided. Additional...
Classical Mechanics problem: See if you can prove the so-called virial theorem. This is a statement...
Classical Mechanics problem: See if you can prove the so-called virial theorem. This is a statement that relates the average kinetic energy of a stable system to the potential energy of the system. It applies when the force between two particles of the system has a corresponding potentual energy U of the form U = kr^n, where r is the separation of the particles and n is some real number. So, suppose a mass m moves in a circular orbit...
Hello - can you assist with this problem please: You have been assigned to be the...
Hello - can you assist with this problem please: You have been assigned to be the audit senior for the Wine Emporium.  Based on the client's industry, you have set the inherent risk as low. You are also setting the control risk as low given that the owners of the Wine Emporium, Paul and Linda, have put many robust controls in place since buying the Emporium. You also had good success in auditing controls as well as ending financial statement balances...
You see an advertisement in a book that shows how you can make a million dollars...
You see an advertisement in a book that shows how you can make a million dollars by investing in the stock market with little or no risk and very little investment. Do you buy the book? Why or why not? If you would buy the book, consider how much you would be willing to pay.
You see an advertisement in a book that shows how you can make a million dollars...
You see an advertisement in a book that shows how you can make a million dollars by investing in the stock market with little or no risk and very little investment. Do you buy the book? Why or why not? If you would buy the book, consider how much you would be willing to pay.
As a group of engineers with basic Visual Basic skills, you are asked to provide your...
As a group of engineers with basic Visual Basic skills, you are asked to provide your client with a user-friendly macro-enabled Excel spreadsheet that can be used to calculate the deflection and bending moment of a simply supported beam and a cantilever beam. The spreadsheet will provide a user-friendly interface to allow the client to: i) define the type of beam (i.e. a simply supported beam or a cantilever beam); ii) define cross sectional properties of a given beam structure;...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
Complete this programming problem in this assignment by using Microsoft Visual Studio Suite. Compile your solutions...
Complete this programming problem in this assignment by using Microsoft Visual Studio Suite. Compile your solutions for each problem solved in a Word or Google document which includes (a) the pseudocode, (b) the C# codes and (c) the execution result (screen capture just the answer part using Snipping Tool, avoiding non-related or blank spaces). Notice for readability, that the (a) & (b) are in text mode and the (c) is in image mode. Use proper titles and wording in the...
After downloading the workbook example source-code for Microsoft Visual Studio 2015-2017 Community Ed., and installing, configuring,...
After downloading the workbook example source-code for Microsoft Visual Studio 2015-2017 Community Ed., and installing, configuring, and running Visual Studio with ASP.NET developers kit, develop and construct an APA formatted paper (also use LIRN (or JSTOR), Internet, and the textbook) that provides a detailed analysis of the following concepts: The importance and proper of data validation for applications The use of state(s), object(s) and their relationship to ASP.NET Strategies for the use and implementation of master pages to enhance content...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT