I am a beginner with VB, I'm coming from C++. When I compile and test the program the base pay textbox changes to 0, gross pay textbox to 0 and the total deductions turns to 0.25. For the life of me I can't figure out why. My little experience with python and C++ tells me that its something simple that I overlooked. Any help would be appreciated, Thank You.

Public Class Form1

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()

    End Sub

  
    Private Sub btnCal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCal.Click
        Dim payRate As Decimal
        Dim grossPay As Decimal
        Dim totalDeds As Decimal = 0.25
        Dim netPay As Decimal
        Dim hoursWorked As Integer


        grossPay = hoursWorked * payRate

        netPay = grossPay - grossPay * totalDeds

        textboxBasePay.Text = payRate
        lblGrossPay.Text = grossPay
        lblTotalDeductions.Text = totalDeds
        lblNetPay.Text = netPay



    End Sub
End Class

It's because your payRate and grossPay isn't assigned anything (if this is all your code). You should be getting these values from a textbox in the program no?
What you should do is break through your program. VB.Net allows you to step through in runtime.
To do this, simply click on the left panel beside your btnCal_Click Procedure to start the stepping as soon as you click the button when the programs running.
In debug mode, press F11 to step to the next millisecond. You'll see the line turn yellow. When it's yellow you can mouseover any variable to see the current value assigned to it. This should give you an idea as to what's happening during runtime.

The hints I can give you are:

- your payRate should either be a constant number, ex: dim const payRate as decimal = 8.90
or assigned a number from a user. Otherwise it'll always be zero.

- Try to remember which side of the equals sign programming languages look at first.

- You should be assigning your variables values before you do calculations on them. In C++ terms, your variables are NULL when you do your calcs.

The rest should be a breeze. Hope this helps

Good luck

Thanks for you quick response but I'm still having troubles, I fixed the equal sign thing ( I should have known that). payRate is define by user input. on the grossPay = lblGrossPay.Text line I get an error when it debugs " Conversion from string "" to type 'Decimal' is not valid." . I'm very stumped.

Public Class Form1

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()

    End Sub

  
    Private Sub btnCal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCal.Click
        Dim payRate As Decimal
        Dim grossPay As Decimal
        Dim totalDeds As Decimal = 0.25
        Dim netPay As Decimal
        Dim hoursWorked As Integer

        payRate = textboxBasePay.Text

        grossPay = hoursWorked * payRate
        grossPay = lblGrossPay.Text

        netPay = grossPay - grossPay * totalDeds
        netPay = lblNetPay.Text

        totalDeds = lblTotalDeductions.Text


    End Sub
End Class

I'm assuming lblGrossPay is where you want to display the value?
If so, you have to switch up the sides. lblGrossPay.text = grossPay
same goes for netPay.

otherwise, looks good man.

cheers,

Lee

Thanks for you quick response but I'm still having troubles, I fixed the equal sign thing ( I should have known that). payRate is define by user input. on the grossPay = lblGrossPay.Text line I get an error when it debugs " Conversion from string "" to type 'Decimal' is not valid." . I'm very stumped.

Public Class Form1

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()

    End Sub

  
    Private Sub btnCal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCal.Click
        Dim payRate As Decimal
        Dim grossPay As Decimal
        Dim totalDeds As Decimal = 0.25
        Dim netPay As Decimal
        Dim hoursWorked As Integer

        payRate = textboxBasePay.Text

        grossPay = hoursWorked * payRate
        grossPay = lblGrossPay.Text

        netPay = grossPay - grossPay * totalDeds
        netPay = lblNetPay.Text

        totalDeds = lblTotalDeductions.Text


    End Sub
End Class

you must a value to hoursWorked and swap grossPay and lblGrossPay.Text as grossPay = lblGrossPay.Text to display as well as netPay and totalDeds

Thanks and sorry but I'm still having problems. I've added a value for hoursWorked as hoursWorked = textboxHours.Text. I'm still getting zero values for gross pay, total deductions, and net pay when I click the calculate button.

Public Class Form1

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()

    End Sub

  
    Private Sub btnCal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCal.Click
        Dim payRate As Decimal
        Dim grossPay As Decimal
        Dim totalDeds As Decimal = 0.25
        Dim netPay As Decimal
        Dim hoursWorked As Integer

        payRate = textboxBasePay.Text

        grossPay = hoursWorked * payRate
        lblGrossPay.Text = grossPay

        netPay = grossPay - grossPay * totalDeds
        lblNetPay.Text = netPay

        lblTotalDeductions.Text = totalDeds
        hoursWorked = textboxHours.Text


    End Sub
End Class

You run grossPay = hoursWorked * payRate

payRate is defined above it but hoursWorked is not - therefore it looks like you're running

grossPay = 0 * (the value of the textbox)

-- move your hoursWorked = textboxHours.Text to above the grossPay = hoursWorked * payRate and see if that helps.

commented: a great help +2

Thank you so much that worked, it makes complete sense, Thank You. I learned for the future.

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.