Skip to main content

It's Alive!!!

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

Comments

Popular posts from this blog

Starting the Path

Where did it all begin? To start, I love computers. I always have. The technology in them and around us is intimidating to say the least. There are many things I would do differently and wish could be done differently. So, why not me? I decided to actually try computers more than what I had in the past. I can troubleshoot and setup computers with some basic concepts. I couldn't build one from scratch, but then again, I never tried. I loved computers, but it was my hobby. I was afraid that if I turned my hobby into a career, I would lose my hobby because I wouldn't want to mess with computers outside of work. Eventually, you just have to get past that and try it out. I had been in Customer Service for over a decade. I excelled quickly in that department, but it became very clear after several efforts that I was simply not going to move forward in that department. Though I had advanced most of their technology from the first year I was there, created and wrote several poli

Time Management

Codefighting Progress Okay, first, if you're not following my other blogs, it's worth noting that I'm simultaneously studying to become a pilot. I had no idea the time it's going to take to study everything for the flight school. The amount of information covered is insane and demanding. I'm going to keep both up, but not nearly at the pace I had initially hoped. The actual ground school lasts 12 weeks, and then I take a written test. I'll have to get actual flight time in and eventually take the flight test within 2 years to be a full blown pilot. That being said to iterate how much my focus will be divided briefly, but I will come back more focused to this task at hand. I'm in the 2nd week of the 12 week close so only 2 1/2 months left, then my flying time is only on the weekends. I'll figure out how to do that. As far as the what I've been doing lately, well, I haven't progressed further than the 2nd chapter in the book. In my spare

Progress on the Pet Project

So, I don't have much, but I do have some. Behold my genius code for my hours calculation:     Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click         Dim s1 As Integer         Dim s2 As Integer         Dim s3 As Integer         Dim s4 As Integer         s1 = Val(txtTimeInSunday.Text)         s2 = Val(txtTimeOutLunchSunday.Text)         s3 = Val(txtTimeInLunchSunday.Text)         s4 = Val(txtTimeOutSunday.Text)         lblSundayHoursTotal.Text = s4 - s1 - (s3 - s2)         Dim m1 As Integer         Dim m2 As Integer         Dim m3 As Integer         Dim m4 As Integer         s1 = Val(txtTimeInMonday.Text)         s2 = Val(txtTimeOutLunchMonday.Text)         s3 = Val(txtTimeInLunchMonday.Text)         s4 = Val(txtTimeOutMonday.Text)         lblMondayHoursTotal.Text = m4 - m1 - (m3 - m2)         Dim t1 As Integer         Dim t2 As Integer         Dim t3 As Integer         Dim t4 As Integer         s1 = Val(txtTime