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

Detailer Calculator GUI

I'm probably not done. I'm going to sit on this design for a day or two to see how it feels. I had a suggestion about adding a right triangle showing people base, slope, rise, angle, etc. I'm kind of torn on that part. In essence, this is probably about 90% done as far as the User Interface goes. I like it, I think. I'm hoping to be able to pass the keyboard strokes directly into the program, rather than have someone point and click. If I can get that done, the flow will be ten times better. I'm excited about the math involved and the fact that this will actually be functional. There are two things I'm struggling with right now. The first is the programming language. I've mentioned this before, I believe, but the programs my group works with are all programmed in VB.net. So, that's the language I'm learning right now. The problem, however, is that the system architect here at work is telling everyone that any new programs should be written in...

Big Scare

I learned an important lesson. Actually, I learned a few lessons. The first lesson - always back up. Have copies of files if backing up isn't easy. Next, it's a good idea to not proceed too far without checking to make sure everything still work, while you can still undo something. Third, and more specifically, apparently, renaming certain items in Visual Studio can completely erase a design. Let me explain... To recap, Visual Studio is the IDE I use to write my programs. I'm learning the VB.Net programming language because that's the language the software my company maintains was written in. It makes sense to get more familiar with that. I'm still extremely  new to Visual Studio, and I'm very new to coding and general coding principles. I'm reading tons of books (often at the same time) to get general coding practices, as well as very specific programming details for VB.Net. All this combined to say, I'm still learning, and I'm really new. No...

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...