Public Class frmSupplyOrders 'Declare Constants Const dblBloodPrice As Double = 129.0 Const dblHeartPrice As Double = 95.0 Const dblActivityPrice As Double = 109.0 Const dblJournalOnePrice As Double = 4.99 Const dblJournalTwoPrice As Double = 9.99 Const dblSALE_TAX As Double = 0.07 Private Sub btnProcess_Click(sender As Object, e As EventArgs) Handles btnProcess.Click 'Declare variables that will hold the values that are put in the textboxes by the user. Dim strCustName As String = txtName.Text Dim strStreet As String = txtAddress.Text Dim strCity As String = txtCity.Text Dim intBlood As Integer Dim intHeart As Integer Dim intActivity As Integer Dim intjournalOne As Integer Dim intjournalTwo As Integer 'Declare variables to calculate the total. Dim dblTotalDue As Double Dim dblTotalTax As Double Dim dblOrderPrice As Double Dim strInvoiceId As String Dim strReversedName As String 'Validate the input into the textboxes. If ValidateInput(strCustName, strStreet, strCity) Then intBlood = CInt(txtBlood.Text) intHeart = CInt(txtHeart.Text) intActivity = CInt(txtActivity.Text) intjournalOne = CInt(txtJournalOne.Text) intjournalTwo = CInt(txtJournalTwo.Text) dblTotalDue = Calculate(intBlood, intHeart, intActivity, intjournalOne, intjournalTwo, dblTotalTax, dblOrderPrice) strInvoiceId = InvoiceNumber(strCustName, strCity) strReversedName = ReverseName(strCustName) Call DisplayBill(intBlood, intHeart, intActivity, intjournalOne, intjournalTwo, dblOrderPrice, dblTotalTax, dblTotalDue, strInvoiceId, strReversedName, strStreet, strCity) End If End Sub Private Function Calculate(intBlood As Integer, intHeart As Integer, intActivity As Integer, intjournalOne As Integer, intjournalTwo As Integer, dblTotalTax As Double, dblOrderPrice As Double) As Double End Function 'Clear all textboxes and listbox. Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click For Each ctrl In Controls.OfType(Of TextBox) ctrl.Clear() Next lstDisplay.Items.Clear() txtName.Focus() End Sub 'End program. Private Sub btnQuit_Click(sender As Object, e As EventArgs) Handles btnQuit.Click Me.Close() End Sub Private Sub DisplayBill(intBlood As Integer, intHeart As Integer, intActivity As Integer, IntjournalOne As Integer, intjournalTwo As Integer, dblOrderPrice As Double, dblTotalTax As Double, dblTotalDue As Double, strInvoiceId As String, strReversedName As String, strStreet As String, strCity As String) lstDisplay.Items.Add("Invoice Number: " + strInvoiceId) lstDisplay.Items.Add("") lstDisplay.Items.Add("Name: " + strReversedName) lstDisplay.Items.Add("Street Address: " + strStreet) lstDisplay.Items.Add("City, State, Zip Code: " + strCity) lstDisplay.Items.Add("") lstDisplay.Items.Add("Number of Blood pressure monitor kits: " + intBlood.ToString) lstDisplay.Items.Add("Number of Heart monitor kits: " + intHeart.ToString) lstDisplay.Items.Add("Number of Activity monitor: " + intActivity.ToString) lstDisplay.Items.Add("Number of Food intake journal: " + IntjournalOne.ToString) lstDisplay.Items.Add("Number of Food intake and activity journal: " + intjournalTwo.ToString) lstDisplay.Items.Add("") lstDisplay.Items.Add("Order Price: " + FormatCurrency(dblOrderPrice)) lstDisplay.Items.Add("Sales Tax: " + FormatCurrency(dblTotalTax)) lstDisplay.Items.Add(" --------------------") lstDisplay.Items.Add("Total Price: " + FormatCurrency(dblTotalDue)) End Sub Function ValidateInput(strCustName As String, strStreet As String, strCity As String) As Boolean If Not strCustName.Contains(",") Or strCustName.Length < 4 Then MessageBox.Show("Invalid Name. Make sure the Last Name and First Name are separated by a comma", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False ElseIf strStreet = "" Or strCity = "" Then MessageBox.Show("Invalid City info", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False ElseIf Not IsNumeric(txtBlood.Text) Or Not IsNumeric(txtHeart.Text) Then ElseIf Not IsNumeric(txtActivity) Or Not IsNumeric(txtJournalOne) Or Not IsNumeric(txtJournalTwo) Then MessageBox.Show("Valid number of txtBlood, txtHeart, txtActivity, txtJournalOne or txtJournalTwo. Please enter numeric values", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False Else Return True End If End Function Function Calculate(intChairs As Integer, intSofas As Integer, ByRef dblTotalTax As Double, ByRef dblOrderPrice As Double) As Double Dim intJournalOne As Double = Nothing Dim intjournalTwo As Double = Nothing dblOrderPrice = (txtBlood.Text * dblBloodPrice) + (txtHeart.Text * dblHeartPrice) + (txtActivity.Text * dblActivityPrice) + (txtJournalOne.Text * dblJournalOnePrice) + (txtJournalTwo.Text * dblJournalTwoPrice) dblTotalTax = dblOrderPrice * dblSALE_TAX Return dblOrderPrice + dblTotalTax End Function Private Function intActivity() As Double End Function Function InvoiceNumber(strCustName As String, strCity As String) As String Dim strZipDigits As String strZipDigits = strCity.Substring(strCity.Length - 4) Return strCustName.Substring(0, 2).ToUpper() & strZipDigits 'Start at the beginning of the string (0) and go forward (2) characters. Convert the characters to uppercase. Concatenate with the zip code digits. End Function Function ReverseName(strCustName As String) As String Dim strFirstName As String Dim strLastName As String Dim intCommaPosition As Integer intCommaPosition = strCustName.IndexOf(",") strFirstName = strCustName.Substring(intCommaPosition + 2) strLastName = strCustName.Substring(0, intCommaPosition) Return strFirstName & ", " & strLastName End Function End Class
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.
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
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
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 ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
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
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
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End 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
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.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub