Writing /home/cknows/public_html/support/data/cache/2/22aa48cd3673276f91563549c76f640e.captchaip failed
taxengine:integration:code_samples:visual_basic_sample_code
Sample Code in Visual Basic
Please see Getting Started for help with using the KampData TaxEngine.
Imports System
Imports System.Array
Imports System.Runtime.InteropServices
Imports System.Collections
Imports KampData.TaxEngine.API.Enums
Imports KampData.TaxEngine.API
Module VBClient
Dim zip As String
Dim state As String
Dim county As String
Dim city As String
Dim message As String
Dim server As String
Dim userId As String
Dim password As String
Dim companyDatabase As String
Dim timeOutSeconds As Short
Dim loginMessage As String
Dim docNumber As String
Dim sourceModule As String
Dim docType As Short
Dim lineNumber As Integer
Dim abort As Boolean
Dim createTables As Boolean
Dim cityNotChosen As Boolean
Dim countyNotChosen As Boolean
Dim displayProgressBar As Boolean
Dim useSqlPassword As Boolean
Dim cities As ArrayList
Dim counties As ArrayList
Dim states As ArrayList
Dim txEngn As Portal
' The VBClient object is a simple example of how the KampData
' TaxEngine can be utilized from a 3rd party application. This sample
' is not intended to be comprehensive. It simply illustrates the access
' methods.
' To use the KampData TaxEngine in this sample, or in any other
' project, you must first setup the SOP module from the KDControlCenter.exe's
' Transaction Source Module Setup window. Please see "Getting Started"in the
' KDTaxEngine.chm help file for more information.
Sub Main()
abort = False
cities = New ArrayList
counties = New ArrayList
states = New ArrayList
server = "Microsoft SQL Server®"
userId = "User"
password = "Password"
companyDatabase = "TWO"
timeOutSeconds = 60
loginMessage = ""
displayProgressBar = True
useSqlPassword = False
' KampData.TaxEngine object must be instantiated.
txEngn = New Portal
Try
' The TaxEngine.Login method makes the connection to Microsoft SQL Server® and
' prepares the TaxEngine for use.
txEngn.Login(server, userId, password, companyDatabase, timeOutSeconds, displayProgressBar, useSqlPassword)
Catch ex As Exception
loginMessage = ex.Message
End Try
If loginMessage <> "" Then
abort = True
Console.WriteLine(loginMessage)
Console.WriteLine("Press ENTER to continue")
Console.ReadLine() ' To hold window open displaying error message.
End If
If Not abort Then
' Set the docType and module using the values you have setup
' in the KDWindowClient.exe's Transaction Source Module Setup
' and Document Type Setup windows. In the SOP module, invoices are
' docType 3.
docType = 3
sourceModule = "SOP"
' You must assign a document number at this point. You can use a
' document number generated by your order entry software
' that will call the TaxEngine, or you can use the following code
' to generate a document number.
docNumber = txEngn.NextDocumentNumber(sourceModule)
' The DocSaleOrPurchase property defaults to the Transaction Type
' used when creating the sourceModule in the KDControlCenter.exe.
' Setting this property is only necessary when you are either
' NOT using a sourceModule or when using a Transaction Type that is
' different from the Transaction Type that the sourceModule was
' created for.
txEngn.DocSaleOrPurchase = SalesOrPurchases.Sales
' Initialize the document. In this example I am using a document
' number, document type, and sourceModule that have been setup in
' the KDControlCenter.exe. However, it is possible to call the
' method below using a blank document number, -1 for the docType,
' and a blank sourceModule.
txEngn.Document(docNumber, docType, sourceModule)
' You would normally set your customer id at this point along with
' any other document defaults. For purposes of this demonstration,
' we will skip that step as we have no need to consider customer
' taxability.
' txEngn.DocCustomerID = "AARONFIT0001";
' We now add a line to the order. The addressing and taxation
' features occur on the line level so this step is required to
' instantiate a line object. We recommend using the lineNumber
' as it exists in your order entry system. That way the TaxEngine
' line and the order entry line can be matched and verified.
lineNumber = 1
txEngn.LineAdd(lineNumber)
Do
' We now provide the ZIP Code.
Console.WriteLine("Enter a ZIP Code")
zip = Console.ReadLine()
If zip = "" Or zip.ToUpper() = "EXIT" Then
Exit Do
End If
Try
txEngn.LineZip = zip
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.WriteLine("")
' At this point the Portal object will have identified and made
' available the default city, county and state for the ZIP provided.
' Also, the default tax schedule will be identified, and made available.
' The following call prints these defaults:
Console.WriteLine("Count found: {0} Default: {1}, [{2}] {3} {4}", _
txEngn.LineAddressesInZip(), txEngn.LineCity, txEngn.LineCounty, txEngn.LineState, txEngn.LineZip)
End Try
' Some ZIP codes are valid for more than one city, county and or state.
' The Portal object can provide ArrayLists of the available choices.
' The ArrayLists include:
' All States in the current ZIP.
' All Cities in the current state and ZIP.
' All Counties in the current city, state and ZIP.
' For example, if you change the city, the list of possible counties
' may changes.
' You select the state, city and county in the same way that you select
' the ZIP. (ie txEngn.LineCity = "New Orleans";)
If txEngn.LineAddressesInZip() > 1 Then
states = txEngn.LineStatesInZip()
Console.WriteLine("States in ZIP:")
For Each state In states
Console.WriteLine(" State of {0}", state)
Next
If states.Count > 1 Then
Console.WriteLine("Enter a state. Press ENTER for {0}", _
txEngn.LineState)
state = Console.ReadLine()
If state <> "" Then
txEngn.LineState = state
End If
End If
End If
cities = txEngn.LineCitiesInStateAndZip()
Console.WriteLine("Cities in {0} state and {1} ZIP:", txEngn.LineState, _
txEngn.LineZip)
For Each city In cities
Console.WriteLine(" City of: {0} ", city)
Next
If cities.Count > 1 Then
cityNotChosen = True
While cityNotChosen
Console.WriteLine("Enter a city. Press ENTER for {0}", txEngn.LineCity)
city = Console.ReadLine()
If city = "" Then
cityNotChosen = False
Else
Try
txEngn.LineCity = city
cityNotChosen = False
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End If
End While
End If
counties = txEngn.LineCountiesInCityStateAndZip()
Console.WriteLine("Counties in {0}, {1} {2}:", txEngn.LineCity, _
txEngn.LineState, txEngn.LineZip)
For Each county In counties
Console.WriteLine(" County of {0}", county)
Next
If counties.Count > 1 Then
countyNotChosen = True
While countyNotChosen
Console.WriteLine("Enter a city. Press ENTER for {0}", txEngn.LineCity)
county = Console.ReadLine()
If county = "" Then
countyNotChosen = False
Else
Try
txEngn.LineCounty = county
countyNotChosen = False
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End If
End While
End If
' In city limits is assumed. This line exists here only to
' illustrate that the option can be set after the city has
' been specified.
txEngn.LineInCityLimits = True
If txEngn.DocReselectionRequired Then
txEngn.LineTaxScheduleSelect()
End If
Console.WriteLine("Tax Schedule [{0}] {1} Rate: {2}", _
txEngn.LineTaxScheduleID, txEngn.LineTaxScheduleDescription, txEngn.LineInitialTaxPercent)
Console.WriteLine()
Loop While zip <> "" And zip.ToUpper() <> "EXIT"
End If
End Sub
End Module
taxengine/integration/code_samples/visual_basic_sample_code.txt · Last modified: 2015/06/12 18:47 by conni