Visual basics 2012 Can someone please help with the code for
Visual basics 2012 Can someone please help with the code for these two parts
Add a three vertically aligned textboxes.
1) Add a button named “btnOrderEm” to the form that displays the text “&OrderEm.” Write code in the event handler that calls a sub-procedure named “OrderEm,” passing as arguments the values to be reordered. Define a sub-procedure named “OrderEm” that takes three integer parameters and displays the integers in ascending order in a MessageBox. [3 points]
2) Add a button named “btnReset” that displays the text “&Reset.” Write code in the event handler that calls a sub-procedure named “ResetData.” Define a sub-procedure named “ResetData” that takes no parameters and that clears the input text on the form.
Solution
Form1.vb
Public Class Form1
\'Writing a subprocedure for Orderem
Sub OrderEm()
\'Creating variables to hold one of those 3 inputed numbers
Dim smallest As Double = 0
Dim larger As Double = 0
Dim largest As Double = 0
\'Creating a array with those three inputed numbers and sort them
Dim ary As Double() = {CDbl(txtInput1.Text), CDbl(txtInput2.Text), CDbl(txtInput3.Text)}
Array.Sort(ary)
\'Depending on sorted numbers pluging it into variables
smallest = ary(0)
larger = ary(1)
largest = ary(2)
\'Showing the result in messagebox
MessageBox.Show(smallest & \", \" & larger & \", \" & largest)
End Sub
\'Writing a subprocedure for ResetData
Sub ResetData()
For Each TxtBox As Control In Me.Controls
If TypeName(TxtBox) = \"TextBox\" Then
TxtBox.Text = \"\"
End If
txtInput1.Focus()
Next
End Sub
\'Button clicked
Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOrder.Click
\'Making sure that all the data was entered and correct
\'Making sure that all the textboxes are filled
\'Making sure that input isnumeric
If String.IsNullOrEmpty(txtInput1.Text) Or String.IsNullOrEmpty(txtInput2.Text) Or String.IsNullOrEmpty(txtInput1.Text) Then
MessageBox.Show(\"Check the data, all the textboxes should be filled\", \"Error\", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Not IsNumeric(txtInput1.Text) Or Not IsNumeric(txtInput2.Text) Or Not IsNumeric(txtInput1.Text) Then
MessageBox.Show(\"All input should be numbers .\", \"Error\", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
\'Calling a subprocedure OrderEm xwhich will put the numbers in order when the button Order clicked
Call OrderEm()
End Sub
\'Calling a subprocedure ResetData which resets all textbox to empty and sets focus to the firts textbox when button Reset clicked
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
Call ResetData()
End Sub
End Class
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.txtInput1 = New System.Windows.Forms.TextBox()
Me.txtInput2 = New System.Windows.Forms.TextBox()
Me.txtInput3 = New System.Windows.Forms.TextBox()
Me.btnOrder = New System.Windows.Forms.Button()
Me.btnReset = New System.Windows.Forms.Button()
Me.SuspendLayout()
\'
\'txtInput1
\'
Me.txtInput1.Location = New System.Drawing.Point(22, 12)
Me.txtInput1.Name = \"txtInput1\"
Me.txtInput1.Size = New System.Drawing.Size(100, 20)
Me.txtInput1.TabIndex = 0
\'
\'txtInput2
\'
Me.txtInput2.Location = New System.Drawing.Point(22, 58)
Me.txtInput2.Name = \"txtInput2\"
Me.txtInput2.Size = New System.Drawing.Size(100, 20)
Me.txtInput2.TabIndex = 1
\'
\'txtInput3
\'
Me.txtInput3.Location = New System.Drawing.Point(22, 99)
Me.txtInput3.Name = \"txtInput3\"
Me.txtInput3.Size = New System.Drawing.Size(100, 20)
Me.txtInput3.TabIndex = 2
\'
\'btnOrder
\'
Me.btnOrder.Location = New System.Drawing.Point(34, 149)
Me.btnOrder.Name = \"btnOrder\"
Me.btnOrder.Size = New System.Drawing.Size(75, 23)
Me.btnOrder.TabIndex = 3
Me.btnOrder.Text = \"Order\"
Me.btnOrder.UseVisualStyleBackColor = True
\'
\'btnReset
\'
Me.btnReset.Location = New System.Drawing.Point(34, 178)
Me.btnReset.Name = \"btnReset\"
Me.btnReset.Size = New System.Drawing.Size(75, 23)
Me.btnReset.TabIndex = 4
Me.btnReset.Text = \"Reset\"
Me.btnReset.UseVisualStyleBackColor = True
\'
\'Form1
\'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(149, 225)
Me.Controls.Add(Me.btnReset)
Me.Controls.Add(Me.btnOrder)
Me.Controls.Add(Me.txtInput3)
Me.Controls.Add(Me.txtInput2)
Me.Controls.Add(Me.txtInput1)
Me.Name = \"Form1\"
Me.ShowIcon = False
Me.Text = \"Assignment 10\"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents txtInput1 As System.Windows.Forms.TextBox
Friend WithEvents txtInput2 As System.Windows.Forms.TextBox
Friend WithEvents txtInput3 As System.Windows.Forms.TextBox
Friend WithEvents btnOrder As System.Windows.Forms.Button
Friend WithEvents btnReset As System.Windows.Forms.Button
End Class


