I have an assignment to make a program for Time Entry. I am trying to get it where the Get payment button is disabled when the program first executes and then enables once I have submitted hours for five days. Below is the code I have so far and any help would be greatly appreciated!

Public Class TimeEntry

    Private Sub submitButton_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles submitButton.Click

        If hoursTextBox.Text <> String.Empty Then
            recordsListBox.Items.Add(hoursTextBox.Text)
            hoursTextBox.Clear()
        End If

        hoursTextBox.Focus()
    End Sub


    Private Sub getButton_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles getButton.Click

        Dim total As Integer
        Dim hoursCounter As Integer
        Dim hours As Integer

        total = 0
        hoursCounter = 0
        hours = 0

        Do While hoursCounter <= 5
            hoursCounter = recordsListBox.Items(hoursCounter)
            total += hours
            hoursCounter += 1
        Loop

        If hoursCounter < 0 Then
            paymentLabel.Text = "No hours were entered!"
        ElseIf hoursCounter < 21 Then
            paymentLabel.Text = String.Format("{0:F}", hoursCounter * 10)
        ElseIf hoursCounter < 31 Then
            paymentLabel.Text = String.Format("{0:F}", hoursCounter * 12)
        ElseIf hoursCounter < 41 Then
            paymentLabel.Text = String.Format("{0:F}", hoursCounter * 12)
        Else
            paymentLabel.Text = "Too many hours were entered!"
        End If
    End Sub

    Private Sub clearButton_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles clearButton.Click

        recordsListBox.Items.Clear()
        paymentLabel.Text = String.Empty
        submitButton.Enabled = True
        getButton.Enabled = False
        hoursTextBox.Focus()
    End Sub
End Class

Recommended Answers

All 5 Replies

You will need to change the Get Payment button's Enabled property to False and then add the following line of code to the submitButton:

Private Sub submitButton_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles submitButton.Click
 
        If hoursTextBox.Text <> String.Empty Then
            recordsListBox.Items.Add(hoursTextBox.Text)
            hoursTextBox.Clear()
        End If
        'Enables the Button
        getPayment.Enabled = True
        hoursTextBox.Focus()
    End Sub

I was able to get it where the buttons are performing correctly after I enter the first number however I am supposed to have the Get payment button disabled when the program executes and then when I clear the time it should go back to the beginning so I can execute the program again but it does not. Any advice on this?

Yeah, just add the code I gave you onto the clear button:

getPayment.Enabled = True

This should make the button enabled after you clear the time.

Ok everything is working perfectly except for when I start the program the get payment button is enabled and doesn't disable until after I enter the hours for the first day. Where do I need to put the getButton.Enabled = False to make is disabled when the program starts?

You can either click on the button and in the properties menu find where it says Enabled and change it to false or you can add the following code to the Form_Load Event:

getPayment.Enabled = False
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.