Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Visual Basic programming Make sure to add top level comments and use VB Data Typ

ID: 3685341 • Letter: V

Question

Visual Basic programming

Make sure to add top level comments and use VB Data Type conversion functions whenever needed.

Create a new Windows Forms application. On the form, add three textboxes where the user enters numbers between 0-100. Code to calculate the result should be added as the click event handler of a button, Mean. The Mean Click event handler code should use this logic:

the output is the average of all three textbox entries, if the average is between 0-100. Show the output in a messagebox.

If the output is >100 or <0, that means that one or more of the textbox entries is not within 0-100 range.

ONLY if, the output is not within range, check if the first textbox entry is not within range. If so, show an error message is a messagebox, and clear that textbox from its content. The user should type a new entry then click the Mean button.

If the first textbox is within range, then only in that case, check if the second textbox is not within range an repeat the same procedure of the previous bullet (show message, clear, ...). Repeat the same steps if needed for the third textbox.

All input variables should be of the Integer data type. No other code besides the Mean calculate event handler is to be written.

All codes written must implement Exception Handling using an applicable Catch clause in addition to the Catch-all phrase. This means EH should handle errors caused by: 1. not entering numbers, 2. entering too big numbers (e.g. 20Billion), and 3. all other errors. Hence you should have three Catch clauses. See slides of unit 3 for details.

Explanation / Answer

Please Go throught the bellow link and download the zip file and run te application plz let me know your comments.

https://we.tl/SQc1AO4t9X

form.design

<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.button1 = New System.Windows.Forms.Button()
Me.textMean = New System.Windows.Forms.TextBox()
Me.label4 = New System.Windows.Forms.Label()
Me.textThirdNumber = New System.Windows.Forms.TextBox()
Me.label3 = New System.Windows.Forms.Label()
Me.textSecondNumber = New System.Windows.Forms.TextBox()
Me.label2 = New System.Windows.Forms.Label()
Me.textFirstNumber = New System.Windows.Forms.TextBox()
Me.label1 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'button1
'
Me.button1.Location = New System.Drawing.Point(213, 195)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(100, 23)
Me.button1.TabIndex = 17
Me.button1.Text = "Calculate Mean"
Me.button1.UseVisualStyleBackColor = True
'
'textMean
'
Me.textMean.Location = New System.Drawing.Point(213, 148)
Me.textMean.Name = "textMean"
Me.textMean.ReadOnly = True
Me.textMean.Size = New System.Drawing.Size(100, 20)
Me.textMean.TabIndex = 16
'
'label4
'
Me.label4.AutoSize = True
Me.label4.Location = New System.Drawing.Point(96, 151)
Me.label4.Name = "label4"
Me.label4.Size = New System.Drawing.Size(64, 13)
Me.label4.TabIndex = 15
Me.label4.Text = "Mean Value"
'
'textThirdNumber
'
Me.textThirdNumber.Location = New System.Drawing.Point(213, 111)
Me.textThirdNumber.MaxLength = 3
Me.textThirdNumber.Name = "textThirdNumber"
Me.textThirdNumber.Size = New System.Drawing.Size(100, 20)
Me.textThirdNumber.TabIndex = 14
'
'label3
'
Me.label3.AutoSize = True
Me.label3.Location = New System.Drawing.Point(96, 114)
Me.label3.Name = "label3"
Me.label3.Size = New System.Drawing.Size(99, 13)
Me.label3.TabIndex = 13
Me.label3.Text = "Enter Third Number"
'
'textSecondNumber
'
Me.textSecondNumber.Location = New System.Drawing.Point(213, 74)
Me.textSecondNumber.MaxLength = 3
Me.textSecondNumber.Name = "textSecondNumber"
Me.textSecondNumber.Size = New System.Drawing.Size(100, 20)
Me.textSecondNumber.TabIndex = 12
'
'label2
'
Me.label2.AutoSize = True
Me.label2.Location = New System.Drawing.Point(96, 77)
Me.label2.Name = "label2"
Me.label2.Size = New System.Drawing.Size(112, 13)
Me.label2.TabIndex = 11
Me.label2.Text = "Enter Second Number"
'
'textFirstNumber
'
Me.textFirstNumber.Location = New System.Drawing.Point(213, 35)
Me.textFirstNumber.MaxLength = 3
Me.textFirstNumber.Name = "textFirstNumber"
Me.textFirstNumber.Size = New System.Drawing.Size(100, 20)
Me.textFirstNumber.TabIndex = 10
'
'label1
'
Me.label1.AutoSize = True
Me.label1.Location = New System.Drawing.Point(96, 38)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(94, 13)
Me.label1.TabIndex = 9
Me.label1.Text = "Enter First Number"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(448, 262)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.textMean)
Me.Controls.Add(Me.label4)
Me.Controls.Add(Me.textThirdNumber)
Me.Controls.Add(Me.label3)
Me.Controls.Add(Me.textSecondNumber)
Me.Controls.Add(Me.label2)
Me.Controls.Add(Me.textFirstNumber)
Me.Controls.Add(Me.label1)
Me.Name = "Form1"
Me.Text = "Calculate Mean"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Private WithEvents button1 As System.Windows.Forms.Button
Private WithEvents textMean As System.Windows.Forms.TextBox
Private WithEvents label4 As System.Windows.Forms.Label
Private WithEvents textThirdNumber As System.Windows.Forms.TextBox
Private WithEvents label3 As System.Windows.Forms.Label
Private WithEvents textSecondNumber As System.Windows.Forms.TextBox
Private WithEvents label2 As System.Windows.Forms.Label
Private WithEvents textFirstNumber As System.Windows.Forms.TextBox
Private WithEvents label1 As System.Windows.Forms.Label

End Class

Form.cs code

Imports System.Globalization
Public Class Form1
Dim firstValue As Double, secondValue As Double, thirdValue As Double, calMean As Double

Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
Try
If textFirstNumber.Text <> "" Then
If textSecondNumber.Text <> "" Then
If textThirdNumber.Text <> "" Then
firstValue = Convert.ToDouble(textFirstNumber.Text)
firstValue = Convert.ToDouble(textFirstNumber.Text)
secondValue = Convert.ToDouble(textSecondNumber.Text)
thirdValue = Convert.ToDouble(textThirdNumber.Text)
If firstValue >= 0 AndAlso firstValue <= 100 Then

If secondValue >= 0 AndAlso secondValue <= 100 Then
If thirdValue >= 0 AndAlso thirdValue <= 100 Then
calMean = firstValue + secondValue + thirdValue
calMean = calMean / 3
textMean.Text = Addingcomma(calMean)
Else
MessageBox.Show("Enter third number value between 0-100")
textThirdNumber.Focus()
textThirdNumber.Text = ""

End If
Else
MessageBox.Show("Enter second number value between 0-100")
textSecondNumber.Focus()
textSecondNumber.Text = ""
End If
Else
MessageBox.Show("Enter first number value between 0-100")
textFirstNumber.Focus()
textFirstNumber.Text = ""

End If
Else
MessageBox.Show("Enter third number Value")
textThirdNumber.Focus()
End If
Else
MessageBox.Show("Enter Second number Value")
textSecondNumber.Focus()
End If
Else
MessageBox.Show("Enter first number Value")
textFirstNumber.Focus()
End If
Catch EX As Exception
MessageBox.Show(EX.Message.ToString())
End Try

End Sub

Private Sub textFirstNumber_KeyPress(sender As Object, e As KeyPressEventArgs) Handles textFirstNumber.KeyPress
OnlyAcceptNumber(e)
End Sub


Private Sub textSecondNumber_KeyPress(sender As Object, e As KeyPressEventArgs) Handles textSecondNumber.KeyPress
OnlyAcceptNumber(e)
End Sub

Private Sub textThirdNumber_KeyPress(sender As Object, e As KeyPressEventArgs) Handles textThirdNumber.KeyPress
OnlyAcceptNumber(e)
End Sub
Private Shared Sub OnlyAcceptNumber(e As KeyPressEventArgs)
Try
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) Then
e.Handled = True
End If
Catch EX As Exception
MessageBox.Show(EX.Message.ToString())
End Try
End Sub
Private Shared Function Addingcomma(totaltax As Double) As String
Dim d As Double = totaltax
Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat
Return totaltax.ToString("N", CultureInfo.InvariantCulture)
End Function
End Class