In: Computer Science
Using Visual Basic 2017,
Create a form with two textboxes and one button. A user enters the course she is taking in the first text box and then clicks on the button. Then if the user entered "Program Language" in the first text box, the second text box will show "Awesome pick!". If the user entered something else, the text box shows "Ok."
Please write the correct code.
'Vb Code
'Form Interface
'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.txtInput = New System.Windows.Forms.TextBox()
Me.txtOutput = New System.Windows.Forms.TextBox()
Me.btnDisplay = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'txtInput
'
Me.txtInput.Location = New System.Drawing.Point(102, 33)
Me.txtInput.Name = "txtInput"
Me.txtInput.Size = New System.Drawing.Size(100, 20)
Me.txtInput.TabIndex = 0
'
'txtOutput
'
Me.txtOutput.Location = New System.Drawing.Point(102, 93)
Me.txtOutput.Name = "txtOutput"
Me.txtOutput.Size = New System.Drawing.Size(100, 20)
Me.txtOutput.TabIndex = 1
'
'btnDisplay
'
Me.btnDisplay.Location = New System.Drawing.Point(102, 158)
Me.btnDisplay.Name = "btnDisplay"
Me.btnDisplay.Size = New System.Drawing.Size(100, 49)
Me.btnDisplay.TabIndex = 2
Me.btnDisplay.Text = "Click Me"
Me.btnDisplay.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(21, 36)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(68, 13)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Enter Course"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(21, 96)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(50, 13)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Message"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(288, 245)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnDisplay)
Me.Controls.Add(Me.txtOutput)
Me.Controls.Add(Me.txtInput)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents txtInput As TextBox
Friend WithEvents txtOutput As TextBox
Friend WithEvents btnDisplay As Button
Friend WithEvents Label1 As Label
Friend WithEvents Label2 As Label
End Class
'Form1.vb
Public Class Form1
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
' if user does not enter any value
If txtInput.Text = "" Then
txtOutput.Text = "Please enter course"
Else
' compare course name(case insensitive)
If txtInput.Text.ToLower() = "program language" Then
txtOutput.Text = "Awesome pick!"
Else
txtOutput.Text = "Ok"
End If
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' make the output text box read only
txtOutput.ReadOnly = True
End Sub
End Class
'Output
//If you need any help regarding this solution...... please leave a comment..... thanks