Here we take you through the first steps in using TaxControls in your application. (Be sure to select the proper platform for your environment.)
Set up the environment
- Download the .NET component from here.
- Open a command-line window.
- In the resulting command prompt, type the following:
- Create a project directory.
Two methods can be used to compile and execute code on the .NET platform: Microsoft's Visual Studio .NET, and the Mono project. For this tutorial, we will use the command-line tools available with Visual Studio 2022.
Click the Windows Start button, then select Visual Studio 2022
, then Developer Command Prompt for VS 2022
.
csc /version
You should see output similar to this if your environment is set up correctly:
4.0.1-1.21568.1 (6ab66011)
We're using the name "TaxDemo" under the user's home directory:
cd %HOMEPATH%
mkdir TaxDemo
cd TaxDemo
Instantiate the TaxControls object
- Create and test the object.
- Compile the code.
- Run the code.
In your project directory, create a new file called 'Instantiate.cs'. Enter the following code and save the file:
using System;
using TaxControls;
class Instantiate {
public static voic Main() {
CTaxControl tc = new CTaxControl();
Console.WriteLine(tc.SoftwareVersion);
}
}
At the command prompt enter:
csc /reference TaxControls.dll Instantiate.cs
At the command prompt enter:
Instantiate.exe
The program should print a version number for TaxControls on the console.
Compute a withholding amount
- Enter the following code into a file named 'Compute.cs':
- Compile the code.
- Run the code.
using System;
using TaxControls;
class Compute {
public static void Main() {
CTaxControl tc = new CTaxControl();
tc.DataFilename = "demo.tax";
try {
tc.SelectedTax = "federal income tax";
tc.Earnings = 2000.00;
Console.WriteLine(tc.TaxAmount());
} catch(TaxControlException e) {
Console.WriteLine(e);
}
}
}
At the command prompt enter:
csc /reference TaxControls.dll Compute.cs
At the command prompt enter:
Compute.exe
The program should print a computed withholding amount on the console, which you can check against an online payroll calculator such as NanoCalc using the same earnings, selecting Monthly payroll, and checking the "2020 W-4" field. Results should match those labelled "Federal tax".
List all tax names
- Enter the following code into a file named 'List.cs':
- Compile the code.
- Run the code.
using System;
using System.Collections;
using TaxControls;
class List {
public static void Main() {
CTaxControl tc = new CTaxControl();
tc.DataFilename = "demo.tax";
try {
Taxes txs = tc.Taxes;
IEnumerator inr = txs.GetEnumerator();
while(inr.MoveNext()) {
Tax t = (Tax) inr.Current;
Console.WriteLine(t.Name);
}
} catch(TaxControlException e) {
Console.WriteLine(e);
}
}
}
At the command prompt enter:
csc /reference TaxControls.dll List.cs
At the command prompt enter:
List.exe
The program should print many tax names to the console.
List state tax names
- Enter the following code into a file named 'States.cs':
- Compile the code.
- Run the code.
using System;
using System.Collections;
using TaxControls;
class States {
public static void Main() {
CTaxControl tc = new CTaxControl();
tc.DataFilename = "demo.tax";
try {
Taxes txs = tc.Taxes;
IEnumerator inr = txs.GetEnumerator();
while(inr.MoveNext()) {
Tax t = (Tax) inr.Current;
if (t.TaxType == "S") {
Console.WriteLine(t.Name);
}
}
} catch(TaxControlException e) {
Console.WriteLine(e);
}
}
}
At the command prompt enter:
csc /reference TaxControls.dll States.cs
At the command prompt enter:
States.exe
The program should print state tax names to the console.
Look up taxes for a ZIP code
- Enter the following code into a file named 'Zip.cs':
- Compile the code.
- Run the code.
using System;
using TaxControls;
class Zip {
public static void Main() {
CTaxControl tc = new CTaxControl();
tc.DataFilename = "demo.tax";
try {
// Employee lives and works in Ohio:
String s = tc.TaxNamesForZip(44139, 44145);
Console.WriteLine(s);
} catch(TaxControlException e) {
Console.WriteLine(e);
}
}
}
At the command prompt enter:
csc /reference TaxControls.dll Zip.cs
At the command prompt enter:
Zip.exe
The program should print a comma-delimited string of tax names on the console. Note that Federal and Social Security taxes apply regardless of ZIP code, and are not returned by TaxNamesForZip().
Because ZIP code boundaries do not generally align well with tax jurisdiction boundaries, we recommend the use of the TaxQuery container, which uses employee workplace and residence addresses to identify relevant tax names.