My first program!!!
It works! It installs! It does everything! :) Okay, I'm excited, but yesterday was a huge day. Not only did I pass my instructor test in my pilot school with a 97, but I also finished my first program. Functionality is completely perfect.
The education I got from this was huge. Google answered nearly all of my questions, but I had to get quite a bit of help from my Supervisor to troubleshoot and help me piece it all together. Some things even baffled him for a second, which made me feel better.
The code is pasted down below. Again, I'm sure there are better ways to do what I've done, but for my first program, I am thrilled to death!
Public Class FRMTimeSheet
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles lblMonday.Click
End Sub
Private Sub Label1_Click_1(sender As Object, e As EventArgs) Handles lblTimeIn.Click
End Sub
Private Sub Label1_Click_2(sender As Object, e As EventArgs) Handles lblTimeOutLunch.Click
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Loads Saturday and Sunday values since the default is blank
ChkBoxTrue(dtpTimeInSunday, dtpTimeOutLunchSunday, dtpTimeInLunchSunday, dtpTimeOutSunday)
ChkBoxTrue(dtpTimeInSaturday, dtpTimeOutLunchSaturday, dtpTimeInLunchSaturday, dtpTimeOutSaturday)
End Sub
Private Sub Label1_Click_3(sender As Object, e As EventArgs) Handles lblLunch.Click
End Sub
Private Sub LBLSchedHours_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles lblGotHoursYet.Click
End Sub
Private Sub SumHours(tTimeIn As DateTimePicker, tTimeOutLunch As DateTimePicker, tTimeInLunch As DateTimePicker, tTimeOut As DateTimePicker, lblSum As Label)
'Totals hours for each day of the week, deducts lunch
Dim t1 As DateTime
Dim t2 As DateTime
Dim t3 As DateTime
Dim t4 As DateTime
Dim tht As TimeSpan
t1 = DateTime.Parse(tTimeIn.Value)
t2 = DateTime.Parse(tTimeOutLunch.Value)
t3 = DateTime.Parse(tTimeInLunch.Value)
t4 = DateTime.Parse(tTimeOut.Value)
tht = t4 - t1 - (t3 - t2)
lblSum.Text = tht.TotalHours
End Sub
Private Sub BTNCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
'Calculates hours for each day of the week, calling the SumHours function
SumHours(dtpTimeInSunday, dtpTimeOutLunchSunday, dtpTimeInLunchSunday, dtpTimeOutSunday, lblSundayHoursTotal)
SumHours(dtpTimeInMonday, dtpTimeOutLunchMonday, dtpTimeInLunchMonday, dtpTimeOutMonday, lblMondayHoursTotal)
SumHours(dtpTimeInTuesday, dtpTimeOutLunchTuesday, dtpTimeInLunchTuesday, dtpTimeOutTuesday, lblTuesdayHoursTotal)
SumHours(dtpTimeInWednesday, dtpTimeOutLunchWednesday, dtpTimeInLunchWednesday, dtpTimeOutWednesday, lblWednesdayHoursTotal)
SumHours(dtpTimeInThursday, dtpTimeOutLunchThursday, dtpTimeInLunchThursday, dtpTimeOutThursday, lblThursdayHoursTotal)
SumHours(dtpTimeInFriday, dtpTimeOutLunchFriday, dtpTimeInLunchFriday, dtpTimeOutFriday, lblFridayHoursTotal)
SumHours(dtpTimeInSaturday, dtpTimeOutLunchSaturday, dtpTimeInLunchSaturday, dtpTimeOutSaturday, lblSaturdayHoursTotal)
Dim sht As Double
Dim mht As Double
Dim tht As Double
Dim wht As Double
Dim thht As Double
Dim fht As Double
Dim saht As Double
Dim ttlHours As Double
sht = lblSundayHoursTotal.Text
mht = lblMondayHoursTotal.Text
tht = lblTuesdayHoursTotal.Text
wht = lblWednesdayHoursTotal.Text
thht = lblThursdayHoursTotal.Text
fht = lblFridayHoursTotal.Text
saht = lblSaturdayHoursTotal.Text
lblTotalHours.Text = sht + mht + tht + wht + thht + fht + saht
ttlHours = sht + mht + tht + wht + thht + fht + saht
'Displays the picture based on hours worked versus hours scheduled
If nudSchedHours.Value > ttlHours Then
picHours.Visible = True
picHours.Image = Image.FromFile("L:\JMay\Pending Projects\Timesheet Pics\Head Shake.gif")
ElseIf nudSchedHours.Value <= ttlHours Then
picHours.Visible = True
picHours.Image = Image.FromFile("L:\JMay\Pending Projects\Timesheet Pics\Colbert Clap.gif")
End If
End Sub
Private Sub Label1_Click_4(sender As Object, e As EventArgs) Handles lblSchedHours.Click
End Sub
Private Sub Label1_Click_6(sender As Object, e As EventArgs) Handles lblSundayHoursTotal.Click
End Sub
Private Sub LBLJedsTimesheetTitle_Click(sender As Object, e As EventArgs) Handles lblJedsTimesheetTitle.Click
End Sub
Private Sub BTNReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
Controls.Clear()
InitializeComponent()
End Sub
Private Sub DateTimePicker1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles dtpTimeInSunday.KeyDown
'Adjusts minutes in 15 minute increments when the up or down button is pushed
If e.KeyCode = Keys.Up Then
dtpTimeInSunday.Value = dtpTimeInSunday.Value.AddMinutes(15)
e.Handled = True
End If
If e.KeyCode = Keys.Down Then
dtpTimeInSunday.Value = dtpTimeInSunday.Value.AddMinutes(-15)
e.Handled = True
End If
End Sub
Private Sub LBLTotalHours_Click(sender As Object, e As EventArgs) Handles lblTotalHours.Click
End Sub
Private Sub Label1_Click_5(sender As Object, e As EventArgs) Handles lblBlankHours.Click
End Sub
Private Sub ChkBoxTrue(fTimeIn As DateTimePicker, fTimeOutLunch As DateTimePicker, fTimeInLUnch As DateTimePicker, fTimeOut As DateTimePicker)
'Sets all dates to the same "standard date" value so that the total when added together = 0
Dim stddate As String
stddate = "7 / 12 / 2017 16:00"
fTimeOut.Visible = False
fTimeOutLunch.Visible = False
fTimeInLUnch.Visible = False
fTimeIn.Visible = False
fTimeIn.Text = stddate
fTimeOutLunch.Text = stddate
fTimeInLUnch.Text = stddate
fTimeOut.Text = stddate
End Sub
Private Sub ChkBoxFalse(fTimeIn As DateTimePicker, fTimeOutLunch As DateTimePicker, fTimeInLUnch As DateTimePicker, fTimeOut As DateTimePicker)
'Sets a default value when the checkbox for each day of the week is unselected
fTimeIn.Visible = True
fTimeOutLunch.Visible = True
fTimeInLUnch.Visible = True
fTimeOut.Visible = True
fTimeIn.Text = "7 / 12 / 2017 08:00"
fTimeOutLunch.Text = "7 / 12 / 2017 12:00"
fTimeInLUnch.Text = "7 / 12 / 2017 13:00"
fTimeOut.Text = "7 / 12 / 2017 17:00"
End Sub
Private Sub PICHours_Click(sender As Object, e As EventArgs) Handles picHours.Click
End Sub
Private Sub NUDSchedHours_ValueChanged(sender As Object, e As EventArgs) Handles nudSchedHours.ValueChanged
End Sub
Private Sub DTPTimeInSunday_ValueChanged(sender As Object, e As EventArgs) Handles dtpTimeInSunday.ValueChanged
End Sub
Private Sub CHKSundayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkSundayHours.CheckedChanged
If chkSundayHours.Checked = True Then
ChkBoxTrue(dtpTimeInSunday, dtpTimeOutLunchSunday, dtpTimeInLunchSunday, dtpTimeOutSunday)
ElseIf chkSundayHours.Checked = False Then
ChkBoxFalse(dtpTimeInSunday, dtpTimeOutLunchSunday, dtpTimeInLunchSunday, dtpTimeOutSunday)
End If
End Sub
Private Sub CHKMondayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkMondayHours.CheckedChanged
If chkMondayHours.Checked = True Then
ChkBoxTrue(dtpTimeInMonday, dtpTimeOutLunchMonday, dtpTimeInLunchMonday, dtpTimeOutMonday)
ElseIf chkMondayHours.Checked = False Then
ChkBoxFalse(dtpTimeInMonday, dtpTimeOutLunchMonday, dtpTimeInLunchMonday, dtpTimeOutMonday)
End If
End Sub
Private Sub CHKTuesdayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkTuesdayHours.CheckedChanged
If chkTuesdayHours.Checked = True Then
ChkBoxTrue(dtpTimeInTuesday, dtpTimeOutLunchTuesday, dtpTimeInLunchTuesday, dtpTimeOutTuesday)
ElseIf chkTuesdayHours.Checked = False Then
ChkBoxFalse(dtpTimeInTuesday, dtpTimeOutLunchTuesday, dtpTimeInLunchTuesday, dtpTimeOutTuesday)
End If
End Sub
Private Sub CHKWednesdayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkWednesdayHours.CheckedChanged
If chkWednesdayHours.Checked = True Then
ChkBoxTrue(dtpTimeInWednesday, dtpTimeOutLunchWednesday, dtpTimeInLunchWednesday, dtpTimeOutWednesday)
ElseIf chkWednesdayHours.Checked = False Then
ChkBoxFalse(dtpTimeInWednesday, dtpTimeOutLunchWednesday, dtpTimeInLunchWednesday, dtpTimeOutWednesday)
End If
End Sub
Private Sub CHKThursdayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkThursdayHours.CheckedChanged
If chkThursdayHours.Checked = True Then
ChkBoxTrue(dtpTimeInThursday, dtpTimeOutLunchThursday, dtpTimeInLunchThursday, dtpTimeOutThursday)
ElseIf chkThursdayHours.Checked = False Then
ChkBoxFalse(dtpTimeInThursday, dtpTimeOutLunchThursday, dtpTimeInLunchThursday, dtpTimeOutThursday)
End If
End Sub
Private Sub CHKFridayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkFridayHours.CheckedChanged
If chkFridayHours.Checked = True Then
ChkBoxTrue(dtpTimeInFriday, dtpTimeOutLunchFriday, dtpTimeInLunchFriday, dtpTimeOutFriday)
ElseIf chkFridayHours.Checked = False Then
ChkBoxFalse(dtpTimeInFriday, dtpTimeOutLunchFriday, dtpTimeInLunchFriday, dtpTimeOutFriday)
End If
End Sub
Private Sub CHKSaturdayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkSaturdayHours.CheckedChanged
If chkSaturdayHours.Checked = True Then
ChkBoxTrue(dtpTimeInSaturday, dtpTimeOutLunchSaturday, dtpTimeInLunchSaturday, dtpTimeOutSaturday)
ElseIf chkSaturdayHours.Checked = False Then
ChkBoxFalse(dtpTimeInSaturday, dtpTimeOutLunchSaturday, dtpTimeInLunchSaturday, dtpTimeOutSaturday)
End If
End Sub
End Class
It works! It installs! It does everything! :) Okay, I'm excited, but yesterday was a huge day. Not only did I pass my instructor test in my pilot school with a 97, but I also finished my first program. Functionality is completely perfect.
The education I got from this was huge. Google answered nearly all of my questions, but I had to get quite a bit of help from my Supervisor to troubleshoot and help me piece it all together. Some things even baffled him for a second, which made me feel better.
The code is pasted down below. Again, I'm sure there are better ways to do what I've done, but for my first program, I am thrilled to death!
Public Class FRMTimeSheet
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles lblMonday.Click
End Sub
Private Sub Label1_Click_1(sender As Object, e As EventArgs) Handles lblTimeIn.Click
End Sub
Private Sub Label1_Click_2(sender As Object, e As EventArgs) Handles lblTimeOutLunch.Click
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Loads Saturday and Sunday values since the default is blank
ChkBoxTrue(dtpTimeInSunday, dtpTimeOutLunchSunday, dtpTimeInLunchSunday, dtpTimeOutSunday)
ChkBoxTrue(dtpTimeInSaturday, dtpTimeOutLunchSaturday, dtpTimeInLunchSaturday, dtpTimeOutSaturday)
End Sub
Private Sub Label1_Click_3(sender As Object, e As EventArgs) Handles lblLunch.Click
End Sub
Private Sub LBLSchedHours_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles lblGotHoursYet.Click
End Sub
Private Sub SumHours(tTimeIn As DateTimePicker, tTimeOutLunch As DateTimePicker, tTimeInLunch As DateTimePicker, tTimeOut As DateTimePicker, lblSum As Label)
'Totals hours for each day of the week, deducts lunch
Dim t1 As DateTime
Dim t2 As DateTime
Dim t3 As DateTime
Dim t4 As DateTime
Dim tht As TimeSpan
t1 = DateTime.Parse(tTimeIn.Value)
t2 = DateTime.Parse(tTimeOutLunch.Value)
t3 = DateTime.Parse(tTimeInLunch.Value)
t4 = DateTime.Parse(tTimeOut.Value)
tht = t4 - t1 - (t3 - t2)
lblSum.Text = tht.TotalHours
End Sub
Private Sub BTNCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
'Calculates hours for each day of the week, calling the SumHours function
SumHours(dtpTimeInSunday, dtpTimeOutLunchSunday, dtpTimeInLunchSunday, dtpTimeOutSunday, lblSundayHoursTotal)
SumHours(dtpTimeInMonday, dtpTimeOutLunchMonday, dtpTimeInLunchMonday, dtpTimeOutMonday, lblMondayHoursTotal)
SumHours(dtpTimeInTuesday, dtpTimeOutLunchTuesday, dtpTimeInLunchTuesday, dtpTimeOutTuesday, lblTuesdayHoursTotal)
SumHours(dtpTimeInWednesday, dtpTimeOutLunchWednesday, dtpTimeInLunchWednesday, dtpTimeOutWednesday, lblWednesdayHoursTotal)
SumHours(dtpTimeInThursday, dtpTimeOutLunchThursday, dtpTimeInLunchThursday, dtpTimeOutThursday, lblThursdayHoursTotal)
SumHours(dtpTimeInFriday, dtpTimeOutLunchFriday, dtpTimeInLunchFriday, dtpTimeOutFriday, lblFridayHoursTotal)
SumHours(dtpTimeInSaturday, dtpTimeOutLunchSaturday, dtpTimeInLunchSaturday, dtpTimeOutSaturday, lblSaturdayHoursTotal)
Dim sht As Double
Dim mht As Double
Dim tht As Double
Dim wht As Double
Dim thht As Double
Dim fht As Double
Dim saht As Double
Dim ttlHours As Double
sht = lblSundayHoursTotal.Text
mht = lblMondayHoursTotal.Text
tht = lblTuesdayHoursTotal.Text
wht = lblWednesdayHoursTotal.Text
thht = lblThursdayHoursTotal.Text
fht = lblFridayHoursTotal.Text
saht = lblSaturdayHoursTotal.Text
lblTotalHours.Text = sht + mht + tht + wht + thht + fht + saht
ttlHours = sht + mht + tht + wht + thht + fht + saht
'Displays the picture based on hours worked versus hours scheduled
If nudSchedHours.Value > ttlHours Then
picHours.Visible = True
picHours.Image = Image.FromFile("L:\JMay\Pending Projects\Timesheet Pics\Head Shake.gif")
ElseIf nudSchedHours.Value <= ttlHours Then
picHours.Visible = True
picHours.Image = Image.FromFile("L:\JMay\Pending Projects\Timesheet Pics\Colbert Clap.gif")
End If
End Sub
Private Sub Label1_Click_4(sender As Object, e As EventArgs) Handles lblSchedHours.Click
End Sub
Private Sub Label1_Click_6(sender As Object, e As EventArgs) Handles lblSundayHoursTotal.Click
End Sub
Private Sub LBLJedsTimesheetTitle_Click(sender As Object, e As EventArgs) Handles lblJedsTimesheetTitle.Click
End Sub
Private Sub BTNReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
Controls.Clear()
InitializeComponent()
End Sub
Private Sub DateTimePicker1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles dtpTimeInSunday.KeyDown
'Adjusts minutes in 15 minute increments when the up or down button is pushed
If e.KeyCode = Keys.Up Then
dtpTimeInSunday.Value = dtpTimeInSunday.Value.AddMinutes(15)
e.Handled = True
End If
If e.KeyCode = Keys.Down Then
dtpTimeInSunday.Value = dtpTimeInSunday.Value.AddMinutes(-15)
e.Handled = True
End If
End Sub
Private Sub LBLTotalHours_Click(sender As Object, e As EventArgs) Handles lblTotalHours.Click
End Sub
Private Sub Label1_Click_5(sender As Object, e As EventArgs) Handles lblBlankHours.Click
End Sub
Private Sub ChkBoxTrue(fTimeIn As DateTimePicker, fTimeOutLunch As DateTimePicker, fTimeInLUnch As DateTimePicker, fTimeOut As DateTimePicker)
'Sets all dates to the same "standard date" value so that the total when added together = 0
Dim stddate As String
stddate = "7 / 12 / 2017 16:00"
fTimeOut.Visible = False
fTimeOutLunch.Visible = False
fTimeInLUnch.Visible = False
fTimeIn.Visible = False
fTimeIn.Text = stddate
fTimeOutLunch.Text = stddate
fTimeInLUnch.Text = stddate
fTimeOut.Text = stddate
End Sub
Private Sub ChkBoxFalse(fTimeIn As DateTimePicker, fTimeOutLunch As DateTimePicker, fTimeInLUnch As DateTimePicker, fTimeOut As DateTimePicker)
'Sets a default value when the checkbox for each day of the week is unselected
fTimeIn.Visible = True
fTimeOutLunch.Visible = True
fTimeInLUnch.Visible = True
fTimeOut.Visible = True
fTimeIn.Text = "7 / 12 / 2017 08:00"
fTimeOutLunch.Text = "7 / 12 / 2017 12:00"
fTimeInLUnch.Text = "7 / 12 / 2017 13:00"
fTimeOut.Text = "7 / 12 / 2017 17:00"
End Sub
Private Sub PICHours_Click(sender As Object, e As EventArgs) Handles picHours.Click
End Sub
Private Sub NUDSchedHours_ValueChanged(sender As Object, e As EventArgs) Handles nudSchedHours.ValueChanged
End Sub
Private Sub DTPTimeInSunday_ValueChanged(sender As Object, e As EventArgs) Handles dtpTimeInSunday.ValueChanged
End Sub
Private Sub CHKSundayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkSundayHours.CheckedChanged
If chkSundayHours.Checked = True Then
ChkBoxTrue(dtpTimeInSunday, dtpTimeOutLunchSunday, dtpTimeInLunchSunday, dtpTimeOutSunday)
ElseIf chkSundayHours.Checked = False Then
ChkBoxFalse(dtpTimeInSunday, dtpTimeOutLunchSunday, dtpTimeInLunchSunday, dtpTimeOutSunday)
End If
End Sub
Private Sub CHKMondayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkMondayHours.CheckedChanged
If chkMondayHours.Checked = True Then
ChkBoxTrue(dtpTimeInMonday, dtpTimeOutLunchMonday, dtpTimeInLunchMonday, dtpTimeOutMonday)
ElseIf chkMondayHours.Checked = False Then
ChkBoxFalse(dtpTimeInMonday, dtpTimeOutLunchMonday, dtpTimeInLunchMonday, dtpTimeOutMonday)
End If
End Sub
Private Sub CHKTuesdayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkTuesdayHours.CheckedChanged
If chkTuesdayHours.Checked = True Then
ChkBoxTrue(dtpTimeInTuesday, dtpTimeOutLunchTuesday, dtpTimeInLunchTuesday, dtpTimeOutTuesday)
ElseIf chkTuesdayHours.Checked = False Then
ChkBoxFalse(dtpTimeInTuesday, dtpTimeOutLunchTuesday, dtpTimeInLunchTuesday, dtpTimeOutTuesday)
End If
End Sub
Private Sub CHKWednesdayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkWednesdayHours.CheckedChanged
If chkWednesdayHours.Checked = True Then
ChkBoxTrue(dtpTimeInWednesday, dtpTimeOutLunchWednesday, dtpTimeInLunchWednesday, dtpTimeOutWednesday)
ElseIf chkWednesdayHours.Checked = False Then
ChkBoxFalse(dtpTimeInWednesday, dtpTimeOutLunchWednesday, dtpTimeInLunchWednesday, dtpTimeOutWednesday)
End If
End Sub
Private Sub CHKThursdayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkThursdayHours.CheckedChanged
If chkThursdayHours.Checked = True Then
ChkBoxTrue(dtpTimeInThursday, dtpTimeOutLunchThursday, dtpTimeInLunchThursday, dtpTimeOutThursday)
ElseIf chkThursdayHours.Checked = False Then
ChkBoxFalse(dtpTimeInThursday, dtpTimeOutLunchThursday, dtpTimeInLunchThursday, dtpTimeOutThursday)
End If
End Sub
Private Sub CHKFridayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkFridayHours.CheckedChanged
If chkFridayHours.Checked = True Then
ChkBoxTrue(dtpTimeInFriday, dtpTimeOutLunchFriday, dtpTimeInLunchFriday, dtpTimeOutFriday)
ElseIf chkFridayHours.Checked = False Then
ChkBoxFalse(dtpTimeInFriday, dtpTimeOutLunchFriday, dtpTimeInLunchFriday, dtpTimeOutFriday)
End If
End Sub
Private Sub CHKSaturdayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkSaturdayHours.CheckedChanged
If chkSaturdayHours.Checked = True Then
ChkBoxTrue(dtpTimeInSaturday, dtpTimeOutLunchSaturday, dtpTimeInLunchSaturday, dtpTimeOutSaturday)
ElseIf chkSaturdayHours.Checked = False Then
ChkBoxFalse(dtpTimeInSaturday, dtpTimeOutLunchSaturday, dtpTimeInLunchSaturday, dtpTimeOutSaturday)
End If
End Sub
End Class
Comments
Post a Comment