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

New Pet Project

Okay, I've got my next great idea for my pet project. It's a little more complicated, but not terribly. My biggest complaint I had when I transferred from the Detailing Department to the Customer Service department was the loss of my trusty HP48G calculator. This thing was awesome! You calculated feet and inch calculations with formulas. The format was feet.inches and sixteenths. For instance, 14.0608 = 14'-6 1/2". The formulas removed parts of the inputted number and converted them from a foot to a number to add and subtract, and then reconverted the number to a foot answer to display. I and a colleague created several excel sheets that essentially did the same thing, but it just wasn't convenient and didn't flow very well. So, I'm going to create a program that looks close to this calculator. In addition to the addition, subtraction, multiplication, and division of feet-inch numbers, there were formulas that calculated roof slopes, weights, and...

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

Pet Project Progress

Well, I've started my pet project, and I've got a GUI laid out. It's a little slow going, but it should work well in the end, I think. I'm sure there's going to be lots of feedback and many different ways I could do things. Right now, however, I'm limited to what I am learning in the text. As promised, here's the screenshot of my first program. Help? I'm trying not to ask too many people how to write any of the code yet for a couple of reasons. First, I haven't learned any code yet, and I likely won't understand a word of what's being told to me. Second, I'm afraid that what I'll be told I'll understand at that moment, but since I didn't have to work  for it, it won't get burned into my memory like the knowledge I have to seek out. Those long hours searching usually scar you to the point you never want to forget those lessons again. Function Since I don't have too much to show, I'll just explain what th...