Skip to main content

I Stray Further

Progress

Okay, my pet project is going okay. I'm learning the questions to ask, in any case. I have strayed exceptionally far from the book. I was hoping to do both simultaneously. That hasn't worked out at all. Here's what it's become so far:


The picture on the right changes. If you've got all your hours in, it's a happy face, sad face if you don't.

What I Know and Don't Know

I have figured out how to use the date picker. I cannot for the life of me figure out how to get the up arrows in each box to correspond to 15-minute increments. I found code to do it, but it's not working for me. I probably have it in the wrong spot or something.

    Private Sub DateTimePicker1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles dtpTimeInSunday.KeyDown
        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

I don't understand half of the first line, and I don't understand the "e" values at all, but I understand the rest of it.

I also understand how to create functions I can call on later. That part was very awesome that I learned from my boss. He took about 15 minutes to show me how to get it to work via Skype.

Granted, he did torment me by telling me he wrote all of the code for the program in about two minutes, while I spent weeks trying to figure out how to do it. I did cave and have to get him to help me.

I commented out his stuff, but kept it in the code for reference. It took me a while to understand how this worked, but once I did, it actually made sense pretty quickly. 

Concerns

I have concerns. First, I don't know if I could replicate all of this again on my own. I'd almost certainly have to have help again, but not nearly the amount as last time. I haven't memorized all of the timespan DateTime.Parse function stuff yet. It's getting there, but I'm struggling with it.

The other concern is the book. There's very likely some minimal things I need to go back and learn before I get much further. Time is an issue. I have a lot of other going on. The others are just excuses, however. I need to get on the book and learn more basics. I also think going back to college in January will be a big help moving forward with this. Not just financially (which is always a goal), but professionally, which is my main goal. I love this coding stuff, even if it is frustrating at times. I can't believe I'm actually doing it. Even if it's on the side right now, it's still a dream come true.

Upcoming Challenges

I have a couple of steps to take next.

First, I learned how to create a math function that does the same arithmetic. The first time I did the calculations for the total hours for each day of the week, I wrote out the formula each time for each day of the week (seven times, if you're keeping up). My boss showed me how to just write one function, and call it back with each day of the week. In other words, I can write the formula one time, leave the variables generic, and fill them in by calling the function and including the specific variables each time (one formula, seven lines to call them). This not only saved a tone of typing, but it also made it easier to read, and if I have to change the code, I only have to change it in one place. Very cool. So, I have some formatting that needs to change (I think) whenever you don't work any hours. I have stuff that disappears, and I tried it with Sunday. it seems to be working so far, somewhat, but I don't want to have to duplicate this for each day of the week. 

    Private Sub CHKSundayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkSundayHours.CheckedChanged

        dtpTimeInSunday.CustomFormat = "hh:mm tt"
        dtpTimeOutLunchSunday.CustomFormat = "hh:mm tt"
        dtpTimeInLunchSunday.CustomFormat = "hh:mm tt"
        dtpTimeOutSunday.CustomFormat = "hh:mm tt"
        If chkSundayHours.Checked = True Then
            dtpTimeInSunday.Text = "7 / 12 / 2017 16:00"
            dtpTimeInSunday.Visible = False
            dtpTimeOutLunchSunday.Text = "7 / 12 / 2017 16:00"
            dtpTimeOutLunchSunday.Visible = False
            dtpTimeInLunchSunday.Text = "7 / 12 / 2017 16:00"
            dtpTimeInLunchSunday.Visible = False
            dtpTimeOutSunday.Text = "7 / 12 / 2017 16:00"
            dtpTimeOutSunday.Visible = False
        Else
            If chkSundayHours.Checked = False Then
                dtpTimeInSunday.CustomFormat = "hh:mm tt"
                dtpTimeOutLunchSunday.CustomFormat = "hh:mm tt"
                dtpTimeInLunchSunday.CustomFormat = "hh:mm tt"
                dtpTimeOutSunday.CustomFormat = "hh:mm tt"
                dtpTimeInSunday.Visible = True
                dtpTimeOutLunchSunday.Visible = True
                dtpTimeInLunchSunday.Visible = True
                dtpTimeOutSunday.Visible = True
                dtpTimeInSunday.Text = "7 / 12 / 2017  08:00"
                dtpTimeOutLunchSunday.Text = "7 / 12 / 2017  12:00"
                dtpTimeInLunchSunday.Text = "7 / 12 / 2017 13:00"
                dtpTimeOutSunday.Text = "7 / 12 / 2017 17:00"
            End If
        End If
    End Sub

There almost has to be some kind of way to translate the stuff above to a function, but I haven't figured that out yet.

My second challenge is the comparison. I need to be able to do a comparison between the scheduled hours chosen from the number picker and the total hours calculated. I got the total hours to calculate so far (using the long Sunday calculations checkbox shown above only), but it's calculating every other week, provided it has hours, but I can't get a comparison. Something to do with a String and Double types or something like that. I'll figure that out eventually, but I haven't got it yet. Once I get that, the photo should work, and I'm almost done.

The last, and convenient challenge, is the DateTimePicker boxes. I want the 15-minute intervals. That would be important if this were a real project. I have the answers, but I don't know where to put it yet.

If I figure these three things out, I'll be in excellent shape.

Under the Hood

Well, below is all of the code on my project thus far. Some things are incomplete, as I noted above, but it's all here.

Public Class FRMTimeSheet
    Public Sub SetMyCustomFormat()
        dtpTimeInSunday.Format = DateTimePickerFormat.Custom
        dtpTimeInSunday.CustomFormat = "hh:mm tt"
    End Sub

    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

    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)
        Dim t1 As DateTime
        Dim t2 As DateTime
        Dim t3 As DateTime
        Dim t4 As DateTime
        Dim tht As TimeSpan

        t1 = DateTime.Parse(tTimeIn.Text)
        t2 = DateTime.Parse(tTimeOutLunch.Text)
        t3 = DateTime.Parse(tTimeInLunch.Text)
        t4 = DateTime.Parse(tTimeOut.Text)
        tht = t4 - t1 - (t3 - t2)
        lblSum.Text = tht.TotalHours

    End Sub

    Private Sub BTNCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click

        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

        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

    End Sub

    '    Private Sub SumUpHours(tTimeIn As TextBox, tTimeOutLunch As TextBox, tTimeInLunch As TextBox, tTimeOut As TextBox, lblSum As Label)
    '        Dim t1 As Double
    '        Dim t2 As Double
    '        Dim t3 As Double
    '        Dim t4 As Double
    '        Dim tht As Double

    '        t1 = Val(tTimeIn.Text)
    '        t2 = Val(tTimeOutLunch.Text)
    '        t3 = Val(tTimeInLunch.Text)
    '        t4 = Val(tTimeOut.Text)
    '        tht = t4 - t1 - (t3 - t2)
    '        lblSum.Text = tht.ToString

    '    End Sub

    'SumUpHours(TextBox1, TextBox2, TextBox3, TextBox4, Label1) 
    'SumUpHours(txtTimeInMonday, txtTimeOutLunchMonday, txtTimeInLunchMonday, txtTimeOutMonday, lblMondayHoursTotal)

    'you can use DateTime.Parse To convert your textbox values To Date objects, subtract those objects To Return a TimeSpan Object, Then write out the hours To the label.  I did it And got the 8.5 hours expected.



    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
        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 DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles dtpTimeInSunday.ValueChanged

    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 CheckboxYes(cTimeIn, cTimeOutLunch, cTimeInLunch, cTimeout)

        Dim c1 As DateTime
        Dim c2 As DateTime
        Dim c3 As DateTime
        Dim c4 As DateTime

        c1 = DateTime.Parse(cTimeIn.Text)
        c2 = DateTime.Parse(cTimeOutLunch.Text)
        c3 = DateTime.Parse(cTimeInLunch.Text)
        c4 = DateTime.Parse(cTimeout.Text)

        '        c1.visible

    End Sub

    Private Sub CHKSundayHours_CheckedChanged(sender As Object, e As EventArgs) Handles chkSundayHours.CheckedChanged

        dtpTimeInSunday.CustomFormat = "hh:mm tt"
        dtpTimeOutLunchSunday.CustomFormat = "hh:mm tt"
        dtpTimeInLunchSunday.CustomFormat = "hh:mm tt"
        dtpTimeOutSunday.CustomFormat = "hh:mm tt"
        If chkSundayHours.Checked = True Then
            dtpTimeInSunday.Text = "7 / 12 / 2017 16:00"
            dtpTimeInSunday.Visible = False
            dtpTimeOutLunchSunday.Text = "7 / 12 / 2017 16:00"
            dtpTimeOutLunchSunday.Visible = False
            dtpTimeInLunchSunday.Text = "7 / 12 / 2017 16:00"
            dtpTimeInLunchSunday.Visible = False
            dtpTimeOutSunday.Text = "7 / 12 / 2017 16:00"
            dtpTimeOutSunday.Visible = False
        Else
            If chkSundayHours.Checked = False Then
                dtpTimeInSunday.CustomFormat = "hh:mm tt"
                dtpTimeOutLunchSunday.CustomFormat = "hh:mm tt"
                dtpTimeInLunchSunday.CustomFormat = "hh:mm tt"
                dtpTimeOutSunday.CustomFormat = "hh:mm tt"
                dtpTimeInSunday.Visible = True
                dtpTimeOutLunchSunday.Visible = True
                dtpTimeInLunchSunday.Visible = True
                dtpTimeOutSunday.Visible = True
                dtpTimeInSunday.Text = "7 / 12 / 2017  08:00"
                dtpTimeOutLunchSunday.Text = "7 / 12 / 2017  12:00"
                dtpTimeInLunchSunday.Text = "7 / 12 / 2017 13:00"
                dtpTimeOutSunday.Text = "7 / 12 / 2017 17:00"
            End If
        End If
    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

        Dim schedhrs As Double
        Dim totalhrs As Double

        schedhrs = lblSchedHours.Text
        totalhrs = lblTotalHours.Text

        If schedhrs >= totalhrs Then
            picHours.Visible = True
            picHours.Image = Image.FromFile("C:\Users\jed.may\Pictures\Rage\Crying Girl.jpg")
        End If
        If schedhrs < totalhrs Then
            picHours.Visible = True
            picHours.Image = Image.FromFile("C:\Users\jed.may\Pictures\Rage\All The Things.jpg")
        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...