Private Sub cboSelect_Change()

End Sub

Private Sub cboSelect_Enter()
ListBox1.RowSource = ""
End Sub

Private Sub cmdAdd_Click()
Set Drng = Sheet1.Range("b8")
'move the values without selecting
Drng.End(xlDown).Offset(1, 0).Value = Me.txtSurname.Value
Drng.End(xlDown).Offset(0, 1).Value = Me.txtFirstName.Value
Drng.End(xlDown).Offset(0, 2).Value = Me.txtGrade.Value
Drng.End(xlDown).Offset(0, 3).Value = Me.txtFlight.Value
Drng.End(xlDown).Offset(0, 4).Value = Me.txtElement.Value
Drng.End(xlDown).Offset(0, 5).Value = Me.txtAddress.Value
Drng.End(xlDown).Offset(0, 6).Value = Me.txtPhone.Value
Drng.End(xlDown).Offset(0, 7).Value = Me.txtMobile.Value
Drng.End(xlDown).Offset(0, 8).Value = Me.txtEmail.Value
Drng.End(xlDown).Offset(0, 9).Value = Drng.End(xlDown).Offset(-1, 9).Value + 1
Sortit
End Sub

Private Sub cmdClear_Click()

Me.cboSelect = ""
Me.txtSearch = ""
Me.ListBox1.RowSource = ""
'clear the bottom of the form
Clearlist

End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdContact_Click()
On Error GoTo errhandler:
Set DataSH = Sheet1
DataSH.Range("O8") = Me.cboSelect.Value
DataSH.Range("O9") = Me.txtSearch
    DataSH.Range("B8").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "phonelist!Criteria"), CopyToRange:=Range("phonelist!Extract"), Unique:= _
        False
        ListBox1.RowSource = Sheet1.Range("outdata").Address(external:=True)
Exit Sub
errhandler:
MsgBox "There was an error"
    End Sub

Private Sub cmdDelete_Click()
    On Error GoTo cmdDelete_Click_Error
If txtSurname = "" Then
Call MsgBox("Double Click the contact so it can be deleted", vbInformation, "Delete Contact")
Exit Sub
End If

Select Case MsgBox("You are about to delete a contact." _
                    & vbCrLf & "Do you want to proceed?" _
                    , vbYesNo Or vbQuestion Or vbDefaultButton1, "Are you sure about this?")
    Case vbYes
    Case vbNo
End Select


Set findvalue = Sheet1.Range("z8:h10000").Find(what:=Me.txtID, LookIn:=xlValues)
findvalue.Value = ""
findvalue.Offset(0, -1).Value = ""
findvalue.Offset(0, -2).Value = ""
findvalue.Offset(0, -3).Value = ""
findvalue.Offset(0, -4).Value = ""
findvalue.Offset(0, -5).Value = ""
findvalue.Offset(0, -6).Value = ""
findvalue.Offset(0, -7).Value = ""
findvalue.Offset(0, -8).Value = ""
findvalue.Offset(0, -9).Value = ""
Clearlist
Sortit
    On Error GoTo 0
    Exit Sub
'if error occurs the show me exactly where the error occurs
cmdDelete_Click_Error:

    MsgBox "Error " & "(" & Err.Description & ") in procedure cmdDelete_Click of the Form Phonelist"
End Sub
Sub Clearlist()

Me.txtSurname.Value = ""
Me.txtFirstName.Value = ""
Me.txtGrade.Value = ""
Me.txtFlight.Value = ""
Me.txtElement.Value = ""
Me.txtAddress.Value = ""
Me.txtPhone.Value = ""
Me.txtMobile.Value = ""
Me.txtEmail.Value = ""
Me.txtID.Value = ""

End Sub

Private Sub cmdEdit_Click()
'error handler
    On Error GoTo cmdEdit_Click_Error
'check that there is data to edit
If Me.txtID = "" Then
MsgBox "the fields are not complete", vbInformation, "Edit Contact"
Exit Sub
End If
'find the value in case of duplicates we use an ID
Set findvalue = Sheet1.Range("z8:h10000").Find(what:=Me.txtID, LookIn:=xlValues)
'findvalue.value = Me.txtID "we do not want to edit the ID"
  findvalue.Offset(0, -1).Value = Me.txtEmail.Value
  findvalue.Offset(0, -2).Value = Me.txtMobile.Value
  findvalue.Offset(0, -3).Value = Me.txtPhone.Value
  findvalue.Offset(0, -4).Value = Me.txtElement.Value
  findvalue.Offset(0, -5).Value = Me.txtFlight.Value
  findvalue.Offset(0, -6).Value = Me.txtGrade.Value
  findvalue.Offset(0, -7).Value = Me.txtAddress.Value
  findvalue.Offset(0, -8).Value = Me.txtFirstName.Value
  findvalue.Offset(0, -9).Value = Me.txtSurname.Value
  MsgBox "the contact has been updated", vbInformation, "Edit Contact"

'reset error
    On Error GoTo 0
    Exit Sub
'if error occurs then show me exactly where the error occurs
cmdEdit_Click_Error:

    MsgBox "Error " & Err.Description & ") in procedure cmdEdit_Click of Form Phonelist"
End Sub

Private Sub cmdSet_Click()
'error handler
    On Error GoTo cmdset_Click_Error
'reset the by unload and then reload
Unload Me
PhoneList.Show
'stop edits because we are adding a contact
PhoneList.cmdEdit.Enabled = False
'confirmation "All OK" Message
MsgBox "You can now ADD a contact", vbInformation, "Add New Contact"
'reset Error
    On Error GoTo 0
    Exit Sub
'if error occurs the show me exactly where the error occurs
cmdset_Click_Error:

    MsgBox "Error " & "Err.number & (" & Err.Description & ") in procedure cmdSet_Click of the Form Phonelist"
End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'error handler
    On Error GoTo ListBox1_DblClick_Error
'stop a duplicate from being added
Me.cmdAdd.Enabled = False
'allow editing
Me.cmdEdit.Enabled = True
'send data to the bottom of the form for editing
Me.txtSurname.Value = Me.ListBox1.Value
Me.txtFirstName.Value = Me.ListBox1.Column(1)
Me.txtGrade.Value = Me.ListBox1.Column(2)
Me.txtFlight.Value = Me.ListBox1.Column(3)
Me.txtElement.Value = Me.ListBox1.Column(4)
Me.txtAddress.Value = Me.ListBox1.Column(5)
Me.txtPhone.Value = Me.ListBox1.Column(6)
Me.txtMobile.Value = Me.ListBox1.Column(7)
Me.txtEmail.Value = Me.ListBox1.Column(8)
Me.txtID.Value = Me.ListBox1.Column(9)

    On Error GoTo 0
    Exit Sub
'if error occurs then show me exactl where the error occurs
ListBox1_DblClick_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ListBx1_DblClick of Form Phonelist"
    
End Sub

Private Sub UserForm_Initialize()
Me.cboSelect.List = WorksheetFunction.Transpose(Sheet1.Range("b8:K8"))

End Sub
 
by

Visual basic (VB.net) Online Compiler

Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net. OneCompiler also has reference programs, where you can look for the sample code to get started with.

Read input from STDIN in VB.net

OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.

Public Module Program
	Public Sub Main(args() As string)
	 Dim name as String = Console.ReadLine()    ' Reading input from STDIN
   Console.WriteLine("Hello " & name)           ' Writing output to STDOUT
	End Sub
End Module

About VB.net

Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.

Key Features

  • Beginner's friendly language.
  • Simple and object oriented programming language.
  • User friendly language and easy to develop GUI based applications.

Syntax help

Variables

Variable is a name given to the storage area in order to identify them in our programs.

Simple syntax of Variable declaration is as follows

Dim variableName [ As [ New ] dataType ] [ = initializer ]

Variable initialization

variableName = value

Conditional Statements

1. If

If condition-expression Then 
    'code
End If

2. If-else

If(conditional-expression)Then
   'code if the conditional-expression is true 
Else
  'code if the conditional-expression is false 
End If

3. If-else-if ladder

If(conditional-expression)Then
   'code if the above conditional-expression is true 
Else If(conditional-expression) Then
        'code if the above conditional-expression is true 
    Else
        'code if the above conditional-expression is false 
End If

4. Nested-If

If(conditional-expression)Then
   'code if the above conditional-expression is true
   If(conditional-expression)Then
         'code if the above conditional-expression is true 
   End If
End If

5. Select Case

Select [ Case ] expression
   [ Case expressionlist
      'code ]
   [ Case Else
      'code ]
End Select

Loops

1. For..Next

For counter [ As datatype ] = begin To end [ Step step ]
   'code
   [ Continue For ]
   'code
   [ Exit For ]
   'code
Next [ counter ]

2. For..Each

For Each element [ As datatype ] In group
   'code
   [ Continue For ]
   'code
   [ Exit For ]
   'code
Next [ element ]

3. While

While conditional-expression
   'Code 
   [ Continue While ]
   'Code
   [ Exit While ]
   'Code
End While

4. Do-while

Do { While | Until } conditional-expression
   'Code
   [ Continue Do ]
   'Code
   [ Exit Do ]
   'Code
Loop
Do
   'Code
   [ Continue Do ]
   'Code
   [ Exit Do ]
   'Code
Loop { While | Until } conditional-expression

Procedures

Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

Procedures are of two types.

1. Functions

Functions return a value when they are called.

[accessModifiers] Function functionName [(parameterList)] As returnType
   'code
End Function

2. Sub-Procedures

Sub-procedures are similar to functions but they don't return any value.

Sub ProcedureName (parameterList)
'Code
End Sub