Alpha Webdesign

From the Blog

T-Shirts Software App

Visual Basic and Visual Studio – Creating Variables, If statements, Else Statements, Validations and more by using VB.

Click Here to download the Code VB-t-shirt-App

Video 1 of 2

Video 2 of 2

‘The Code:

”””””””””””””””””””””””Start Code”””””””””””””””””””””””””””’

‘This is the var for the small sizes
Dim Small As Integer

‘This is the Var for all sizes
Dim Sizes As Char

‘This is the Var for the designers
Dim Designer As String

‘This is the Var for the qty
Dim Qty As Integer

‘This is the Var to allow me to know the cost for the small size t-shirts
Dim MySmall As Decimal = 30.0

‘This is the Var to allow me to know the cost for the medium size t-shirts
Dim MyMedium As Decimal = 35.0

‘This is the Var to allow me to know the cost for the large size t-shirts
Dim MyLarge As Decimal = 40.0

‘This is the T&C checkbox var
Dim TermsAndConditions As Boolean

‘ This is the info for the Large t-shirts
Dim LargeInfo As String

‘ This is the info for the Medium t-shirts
Dim MediumInfo As String

‘ This is the info for the Small t-shirts
Dim SmallInfo As String

‘ This is the var for the Total
Dim Total As Decimal

‘ This is the var for the Cost
Dim Cost As Decimal

‘ This is the var for the Exit button
Dim ValExit As String

‘ This is the var to ensure that people don’t leave blank fields on the form.
Dim ValOptions As String

Private Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTotal.Click

‘Clear the listbox
lstOrderDetails.Items.Clear()

‘check to ensure that the user has selected a designer
If cobDesigner.Text = “” Then
ValOptions = MessageBox.Show(“You have not selected a Designer!”, “Salt And The Light”, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
End If

‘check to ensure that the user has selected a size
If cobSizes.Text = “” Then
ValOptions = MessageBox.Show(“You have not selected a size!”, “Salt And The Light”, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
End If

‘check to ensure that the user has selected qty
If txtQty.Text = “” Then
ValOptions = MessageBox.Show(“You have not added a qty!”, “Salt And The Light”, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
End If

‘check to ensure that the qty is not greater than 3
If txtQty.Text > 3 Then
ValOptions = MessageBox.Show(“Please note that we don’t have as many t-shirts in stock! Please try again”, “Salt And The Light”, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
End If

‘check to ensure that the customer agrees with our T&C
If chbTerms.Checked = False Then
ValOptions = MessageBox.Show(“You have not accept the Terms and Conditions!”, “Salt And The Light”, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
End If

‘Add a value to the var
TermsAndConditions = chbTerms.Checked

‘Add a value to the var
Sizes = cobSizes.Text

‘Add a value to the var
Qty = Convert.ToInt16(txtQty.Text)

‘Add info to the var
LargeInfo = (“You have selected the follwing size: ” & Sizes & “. The cost is: ” & MyLarge)
‘Add info to the var
MediumInfo = (“You have selected the follwing size: ” & Sizes & “. The cost is: ” & MyMedium)
‘Add info to the var
SmallInfo = (“You have selected the follwing size: ” & Sizes & “. The cost is: ” & MySmall)

‘Check to ensure if the user has selected Large/Medium/Small t-shirt and display the values onto the listbox
””””””””””””””””code starts”””””””””””””””””””
If cobSizes.Text = “L” And TermsAndConditions = True Then
lstOrderDetails.Items.Add(LargeInfo)
Cost = MyLarge

ElseIf cobSizes.Text = “M” And TermsAndConditions = True Then
lstOrderDetails.Items.Add(MediumInfo)
Cost = MyMedium

ElseIf cobSizes.Text = “S” And TermsAndConditions = True Then
lstOrderDetails.Items.Add(SmallInfo)
Cost = MySmall
Else
End If

””””””””””””””””code End”””””””””””””””””””
‘We create the Total Var calculation to find the Total
Total = Qty * Cost

‘as long as the Qty is less than 3 then we will have the following info on the listbox
If Qty < 4 Then lstOrderDetails.Items.Add(“The total Cost is: ” & Total) lstOrderDetails.Items.Add(“”) lstOrderDetails.Items.Add(“”) lstOrderDetails.Items.Add(“Please select the Clear button before you add another item!”) End If ‘if the Total spend is more than £10 then the follwoing if statement will act If Total > 100 Then
‘add the discount
Total = Total – ((Total * 10) / 100)
‘add the VAT
txtTotal.Text = Total + ((Total * 20) / 100)

End If

‘if the qty is more than 3 then we need to clear the listbox and the txtTotal fields
If Qty > 3 Then
lstOrderDetails.Items.Clear()
txtTotal.Text = “”
End If

End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
‘we clear the qty field
txtQty.Text = “”
‘we clear the Total field
txtTotal.Text = “”
‘we clear the Sizes field
cobSizes.Text = “”
‘we clear the Designer field
cobDesigner.Text = “”
‘we clear the listbox field
lstOrderDetails.Items.Clear()
‘we uncheck the T&C box
chbTerms.Checked = False
End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
‘call the var ValExit
ValExit = MessageBox.Show(“Are you sure you wish to Exit the App?”, “Salt And The Light”, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
‘if the user selects the Yes button then the application will close
If ValExit = DialogResult.Yes Then
Application.Exit()

End If
End Sub

”””””””””””””””””””””””End Code”””””””””””””””””””””””””””

Have your say

seventeen − 10 =