Question How write a code to display the answer of values of two textboxes in another textbox

godis3034

New member
Joined
May 6, 2018
Messages
2
Programming Experience
Beginner
I am a beginner in Visual Studio 2015 database development. I want to build an employees payroll. I want to write a code to display the added values of the Basic Salary and Allowances textboxes in the Gross Salary textbox, and then display in the Net Salary textbox the value after Deductions textbox value has been subtracted from the Gross Salary value automatically, when I input values into the Basic Salary, Allowances and Deductions textboxes. I have tried all efforts but to no avail.

I will be very grateful if somebody would help me with a sample to succeed.

Regards,

Godis3034
 
Last edited:
What have you done and where are you stuck? If you haven't done anything then I'd suggest that you need to learn a few things about VB.NET development first, rather than trying to find something to copy. There's a tutorial link in my signature below. You probably ought to at least work your way through that.
 
I used the code below but got stacked. The results didn't display in the Gross Salary and the Net Salary:
Private Sub BtnCalcu_Click(sender As Object, e As EventArgs) Handles BtnCalcu.Click

    Dim BasicSalary, Allowances, GrossSalary, Deductions, NetSalary As Decimal

    BasicSalary = txtBasicSalary.Text
    Allowances = txtAllowances.Text
    GrossSalary = txtGrossSalary.Text
    Deductions = txtDeductions.Text
    NetSalary = txtNetSalary.Text
    GrossSalary = Val(BasicSalary) + Val(Allowances)
    NetSalary = Val(GrossSalary) - Val(Deductions)

I need corrections at where I erred.

Regards,

Godis3034
 
Last edited:
I have reformatted your code snippet using appropriate tags, i.e.

[xcode=vb]your code here[/xcode]

Please do that for us in future.

As for the issue, your code declares some variables, retrieves data into some of those variables from some TextBoxes, performs a couple of calculations and puts the results into another couple of variables, then does nothing more. There's no code to display anything so why would you expect anything to be displayed? Look at the code you already have to get data from controls into variables. Based on that, how do you suppose that you would get data from variables into controls, i.e. go the opposite way?

As it stands, you're populating the GrossSalary and NetSalary variables from controls before you do the calculations. Surely what you should be doing is populating the controls from the variables after the calculations. This is what comes from trying to write code without knowing what it is supposed to do. I don't mean the end result; I mean the steps to get to the end result. If you actually written down the steps you needed to perform in order to get your result and then written code to implement those steps, there's no way you'd have ended up with that code.
 
Back
Top