Imports System.Data.SqlClient
Imports System.Data
Imports System.IO
Imports System.Configuration
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Net.Mail
Imports System.Security.Cryptography.X509Certificates
Imports System.Net.Security
Public Class frmProcess
Public Shared XLconstr As String
Public Shared XLcmd As New SqlCommand
Public Shared XLcon As New SqlConnection
Public Shared XLadap As New SqlDataAdapter(XLcmd)
Public Shared XLcmdstr As String 
Public Shared XLds As New dataset
Public Shared QTYconstr As String
Public Shared QTYcmd As New SqlCommand
Public Shared QTYcon As New SqlConnection
Public Shared QTYadap As New SqlDataAdapter(QTYcmd)
Public Shared QTYcmdstr As String 
Public Shared QTYds As New dataset
Public Shared CNTconstr As String
Public Shared CNTcmd As New SqlCommand
Public Shared CNTcon As New SqlConnection
Public Shared CNTadap As New SqlDataAdapter(CNTcmd)
Public Shared CNTcmdstr As String 
Public Shared CNTds As New dataset
Public Shared ProcTot As Integer = 0
Public Shared pend As Integer = 0
Public Shared mess As String = ""
Private Sub btnprocess_Click( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles btnprocess.Click
        Try
        RunAgentJob
        'Dim agentbatpath As String = "\\aocweb01\c$\DeltaProject\SSISDeployment\AgentJob\agent.bat"
        'ShellandWait(agentbatpath)
        historyrecord
        XLprocessed
        MessageBox.Show("Raw data import completed")
        Me.btnprocess.BackColor = Color.LightGreen
        frmmain.btnProcess.BackColor = Color.LightGreen
        Catch ex As Exception
        MessageBox.Show(ex.ToString)
        End Try
End Sub
Private Sub RunAgentJob()
    Dim SPmovestr As String = ""
    Dim SPconstr As String = ""
    Dim delSPstr As String = ""
    SPconstr = My.Settings.MsdbCon
    SPmovestr = "Exec dbo.sp_start_job N'AspenTech_Simon'"
    System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
    Try
        Using SPcon As New SqlConnection(SPconstr)
            Dim SPcmd As New SqlCommand(SPmovestr, SPcon)
            'Dim SPdelcmd As New SqlCommand(delSPstr,SPcon)
            SPcmd.Connection.Open()
            SPcmd.ExecuteNonQuery()
            'SPdelcmd.ExecuteNonQuery()
            SPcon.Close()
        End Using
    Catch ex As Exception
        MessageBox.Show(ex.Message)

    End Try
End Sub
Private Sub QTY
            Dim Notestr As String = ""
            Dim InvCntstr As String = ""
            Dim Gallonsstr As String = ""
            Dim Invresult As Integer
            Dim Qtyresult As Integer
            Dim AvgLoad As Integer
            'Dim QTYconstr As String = ""
            QTYconstr = My.Settings.AscendCon
            CNTconstr = My.Settings.AscendCon
            Notestr = "Exec dbo.tabs_inv_note"
            Gallonsstr = "Exec AOCTabsInvCnt"
            InvCntstr = "Exec AOCTabsInvQty"
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
            Dim TCIFORDstr As String = ""
            Notestr = "Exec dbo.tabs_inv_note"
            Try
            Using QTYcon As New SqlConnection(QTYconstr)
            Dim QTYcmd As New SqlCommand(Notestr,QTYcon)
            QTYcmd.Connection.Open
            QTYcmd.ExecuteNonQuery()
            QTYcon.Close
            End Using
            Catch ex As Exception
            MessageBox.Show(ex.ToString)
            End Try

            Try
            QTYcon = New SqlConnection(QTYconstr)
            QTYcmd = New SqlCommand(InvCntstr,QTYcon)
            QTYcon.ConnectionString = QTYconstr
            QTYcon.Open
            QTYcmd.Connection = QTYcon
            QTYadap.SelectCommand = QTYcmd
            QTYadap.Fill(QTYds)
            QTYadap.Dispose()
            QTYcmd.Dispose()
            QTYcon.Close
            For Each datarowQTY As DataRow In QTYds.Tables(0).Rows
            Invresult = datarowQTY("InvQty")
            Next
            Catch ex As Exception
            MessageBox.Show(ex.ToString)
            End Try
            
            Try
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
            CNTcon = New SqlConnection(CNTconstr)
            CNTcmd = New SqlCommand(Gallonsstr,CNTcon)
            CNTcon.ConnectionString = CNTconstr
            CNTcon.Open
            CNTcmd.Connection = CNTcon
            CNTadap.SelectCommand = CNTcmd
            CNTadap.Fill(CNTds)
            CNTadap.Dispose()
            CNTcmd.Dispose()
            CNTcon.Close
            For Each datarowCNT As DataRow In CNTds.Tables(0).Rows
            Qtyresult = datarowCNT("InvCnt")
            Next
                If Not Invresult = 0 then 
                AvgLoad = Invresult/Qtyresult
                mess = Qtyresult & " Invoices. " & Invresult & " Gallons. " & AvgLoad & " Average delivered Qty"
                Dim pstr As String = "Processed gallons = " & frmProcess.ProcTot
                Dim ustr As String = "Unprocessed gallons = " & frmaudit.ControlUP
                Dim pendstr As String = "Pending gallons = " & frmProcess.pend
                Dim tstr As String = "TABS gallons = " & frmmain.CT
                Dim diff As Integer = frmmain.CT - frmProcess.ProcTot - frmProcess.pend
            
                MessageBox.Show (mess & ControlChars.NewLine & tstr & ControlChars.NewLine & pstr & ControlChars.NewLine & ustr & ControlChars.NewLine & pendstr & ControlChars.NewLine & "__________________________" & ControlChars.NewLine & diff)
                'MessageBox.Show(mess)
                'MessageBox.Show(tstr)
                'MessageBox.Show(pstr)
                'MessageBox.Show(ustr)
                'MessageBox.Show(pendstr)
                'MessageBox.Show(diff)
                Else
                MessageBox.Show("Zero invoice count returned")
                End If

            Catch ex As Exception
            MessageBox.Show(ex.ToString)
            End Try
End Sub
Private Sub ShellandWait(ByVal Processpath As String)
        Dim objprocess As System.Diagnostics.Process
        Try
            objprocess = New System.Diagnostics.Process()
            objprocess.StartInfo.FileName = Processpath
            objprocess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objprocess.Start()
            'Wait
            objprocess.WaitForExit()
            'Free resources
            objprocess.Close
        Catch ex As Exception
        MessageBox.Show(ex.Message)
        End Try
End Sub
Private Sub btnremovehist_Click( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles btnremovehist.Click
        Dim frmhistrest As frmhistoryrestore
        frmhistrest = New frmhistoryrestore()
        frmhistrest.Show()
        frmhistrest = Nothing
End Sub
Private Sub btnExit_Click( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close
End Sub
Private Sub historyrecord
    Dim histmovestr As String = ""
    Dim histconstr As String = ""
    Dim delhiststr As String = ""
    histconstr = My.Settings.TabsCon
    histmovestr = "insert into aocbolviewerhistory (submitdate,submitdateSTR,terminalid,terminalname,consigneenumber,consigneename,shipdate,bolnumber,releaseno,product,gross,net,carrier,authdate,authdateSTR,authnumber,vehiclenumber,processedbol,tcn,loadstart,loadstartSTR,loadend,loadendSTR,carrierfein,po,uom,ID) (select * from aocbolviewer)"
    System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
    Try
    Using histcon As New SqlConnection(histconstr)
    Dim histcmd As New SqlCommand(histmovestr,histcon)
    'Dim histdelcmd As New SqlCommand(delhiststr,histcon)
    histcmd.Connection.Open
    histcmd.ExecuteNonQuery()
    'histdelcmd.ExecuteNonQuery()
    histcon.Close
    End Using
    Catch ex As Exception
    MessageBox.Show(ex.Message)

    End Try
End Sub
Private Sub XLprocessed
Dim sql As String
Dim sqlconstr As String
Dim ds As New DataSet()
Dim adapter As New SqlDataAdapter
Dim con As New SqlConnection(sqlconstr)
Dim cmd As New SqlCommand(sql,con)
Dim stat As Integer
Dim ordid As Integer
Dim termid As Integer
Dim termname As String
Dim connum As String
Dim conname As String
Dim Sdate As DateTime
Dim bol As Integer
Dim PI As String
Dim prod As String
Dim gross As Integer
Dim net As Integer
Dim del As Integer
Dim Lstart As DateTime
Dim Lend As DateTime
Dim amt As Decimal
Dim create As String = ""
Dim dtnow As DateTime = Now()
Dim dtformat As String = "MM dd yyyy HHmm"
create = dtnow.ToString(dtformat)
Dim pickval As DateTime = frmPrep.DateTimePicker1.Value
pickval = pickval.AddDays(-1)
Dim pickformat As String = "MM dd yyy"
Dim pickdate As String = pickval.ToString(pickformat)
Dim pickfullname As String = pickdate & ".xlsx"
Dim nname As String = pickfullname
Dim Ffyear As String = Year(pickdate)
Dim Ffmonth As String = Month(pickdate)
'Dim Ffileformat As String = "yyyyMMddHHmmss"
'Dim Ffname As String = "Factor " & Now.ToString(Ffileformat)
Dim Fusrpath As String = My.Settings.Billingpth & Ffyear & "\" & Ffmonth & "\" & "
'Dim Fusrfile As String = Frptstate & "-" & Ffname & ".csv"
Dim Ffilepath As String = Fusrpath & "Processed Orders " & pickfullname

Try
    If Not Directory.Exists(Fusrpath) Then
        Dim di As DirectoryInfo = Directory.CreateDirectory(Fusrpath)
        File.Create(pickfullname).Dispose()
    Else
    'File.Create(Ffilepath).Dispose()
    End If
Catch ex As Exception
    'MessageBox.Show(ex.ToString)
End Try


Dim XLpath As String = Fusrpath & "Processed Orders " & nname
Dim myrow As Integer = 1
        Try
        XLconstr = My.Settings.TabsCon
        XLcmdstr = "select TerminalID, TerminalName,ConsigneeNumber,ConsigneeName,ShipDate,BOLNumber,PIDX,Product,Gross,Net,Delivered,LoadStart,LoadEnd,Price,OrderID FROM aoctabsexceldata order by LoadEnd desc"
        System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
        XLcon = New SqlConnection(XLconstr)
        XLcmd = New SqlCommand(XLcmdstr,XLcon)
        XLcon.ConnectionString = XLconstr
        XLcon.Open
        XLcmd.Connection = XLcon
        XLadap.SelectCommand = XLcmd
        XLadap.Fill(XLds)
        XLadap.Dispose()
        XLcmd.Dispose()
        XLcon.Close
        Catch ex As Exception
        MessageBox.Show(ex.ToString)
        End Try
            '******************** Creates data set (ds) containing unique customer list ********************AND AXX_TERMINAL = 'WoodhvenBK' AND AXX_TERMINAL ! = 'DETROIT MA' 
            'MsgBox(xrds.Tables(0).Rows.Count)
            If XLds.Tables(0).Rows.Count = 0 Then MessageBox.Show("No records processed!") Else
            'If ds.Tables(0).Rows.Count = 0 Then btnXrpts.BackColor=Color.LightGreen
            'If ds.Tables(0).Rows.Count = 0 Then btnmovetonext.BackColor=Color.LightGreen
            If XLds.Tables(0).Rows.Count = 0 Then Exit Sub Else 
            Dim strFileName As String = nname
 
            Dim xlApp As New Excel.Application
            Dim xlWorkBook As Excel.Workbook
            Dim processpth As String
            processpth = My.Settings.Billingpth & "blank.xlsx"
            try
                '~~> Opens Source Workbook. Change path and filename as applicable
                xlWorkBook = xlApp.Workbooks.Open(processpth)
 
                '~~> Display Excel
                xlApp.Visible = True
 
                '~~> Do some work
            xlApp.ScreenUpdating = False
            xlWorkBook.Sheets("Sheet1").Cells(1, 1).value = "TerminalID"
            xlWorkBook.Sheets("Sheet1").Cells(1, 2).value = "TerminalName"
            xlWorkBook.Sheets("Sheet1").Cells(1, 3).value = "ConsigneeNumber"
            xlWorkBook.Sheets("Sheet1").Cells(1, 4).value = "ConsigneeName"
            xlWorkBook.Sheets("Sheet1").Cells(1, 5).value = "ShipDate"
            xlWorkBook.Sheets("Sheet1").Cells(1, 6).value = "BOLNumber"
            xlWorkBook.Sheets("Sheet1").Cells(1, 7).value = "PIDX"
            xlWorkBook.Sheets("Sheet1").Cells(1, 8).value = "Product"
            xlWorkBook.Sheets("Sheet1").Cells(1, 9).value = "Gross"
            xlWorkBook.Sheets("Sheet1").Cells(1, 10).value = "Net"
            xlWorkBook.Sheets("Sheet1").Cells(1, 11).value = "Delivered"
            xlWorkBook.Sheets("Sheet1").Cells(1, 12).value = "LoadStart"
            xlWorkBook.Sheets("Sheet1").Cells(1, 13).value = "LoadEnd"
            xlWorkBook.Sheets("Sheet1").Cells(1, 14).value = "Price"
            xlWorkBook.Sheets("Sheet1").Cells(1, 15).value = "OrderID"
            xlWorkBook.Sheets("Sheet1").Range("A2").Select
            For Each datarowXL As DataRow In XLds.Tables(0).Rows
            myrow = myrow + 1
            termid = datarowXL("TerminalID")
            termname = datarowXL("TerminalName").ToString
            connum = datarowXL("ConsigneeNumber").ToString
            conname = datarowXL("ConsigneeName").ToString
            Sdate = datarowXL("ShipDate")
            bol = datarowXL("BOLNumber")
            PI = datarowXL("PIDX").ToString
            prod = datarowXL("Product").ToString
            gross = datarowXL("Gross")
            net = datarowXL("Net")
            del = datarowXL("Delivered")
            Lstart = datarowXL("LoadStart")
            Lend = datarowXL("LoadEnd")
            amt = datarowXL("Price")
            ordid = datarowXL("OrderID")
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 1).value = termid
            'xlWorkBook.Sheets("Sheet1").ActiveCell.Value = termid
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 2).value = termname
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 3).value = connum
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 4).value = conname
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 5).value = Sdate
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 6).value = bol
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 7).value = PI
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 8).value = prod
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 9).value = gross
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 10).value = net
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 11).value = del
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 12).value = Lstart
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 13).value = Lend
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 14).Value = amt
            xlWorkBook.Sheets("Sheet1").Cells(myrow, 15).Value = ordid
            xlWorkBook.Sheets("Sheet1").Range("A1:Z1").EntireColumn.Autofit()
            Next
            xlApp.ScreenUpdating = True
            '~~> Save As file
            'xlWorkBook.SaveAs(Filename:= XLpath, FileFormat:=51, Password:=MyPassword, _
            'WriteResPassword:=MyPassword, ReadOnlyRecommended:=True, CreateBackup:=False)
            xlWorkBook.SaveAs(Filename:= XLpath, FileFormat:=51)
            '~~> Close the file
            xlWorkBook.Close()
            xlApp.Quit()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
            Catch ex As Exception
            MessageBox.Show(ex.ToString)
            End Try
            'Me.Cursor = Cursors.Default
            'btnprocess.BackColor = Color.LightGreen
End Sub

Private Sub btnQtys_Click( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles btnQtys.Click
Pendingtot
ControlP
'UploadToDTN
QTY
SendMymail
Me.btnQtys.BackColor = Color.LightGreen
End Sub

Private Sub ControlP
Dim CTPsql As String = ""
Dim CTPsqlconstr As String = ""
Dim CTPds As New DataSet()
Dim CTPadapter As New SqlDataAdapter
Dim CTPcon As New SqlConnection(CTPSqlconstr)
Dim CTPcmd As New SqlCommand(CTPsql,CTPcon)
    CTPsqlconstr = My.Settings.TabsCon
    CTPsql = "Select sum(gross) as ProcessedTotal from aoctabsexceldata"
        Try
        CTPcon.ConnectionString = CTPsqlconstr
        CTPcon.Open
        CTPcmd.CommandText = CTPsql
        CTPadapter.SelectCommand = CTPcmd
        CTPadapter.Fill(CTPds)
        CTPAdapter.Dispose()
        CTPadapter.Dispose()
        CTPcon.Close
        Catch ex As Exception
        MessageBox.Show(ex.ToString)
        End Try
        If  CTPds.Tables(0).Rows.Count > 0 Then
            For Each DataRow As DataRow In CTPds.Tables(0).Rows
            ProcTot = DataRow("ProcessedTotal")
            Next 
        Else
        End If
End Sub
Private Sub Pendingtot
Dim CTPensql As String = ""
Dim CTPensqlconstr As String = ""
Dim CTPends As New DataSet()
Dim CTPenadapter As New SqlDataAdapter
Dim CTPencon As New SqlConnection(CTPenSqlconstr)
Dim CTPencmd As New SqlCommand(CTPensql,CTPencon)
    CTPensqlconstr = My.Settings.TabsCon
    CTPensql = "Select sum(gross) as PendingTotal from aocbolviewer_unprocessed"
        Try
        CTPencon.ConnectionString = CTPensqlconstr
        CTPencon.Open
        CTPencmd.CommandText = CTPensql
        CTPenadapter.SelectCommand = CTPencmd
        CTPenadapter.Fill(CTPends)
        CTPenAdapter.Dispose()
        CTPenadapter.Dispose()
        CTPencon.Close
        Catch ex As Exception
        MessageBox.Show(ex.ToString)
        End Try
        If  CTPends.Tables(0).Rows.Count > 0 Then
            For Each DataRow As DataRow In CTPends.Tables(0).Rows 'This needs error handling for dbnull error
            If IsDBNull(DataRow("PendingTotal"))
            pend = 0
            Else
            pend = DataRow("PendingTotal")
            End If
            Next 
        Else
        End If
End Sub
Private Sub BatFileWait(ByVal Processpath As String)
        Dim objprocess As System.Diagnostics.Process
        Try
            objprocess = New System.Diagnostics.Process()
            objprocess.StartInfo.FileName = Processpath
            objprocess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objprocess.Start()
            'Wait
            objprocess.WaitForExit()
            'Free resources
            objprocess.Close
        Catch ex As Exception

        End Try

End Sub
'Private Sub UploadToDTN
'        Try
'        Dim batpath As String = "\\aocfs01\public$\DTN_Enhanced\DTNClear.bat"
'        BatFileWait(batpath)
'        MessageBox.Show("DTN data import completed")
'        Catch ex As Exception
'        MessageBox.Show(ex.ToString)
'        End Try
'End Sub
Sub ssl()
Net.ServicePointManager.ServerCertificateValidationCallback = AddressOf validateCert
End Sub
Public Function validateCert(ByVal sender As Object, ByVal certificate As X509Certificate,ByVal chain As X509Chain,ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
Return True
End Function
Public Sub SendMymail
        ssl
        Dim SmtpServer As New SmtpClient()
        SmtpServer.EnableSsl = True
        Dim mail As New MailMessage()
        Dim mymess As String = "Rack automation process complete!"
        Dim addrstr As String = My.Settings.DistEmailAddress
        Try
        SmtpServer.Credentials = New  _
        Net.NetworkCredential("atlasoil\appoperator", "appopr")
        SmtpServer.Port = 587
        SmtpServer.Host = "mail.atlasoil.com"
        mail = New MailMessage()
        mail.From = New MailAddress("[email protected]")
        For Each recipient As String In addrstr.Split(","c)
        mail.To.Add(recipient)
        Next
        mail.Subject = mymess
        mail.Body = mess
        SmtpServer.Send(mail)
        Catch ex As Exception
        MessageBox.Show(ex.ToString)
'        LoginForm1.logwriter = New System.IO.StreamWriter("\\aocfs01\brianh$\RackQuotes\ErrorLog\" & LoginForm1.ADUser & 

'"\ErrorLog.txt",True) 
'        Dim SendMyMail As String = Now & " frmRackPrices - Sub SendMymail - Error sending mail"
'        LoginForm1.logwriter.WriteLine(SendMyMail)
'        LoginForm1.logwriter.WriteLine(ex)
'        LoginForm1.logwriter.close
        End Try
        mail.Attachments.Dispose()
        mail.Dispose()
End Sub

Private Sub btnMovetoHist_Click( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles btnMovetoHist.Click
        Dim frmMovetoHist As frmMovetoHist
        frmMovetoHist = New frmMovetoHist()
        frmMovetoHist.Show()
        frmMovetoHist = Nothing
End Sub

Private Sub frmProcess_Load( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToParent
End Sub
End Class 

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