Hi there,
I had to make a first little program for school. The intention of the program is to check the speed of several cars. The speed is inputed by hand, just like the maximum tolerance speed. The program has to show the fine if the car is riding too fast (in several levels by 0, 50, 100, 500), also the total count of checked cars and total count of cars riding OK and total count of cars NOT OK.
Everything is working fine and the program runs, but now I want to clean up a bit by putting my if statements into functions so I only have to call that function.
I'll give you the whole code I wrote already. Oh yeah ... we just may use the basic structures, so no arrays and so on.
/>/> It's a practice on basis structures.
The following part I want to put into a function and call it here.
The following part I want to put into a function and call it here.
The following part I want to put into a function and call it here.
So ... what I ask is how I have tot declare a function, where I have to put it an how I call the function in my previous code so that it's all a bit cleaner.
Many thanks in advance.
I had to make a first little program for school. The intention of the program is to check the speed of several cars. The speed is inputed by hand, just like the maximum tolerance speed. The program has to show the fine if the car is riding too fast (in several levels by 0, 50, 100, 500), also the total count of checked cars and total count of cars riding OK and total count of cars NOT OK.
Everything is working fine and the program runs, but now I want to clean up a bit by putting my if statements into functions so I only have to call that function.
I'll give you the whole code I wrote already. Oh yeah ... we just may use the basic structures, so no arrays and so on.
Public Class ExamenOefeningSnelheidscontrole02Form1
'Declaration of variables
Dim intSnelheid As Integer = 0
Dim intTms As Integer = 0
Dim intTeBetalenBoete As Integer = 0
Dim intTotaalBedragBoetes As Integer = 0
Dim intAantalInOvertreding As Integer = 0
Dim intAantalInOrde As Integer = 0
Dim intTotaalGecontroleerd As Integer = 0
Private Sub afsluitenButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles afsluitenButton.Click
End
End Sub
Private Sub nieuweInvoerButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nieuweInvoerButton.Click
'retrieving input objects
intSnelheid = snelheidNumericUpDown.Value
intTms = tmsComboBox.SelectedItem
The following part I want to put into a function and call it here.
'Calculation the fine
If intSnelheid <= intTms Then
intTeBetalenBoete = 0
ElseIf intSnelheid <= intTms * 1.1 Then
intTeBetalenBoete = 50
ElseIf intSnelheid > intTms * 1.1 And intSnelheid < intTms * 2.0 Then
intTeBetalenBoete = 100
Else
intTeBetalenBoete = 500
End If
The following part I want to put into a function and call it here.
'Totale controles in orde én NIET in orde
'total of controls
If intTeBetalenBoete = 0 Then
intAantalInOrde += 1
ElseIf intTeBetalenBoete = 50 Then
intAantalInOvertreding += 1
ElseIf intTeBetalenBoete = 100 Then
intAantalInOvertreding += 1
ElseIf intTeBetalenBoete = 500 Then
intAantalInOvertreding += 1
End If
'retrieving value of fine to be paid
teBetalenBoeteLabel.Text = intTeBetalenBoete.ToString
The following part I want to put into a function and call it here.
'Calculate total sum of all fines
If intTeBetalenBoete = 0 Then
intTotaalBedragBoetes += 0
ElseIf intTeBetalenBoete = 50 Then
intTotaalBedragBoetes += 50
ElseIf intTeBetalenBoete = 100 Then
intTotaalBedragBoetes += 100
ElseIf intTeBetalenBoete = 500 Then
intTotaalBedragBoetes += 500
End If
'Retrieving valueof total sum of all fines
totaalBedragBoetesLabel.Text = intTotaalBedragBoetes.ToString
'Totalof all checked cars
intTotaalGecontroleerd = intAantalInOrde + intAantalInOvertreding
aantalInOrdeLabel.Text = intAantalInOrde.ToString
aantalInOvertredingLabel.Text = intAantalInOvertreding.ToString
totaalGecontroleerdLabel.Text = intTotaalGecontroleerd.ToString
End Sub
Private Sub allesWissenButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles allesWissenButton.Click
snelheidNumericUpDown.Value = 0
snelheidNumericUpDown.Focus()
tmsComboBox.SelectedIndex = -1
teBetalenBoeteLabel.Text = ""
totaalBedragBoetesLabel.Text = ""
aantalInOrdeLabel.Text = ""
aantalInOvertredingLabel.Text = ""
totaalGecontroleerdLabel.Text = ""
End Sub
Private Sub snelheidNumericUpDown_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles snelheidNumericUpDown.Click
snelheidNumericUpDown.Select(0, snelheidNumericUpDown.Text.Length)
End Sub
End Class
So ... what I ask is how I have tot declare a function, where I have to put it an how I call the function in my previous code so that it's all a bit cleaner.
Many thanks in advance.