There is one button and one listbox on the form.
Adding the names and surnames of personnel younger than 35 years old into the listbox when the button is clicked.
is requested.
Using object-oriented programming techniques the required class (with methods) and from that class
code the object to be created.
Thanks in advance to those who help.
<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.btnAdd = New System.Windows.Forms.Button()
Me.lstPersonnel = New System.Windows.Forms.ListBox()
Me.SuspendLayout()
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(12, 27)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(418, 23)
Me.btnAdd.TabIndex = 0
Me.btnAdd.Text = "Add"
Me.btnAdd.UseVisualStyleBackColor = True
'
'lstPersonnel
'
Me.lstPersonnel.FormattingEnabled = True
Me.lstPersonnel.Location = New System.Drawing.Point(12, 70)
Me.lstPersonnel.Name = "lstPersonnel"
Me.lstPersonnel.Size = New System.Drawing.Size(418, 95)
Me.lstPersonnel.TabIndex = 1
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(452, 189)
Me.Controls.Add(Me.lstPersonnel)
Me.Controls.Add(Me.btnAdd)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Personnel Younger 35"
Me.ResumeLayout(False)
End Sub
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents lstPersonnel As System.Windows.Forms.ListBox
End Class
Public Class Form1
Class Personnel
Public name As String
Public surname As String
Public age As Integer
Public Overrides Function ToString() As String
Return name + " " + surname
End Function
End Class
''' <summary>
''' Add button
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim _Personnel As New Personnel()
_Personnel.age = Integer.Parse(InputBox("Enter age: "))
If (_Personnel.age < 35) Then
_Personnel.name = InputBox("Enter name: ")
_Personnel.surname = InputBox("Enter surname: ")
lstPersonnel.Items.Add(_Personnel.ToString())
End If
End Sub
End Class
Comments
Leave a comment