In: Computer Science
NOTE: This is done using Visual Basic.
Create an application named You Do It 1. Add a text box, a label, and a button to the form. The button’s Click event procedure should store the contents of the text box in a Double variable named dblCost. It then should display the variable’s contents in the label. Enter the three Option statements above the Public Class clause in the Code Editor window, and then code the procedure. Save the solution and then start and test the application. Close the solution.
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new Windows Forms Application in VB is created using Visual Studio 2017 with name "YouDoIt".This application contains a form with name "Form1.vb".Below are the files associated with form1.
1.Form1.vb[Design]
2.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.txtContents = New System.Windows.Forms.TextBox()
Me.lblContents = New System.Windows.Forms.Label()
Me.btnContents = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'txtContents
'
Me.txtContents.Font = New System.Drawing.Font("Microsoft Sans
Serif", 12.0!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtContents.Location = New System.Drawing.Point(42, 22)
Me.txtContents.Name = "txtContents"
Me.txtContents.Size = New System.Drawing.Size(169, 26)
Me.txtContents.TabIndex = 0
'
'lblContents
'
Me.lblContents.AutoSize = True
Me.lblContents.Location = New System.Drawing.Point(111, 121)
Me.lblContents.Name = "lblContents"
Me.lblContents.Size = New System.Drawing.Size(0, 13)
Me.lblContents.TabIndex = 1
'
'btnContents
'
Me.btnContents.Location = New System.Drawing.Point(72, 66)
Me.btnContents.Name = "btnContents"
Me.btnContents.Size = New System.Drawing.Size(114, 23)
Me.btnContents.TabIndex = 2
Me.btnContents.Text = "&Display Contents"
Me.btnContents.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(275, 167)
Me.Controls.Add(Me.btnContents)
Me.Controls.Add(Me.lblContents)
Me.Controls.Add(Me.txtContents)
Me.Name = "Form1"
Me.Text = "You Do It"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents txtContents As TextBox
Friend WithEvents lblContents As Label
Friend WithEvents btnContents As Button
End Class
3.Form1.vb
'three Option statements
Option Explicit On
Option Strict On
Option Compare Binary
Public Class Form1
Private Sub btnContents_Click(sender As Object, e As EventArgs)
Handles btnContents.Click
'declaring variable of type double
Dim dblCost As Double
'taking text entered by user and assign to the variable
dblCost
dblCost = Double.Parse(txtContents.Text)
'display variable’s contents in the label
lblContents.Text = dblCost.ToString()
End Sub
End Class
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :
Screen 2:Enter contents and click on button to get the contents on the label
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.