Coding

  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Coding as PDF for free.

More details

  • Words: 3,422
  • Pages: 7
CODING

Public Class Form1 Dim Nozzlenumber As Single 'this variable stores the status, and the function of the nozzle button (btnnozzle) Dim Price As Single 'this variable stores the value of the fuel price per litre Dim Totalpetrol As Single 'this variable stores the total amount of petrol that has been sold that day Dim Totaltakings As Single 'this variable stores the amount of money the petrol station has made that day Dim Litres As Single 'this variable stores the amount of litres that the customer has purchased Dim BMP As Bitmap 'this variaable stores the bitmap for the LCD display Const xstartl = 125 'this variable stores the x co-ordinates for the starting place of the total litres LCD display Const ystartl = 210 'this variable stores the y co-ordinates for the starting place of the total litres LCD display Const xstart = 125 'this variable stores the x co-ordinates for the starting place of the fuel price LCD display Const ystart = 360 'this variable stores the y co-ordinates for the starting place of the fuel price LCD display Const xstartt = 100 'this variable stores the x co-ordinates for the starting place of the total price LCD display Const ystartt = 75 'this variable stores the y co-ordinates for the starting place of the total price LCD display

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPetrol.Tick If Litres < 99.9 Then 'this allows the litres to not go above 100L Litres = Litres + 0.1 'this allows the litres to go up by an appropriate amount as the timer ticks picLCD.Refresh() 'this means that as the timer ticks, the picturebox refreshes, refeshing the 7 segment LCD End If Call highernumberstotal(Litres * Price) 'calls the procedure for the 7 segment display for the total price Call highernumberslitres(Litres * 10) 'call the procedure for the 7 segment display for the total litres txtLitre.Text = Format(Litres, "##0.0") 'formats the litres textbox so there arent too many digits being displayed txtTotal.Text = Format(Price * Litres / 100, "currency") 'formats the total textbox so there arent too many digits being displayed Call highernumberslitres(Litres * 10) 'calls the procedure that allows the LCD display for the amount of litres of petrol that have been purchased by the customer Call highernumberstotal(Litres * Price) ' calls the procedure that allows the LCD display for the amount of money that the customer needs to pay for the petrol he has purchased

End Sub

Private Sub btnNozzle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNozzle.Click Nozzlenumber = Nozzlenumber + 1 'this allows the button to change status, and function Select Case Nozzlenumber 'this selects the appropriate case so the appropriate status is displayed and the appropraiate functions are carried out. Case 0 btnNozzle.Text = "Take Nozzle" 'this changes the text/status being displayed on the buttton which is used to simulate somebody using the petrol pump lblState.Text = "READY FOR USE" 'this changes the text/status being displayed in the "status" label on the console, so the person running the petrol station knows which pumps are in use, and which ones arent Case 1 btnNozzle.Text = "Squeeze Nozzle" 'this changes the text/status being displayed on the buttton which is used to simulate somebody using the petrol pump lblState.Text = "READY FOR USE" 'this changes the text/status being displayed in the "status" label on the console, so the person running the petrol station knows which pumps are in use, and which ones arent Case 2 btnNozzle.Text = "Release Nozzle" 'this changes the text/status being displayed on the buttton which is used to simulate somebody using the petrol pump lblState.Text = "IN USE" 'this changes the text/status being displayed in the "status" label on the console, so the person running the petrol station knows which pumps are in use, and which ones arent tmrPetrol.Start() 'this starts the timer when the nozzle is squeezed so that the petrol is dispensed into the car btnReset.Enabled = False 'this means that the employee cant reset the pump whilst the customer is filling is car with petrol Litres = 0.5 'this means that the customer can't buy less than 0.5L litres of petrol, as mentioned in the specification btnChange.Enabled = False 'this means that the employee cant change the price of the petrol whilst the customer is filling is car with petrol Case 3 btnNozzle.Text = "Replace Nozzle" 'this changes the text/status being displayed on the buttton which is used to simulate somebody using the petrol pump btnChange.Enabled = False 'this means that the employee cant change the price of the petrol before the customer has paid for his petrol btnDaily.Enabled = False 'this means that the daily takings cant be reset before the customer has paid for his petrol btnView.Enabled = False 'this means that the takings cannot be viewed before the customer has paid for his petrol tmrPetrol.Stop() 'this stops the timer when the nozzle is released so that the petrol stops being dispensed into the car Case 4 btnNozzle.Text = "Tempoarily Unavailable" 'this changes the text/status being displayed on the buttton which is used to simulate somebody using the petrol pump lblState.Text = "OUT OF USE" 'this changes the text/status being displayed in the "status" label on the console, so the person running the petrol station knows which pumps are in use, and which ones arent btnNozzle.Enabled = False 'this means that the next customer cannot use the pump until the employee has reset the pump btnReset.Enabled = True 'this allows the employee can reset the pump once the customer has paid for the petrol, allowing the next customer to use the pump btnChange.Enabled = True 'this allows the employee to now change the price once the customer has paid for his petrol, as the employee shouldnt be able to change the price of the petrol whilst the customer is in the middle of filling his car End Select End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

txtLitre.Text = "0.0" 'sets the total litres display on the console and the pump, so that it can display the customers purchase txtTotal.Text = "£0.00" 'sets the total price display on the console back to zero, so that it can display the customers purchase Price = 95.0 'this sets the default price on the pump and the console to 95p/l txtFuel.Text = Format(Price, "#00.0") 'formats the fuel price textbox so there arent too many digits being displayed lblState.Text = "READY FOR USE" 'this sets the default text/status being displayed to "READY FOR USE" when the program is loaded txtFuel.Enabled = False 'this locks down the fuel price box in the console display so the employee cant accidently delete, or change the price by accident txtLitre.Enabled = False 'this locks down the total litres box in the console display so the employee cant accidently delete, or change the number of litres by accident txtTotal.Enabled = False 'this locks down the total price box in the console display so the employee cant accidently delete, or change the total price by accident BMP = New Bitmap(picLCD.Width, picLCD.Height) 'this means that when the form is loaded, the LCD displays are loaded up into the pictre box, rather than the form, speeding up the display, as it only has to resfresh the picture box, not the whole form picLCD.BackgroundImage = BMP Call HigherNumbers(txtFuel.Text * 10) 'calls the procedure that allows the LCD display for the price that needs to be paid for each litre of petrol purchased Call highernumberstotal(Litres * Price) 'calls the procedure that allows the LCD display for the amount of money that the customer needs to pay for the petrol he has purchased Call highernumberslitres(Litres * 10) 'calls the procedure that allows the LCD display for the amount of litres of petrol that have been purchased by the customer End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click Totaltakings = Totaltakings + (Price * Litres / 100) 'this reupdates the daily takings once the employee resets the pump, adding the amount the customer has paid to the previous daily takings total Totalpetrol = Totalpetrol + Litres 'this reupdates the total petrol sold once the employee resets the pump, adding the amount the customer has bought to the previous daily petrol total Litres = 0 'this sets the litres display on the console and the pump back to zero, ready for the next customer to use btnChange.Enabled = True 'this allows the employee to be able to change the price of the petrol once the customer has paid for his petrol, as he shouldnt be allowed to allowed to change the price whilst somebody is in the middle of filling their car btnDaily.Enabled = True 'this allows the employee to reset the daily takings once the customer has paid, as resetting whilst the customer is filling his car may cause confusion btnView.Enabled = True 'allows the employee to view the daily takings after the customer has paid for his petrol, in order to prevent confusion btnNozzle.Enabled = True 'resets the pump so that the next customer can use the pump txtLitre.Text = "0.0" 'resets the total litres display on the console and the pump, so that it can display the next customers purchase txtTotal.Text = "£0.00" 'resets the total price display on the console back to zero, so that it can display the next customers purchase Nozzlenumber = -1 'resets the nozzlenumber to -1, so that the filling process can reoccur, meaning the next customer can use the pump End Sub

Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click txtFuel.Enabled = True 'allows the textbox to have information typed into, so that the emplyee can change the price of the petrol when needed

btnChange.Visible = False 'this hides the button once is has been clicked, and diplaying the confirm price button instead, so the employee can confirm the price once it has been displayed btnConfirm.Visible = True End Sub

Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click Dim Response As Integer 'this variable stores the response, and the coditions that determine the response Response = MsgBox("Are you sure you want to change the price to " & txtFuel.Text & "p?", vbYesNo) 'this is the message that will be displayed so the emplyee can confirm that he has changed to the price to the one desired If Response = vbYes Then 'if he says yes, the fuel price is changed to the once entered provided it is valid Price = txtFuel.Text 'this changes the price variable to the new price that has been entered Else : txtFuel.Text = Price 'if he says no, the price returns to the price that it currently was before he attemped to change it End If If Price > 199.9 Then 'if the price is £2 pr above, then an error message will come up, and reset the price back to the default 95p MsgBox("You can not set the price this high") 'this is the error message that will be displayed when the price is set too high Price = 95.0 'this resets the the price to the default 95p when the error message is closed txtFuel.Text = Price 'this reupdates the console and pump to display the new price End If If Price < 0.1 Then 'if the price is £0 or less, then an error message will come up , and reset the price back to the default 95p MsgBox("you can not set the price this low") 'this is the error message that will be displayed when the price is set too low Price = 95.0 'this resets the the price to the default 95p when the error message is closed txtFuel.Text = Price 'this reupdates the console and pump to display the new price End If txtFuel.Text = Format(Price, "#00.0") 'this formats the fuel price box, so that there aren't too many digits being displayed txtFuel.Enabled = False 'this relocks the text box, so the emplyee cant accidently change the price of the fuel whilst somebody may be filling their car with petrol btnConfirm.Visible = False 'this hides the button once is has been clicked, and diplaying the change price button instead, so the employee can change the price again if need be btnChange.Visible = True Call HigherNumbers(txtFuel.Text * 10) 'calls the procedure that allows the LCD display for the price that needs to be paid for each litre of petrol purchased picLCD.Refresh() 'this refreshes the picture box, so that the new price can be displayed on the LCD End Sub

Private Sub btnDaily_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDaily.Click Totalpetrol = 0 'this resets the variable that stores the amount of money made that day back to zero, so it can store the total money made for the next day Totaltakings = 0 'this resets the variable that stores the amount of petrol sold that day back to zero, so it can store the total petrol sold for the next day End Sub

Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click Dim response As Integer 'this variable stores the response when the button is clocked Totaltakings = Format(Totaltakings, "currency") 'this formats the variable so there arent too many digits displayed in the message Totalpetrol = Format(Totalpetrol, "##0.0") 'this formats the variable so there arent too many digits displayed in the message response = MsgBox("you have made £" & Totaltakings & " and have sold " & Totalpetrol & "L of petrol") 'this is the message that is displayed when the button is clicked, and says what should be displayed in the message End Sub

Public Sub Numbers(ByVal Digit As Integer, ByVal X As Integer, ByVal Y As Integer) Dim G As Graphics = Graphics.FromImage(BMP) Select Case Digit Case 8 G.FillRectangle(Brushes.Black, G.FillRectangle(Brushes.Black, G.FillRectangle(Brushes.Black, G.FillRectangle(Brushes.Black, G.FillRectangle(Brushes.Black, G.FillRectangle(Brushes.Black, G.FillRectangle(Brushes.Black,

X X X X X X X

+ + -

5, Y - 15, 40, 5) 'top bar 15, Y - 5, 5, 40) 'top left 40, Y - 5, 5, 40) 'top right 5, Y + 40, 40, 5) 'mid 40, Y + 50, 5, 40) 'bottom right 15, Y + 50, 5, 40) 'bottom left 5, Y + 95, 40, 5) 'bottom

Case 0 G.FillRectangle(Brushes.Black, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.Black, X - 15, Y - 5, 5, 40) 'top left G.FillRectangle(Brushes.Black, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.WhiteSmoke, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.Black, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.Black, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.Black, X - 5, Y + 95, 40, 5) 'bottom Case 9 G.FillRectangle(Brushes.Black, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.Black, X - 15, Y - 5, 5, 40) 'top left G.FillRectangle(Brushes.Black, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.Black, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.Black, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.Black, X - 5, Y + 95, 40, 5) 'bottom Case 7 G.FillRectangle(Brushes.Black, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y - 5, 5, 40) 'top left G.FillRectangle(Brushes.Black, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.WhiteSmoke, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.Black, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.WhiteSmoke, X - 5, Y + 95, 40, 5) 'bottom Case 6 G.FillRectangle(Brushes.Black, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.Black, X - 15, Y - 5, 5, 40) 'top left

G.FillRectangle(Brushes.WhiteSmoke, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.Black, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.Black, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.Black, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.Black, X - 5, Y + 95, 40, 5) 'bottom Case 5 G.FillRectangle(Brushes.Black, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.Black, X - 15, Y - 5, 5, 40) 'top left G.FillRectangle(Brushes.WhiteSmoke, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.Black, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.Black, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.Black, X - 5, Y + 95, 40, 5) 'bottom Case 4 G.FillRectangle(Brushes.WhiteSmoke, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.Black, X - 15, Y - 5, 5, 40) 'top left G.FillRectangle(Brushes.Black, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.Black, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.Black, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.WhiteSmoke, X - 5, Y + 95, 40, 5) 'bottom Case 3 G.FillRectangle(Brushes.Black, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y - 5, 5, 40) 'top left G.FillRectangle(Brushes.Black, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.Black, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.Black, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.Black, X - 5, Y + 95, 40, 5) 'bottom Case 2 G.FillRectangle(Brushes.Black, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y - 5, 5, 40) 'top left G.FillRectangle(Brushes.Black, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.Black, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.WhiteSmoke, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.Black, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.Black, X - 5, Y + 95, 40, 5) 'bottom Case 1 G.FillRectangle(Brushes.WhiteSmoke, X - 5, Y - 15, 40, 5) 'top bar G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y - 5, 5, 40) 'top left G.FillRectangle(Brushes.Black, X + 40, Y - 5, 5, 40) 'top right G.FillRectangle(Brushes.WhiteSmoke, X - 5, Y + 40, 40, 5) 'mid G.FillRectangle(Brushes.Black, X + 40, Y + 50, 5, 40) 'bottom right G.FillRectangle(Brushes.WhiteSmoke, X - 15, Y + 50, 5, 40) 'bottom left G.FillRectangle(Brushes.WhiteSmoke, X - 5, Y + 95, 40, 5) 'bottom End Select picLCD.Refresh() 'refreshes the picture box displaying the 7 segment G.Dispose() End Sub

Public Sub HigherNumbers(ByVal ThisNumber As Integer) Dim Digit(4) As Integer 'variable that stores how many digits are displayed Dim Count1 As Integer Dim Dummy As Integer Dummy = ThisNumber For Count1 = 1 To 4 'says how many digits should be displayed in this procedure Digit(Count1) = Dummy - (Int(Dummy / 10) * 10) 'breaks the numbers up so that the LCD can display the appropriate numbers Dummy = Int(Dummy / 10) Next

For Count1 = 4 To 1 Step -1 'says which order to display the numbers in Call Numbers(Digit(Count1), xstart + 90 * (4 - Count1), ystart) 'indicates the x and y starting places for the 7 segment display Next End Sub

Public Sub highernumberslitres(ByVal ThisNumber As Integer) Dim Digit(4) As Integer 'variable that stores how many digits are displayed Dim Count1 As Integer Dim Dummy As Integer Dummy = ThisNumber For Count1 = 1 To 4 'says how many digits should be displayed in this procedure Digit(Count1) = Dummy - (Int(Dummy / 10) * 10) 'breaks the numbers up so that the LCD can display the appropriate numbers Dummy = Int(Dummy / 10) Next For Count1 = 4 To 1 Step -1 'says which order to display the numbers in Call Numbers(Digit(Count1), xstartl + 90 * (4 - Count1), ystartl) 'indicates the x and y starting places for the 7 segment display Next End Sub

Public Sub highernumberstotal(ByVal ThisNumber As Integer) Dim Digit(5) As Integer 'variable that stores how many digits are displayed Dim Count1 As Integer Dim Dummy As Integer Dummy = ThisNumber For Count1 = 1 To 5 'says how many digits should be displayed in this procedure Digit(Count1) = Dummy - (Int(Dummy / 10) * 10) 'breaks the numbers up so that the LCD can display the appropriate numbers Dummy = Int(Dummy / 10) Next For Count1 = 5 To 1 Step -1 'says which order to display the numbers in Call Numbers(Digit(Count1), xstartt + 90 * (5 - Count1), ystartt) 'indicates the x and y starting places for the 7 segment display Next End Sub End Class

Related Documents

Coding
December 2019 22
Coding
July 2020 13
Coding
November 2019 26
Coding
April 2020 13
Coding
November 2019 26
Source Coding
June 2020 4