Contents 

Fast Start
Weight Scale Interfacing (Digi D770)
What Is Visual Builder?
What's New In Visual Builder?
Creating A CAPITAL Form
Creating a Form - Conceptual Overview
Creating a Form - Quick Guide For Advanced Users
The Forms Wizard
Creating A CAPITAL Report
The Label Wizard
Report Wizard Tutorial
New & Revised Topics in CAPITAL 7.5
AllocatePayment()
CrossTab()
CreateTable()
EventAdd()
FilterTable()
Find()
PayMethodName()
ReadINI()
SendHTMLMail()
TranInfo()
WriteNote()
New & Revised Topics in CAPITAL 7.41
AddPayment()
Business Functions Listing
BufferCommit()
BufferRollBack()
BufferUpdates()
ExportASCII()
GetFolder()
KitList()
LockRecord()
ReadNote()
ReadTextFile()
StockQuantity()
StrWrap()
WriteTextFile()
New & Revised Topics in CAPITAL 7.4
Business Functions Listing
CompanyName()
Department()
Field Objects
JobInfo()
Linking
Moving & Resizing Body Objects
Operators & Expressions
OrderTable()
PathData()
Picture Object Properties
ReadINI()
ReadNote()
RunApplication()
Sample Scripts
Send Product Info Email With Pictures
Start-up Switches
StockAnalysis()
TagInfo()
TranWrite()
WriteINI()
New & Revised Topics in CAPITAL 7.3
AddStock()
AddTraceProperty()
BackAllocate()
Business Functions Listing
CardFileBill()
ComError()
ComClose()
ComOpen()
ComRead()
ComSetup()
ComWrite()
ComputerName()
EchoBox()
EchoBoxOn()
EchoBoxOff()
LockSemaphore()
PasswordInfo()
ScriptRun()
TodoAdd()
Trouble-Shooting Guide
UnlockSemaphore()
New & Revised Topics in CAPITAL 7.2
Business Functions Listing
ImportASCII()
Journal()
ReadNote()
StockGetQuantity()
StockQuantity()
TimeFormat()
Version()
Basic Editing
Moving & Resizing Objects
Moving & Resizing Body Objects
Creating Forms & Reports
Form Bodies
Form Design Hints & Tips
Body Properties
Body Contents
Rule Wizard
Rule Wizard Guidelines
Body Rules
Group Wizard
Body Groups & Totals
Form Output Properties
Form Notes
Question Wizard
Form Question Prompt
Form Questions
Preface and Postscript Scripts
Form Dictionaries
Page Setup
Form Editor Preferences
Field Objects
Field Formulas
Bar Code Field Objects
Text Object Properties
Picture Object Properties
Linking
Why are Table Joins Necessary?
Linking Forms - Concepts
Linking Forms - Tutorial
Linking Forms - Hints & Problem Solver
Special Topics
CAPITAL Data Browser
Bar Codes - An Overview
Cross-Tab Concepts
Cross-Tabs
Cross Tab Fields
Cross-Tab Hints & Tips
Exporting Data
Printing
Transaction (Form) Printing
The Print Job Manager
Windows Printing Concepts
Script Programming
Business Functions Listing
Capital Business Script
Variables & Data Types
Scope
Operators & Expressions
Type Conversion
Business Functions Overview
Commands
CALL
DEBUG
GOTO (label)
IF (expression) GOTO
IF (expression) ... ELSE ... ENDIF
PAUSE
REM (*)
RETURN
Visual Forms Builder Special Variables
Sample Scripts
Sending Email Using CBS
Programmer's Frequently Asked Questions
Business Functions
AAdd()
Abs()
AddCustomer()
AddJobCard()
AddMail()
AddPayment()
AddRecord()
AddStock()
AddTraceProperty()
AllocatePayment()
Alltrim()
AnswerYes()
ArraySort()
Asc()
AsChar()
ASIZE()
AsTran()
AsVal()
AT()
BackAllocate()
BPayCRN()
BPayError()
BufferCommit()
BufferRollBack()
BufferUpdates()
CDOW()
Ceil()
CHR()
CloseFile()
CloseIndex()
CloseTable()
CMONTH()
CompanyName()
CompressTable()
ComError()
ComClose()
ComOpen()
ComRead()
ComSetup()
ComWrite()
ComputerName()
CopyFile()
CopyRecord()
CopyToClipBoard()
CreateFile()
CreateEmailJob()
CreatePrintJob()
CreateTable()
CrossTab()
CTOD()
DateFormat()
DateFromMonth()
DAY()
Dictionary()
DOW()
DTOC()
DTOS()
Echo()
EchoBox()
EchoBoxOff()
EchoBoxOn()
EchoStatus()
Eof()
EraseFile()
EventAdd()
ExpenseAnalysis()
ExportASCII()
FilterTable()
Find()
FindWindow()
ForDate()
FormAdd()
FormResult()
FreeCPU()
FormCreate()
FormShow()
GetField()
GetFolder()
Goto()
GotoBottom()
GotoTop()
HoldRecord()
GroupChange()
Idle()
IF()
ImportASCII()
IndexTable()
Input()
InputFile()
INT()
IsEmpty()
IsFile()
IsFileEnd()
IsLayBy()
IsPaid()
IsPayment()
JobInfo()
JobPriority()
JobStatus()
KitList()
LEFT()
LEN()
LockRecord()
LOWER()
LTRIM()
Max()
Min()
ModemDial()
Month()
MonthEnd()
MonthStart()
NTrim()
NumToWord()
OpenFile()
OpenTable()
OrderTable()
OpenVisualBuilder()
Pad()
PathCompany()
PathProgram()
PayMethodName()
PostMessage()
PriceUpdate
RAT()
ReadFile()
ReadNote()
ReadFileLine()
ReadTextFile()
RecNo()
RenameFile()
Replicate()
Right()
Round()
Rtrim()
RunApplication()
Seconds()
Security()
SendDirect()
SendMail()
SendEscapeCodes()
SendMail()
Shell()
Skip()
Space()
SpecialName()
SpecialPrice()
SQRT()
StockAnalysis()
StockDescription()
StockMovement()
StockPrice()
StockId()
StockQuantity()
Str()
StrLine()
StrLineCount()
Strtran()
StrWrap()
Substr()
StrZero()
Time()
Today()
TodoAdd()
TranAdd()
TranCreate()
TranWrite()
TranInc()
Transform()
TranStr()
Type()
UnlockRecord()
Unpaid()
Upper()
UserName()
UserNumber()
Version()
WaitCursor()
WaitFile()
Week()
Write()
WriteFile()
WriteFileLine()
WriteNote()
WriteTextFile()
Year()
ZipFile()
Tutorials
Report Wizard Tutorial (Basic)
Label Wizard Tutorial (Advanced)
Forms Library
The Visual Builder Report & Forms Library
Forms Stationary
Report Library - Customer Transactions
Report Library - Cash Management
Report Library - Sales Analysis
Report Library - Sales Orders & Back Orders
Report Library - Stock Control
Report Library - Service Management & Periodic Billing
Report Library - Special
Appendix
Moving Forms
Logging On
Overriding Print Warning Messages
Questions & Answers
Start-up Switches
Trouble-Shooting Guide
Weight Scale Interfacing (Digi D770)
Working With Text Printers

CAPITAL Series 7 Visual Builder Reference Guide

Prev Page Next Page

CrossTab() generate/en75.gif


Creates a database table containing consolidated totals.

Syntax

CrossTab(<cTable>, <cRowField>, <aColumns>, [<cFilter>], [<xStart>], [<cEnd>]) --> nResult

Arguments

<cTable> --> The name of the database table to create. Do not specify a path. The table will be created and placed in the default company folder. If the table already exists, it will be erased. Do not specify a table name that would conflict with any table that already exists in your company folder.

<cRowField> --> The field name of the table from which the consolidated table will use to base its totals on.

For example, if you wished to produce a cross-tabulated table of your sales (INVOICE.DBF), based on the total number in each state, the cRowField would contain the field name "STATE". Of if you wanted to produce a cross-tabulated total of sales by customer, the field name would contain the value "ACCCODE", which is the field used to designate the account code of the records of the INVOICE.DBF table.

<aColumns> --> This is a series of array elements containing the structure described in the following table. There must be at least one array of this type within aColumns.

Element No.

Type

Description

1

Field Name

The name of the field to be created within the cross-tabulated table. Field names may be up to 10 characters long, must be unique, and may contain only letters and numbers. The first character of the field name must be a letter. For example, "SALES" and "TOTAL1" are valid field column names.

2

Size

The size of the numeric field as a number. This number must be large enough to hold the maximum total value that may be calculated.

3

Decimals

The number of decimals to maintain for the number. For simple counters, the decimal value may be zero. For dollar value totals the number of decimals should be set to 2. When a decimal portion is specified, space must be allowed for the decimal point within the field. The total size of the numeric field should therefore be increased by the number of decimals specified plus 1.

4

Field or Expression

A character string as either a field within the source table upon which the cross-tabulation is based, or a single line expression containing CBS script.

For example, if you are consolidating the INVOICE.DBF table (invoice sales) based on total sales, the contents of this element might be "INVTOT" as Invoice->Invtot holds the transaction total in this database table.

 

The following script defines several aColumn elements:

Declare aColumns Type Array

aColumns := {}

AADD(aColumns, { "COUNT", 06, 0, "1" } )

AADD(aColumns, { "CARTONS", 06, 0, "Cartons" } )

AADD(aColumns, { "SALES", 18, 2, "Invtot" } )

<cFilter> --> An optional single line CBS expression used for filtering records for the consolidation. If the expression evaluates to TRUE, the record is not included in the cross-tabulated totals.

<xStart> --> A value of character, numeric or date type that is used to locate the first matching record in the source table to be consolidated. If supplied, it is assumed that the source table has already been set to the appropriate matching index, using the OrderTable() function.

For example, if you were intending to consolidate totals by salesperson between two dates, you would first specify that the index order of the source table be set to its date based ordering. xStart would then contain the first date string to match, typically either dYourDate or DTOS(dYourDate).

If the value of xStart does not exactly match a value contained in your source database, CrossTab() will start at the closest matching record.

<cEnd> --> An optional expression used to terminate the cross-tabulation process. cEnd is a valid single line CBS expression. If it evaluates to TRUE, the cross-tabulation process ends. For cEnd to be useful, the source table should be set to an indexed order, and cEnd should be evaluating a field value matching this order. For example, if you were intending to consolidate totals by salesperson between two dates, you would specify the last date you intended to include in the consolidation table within the cEnd expression. For sales records this might be "Invoice->Date > dEndDate". (The variable dEndDate is assumed to have been previously defined and that it will contain a last date value.)

Returns

CrossTab() will build the requested table and return a value of zero if the operation completed successfully. If a problem occurred, an error message is returned or an error code will be returned as a negative number. The following table describes all return error codes that do not display error messages.

Error Code

Description

-2

Could not delete crosstab index or table. File not found.

-3

Could not delete crosstab index or table. Path not found.

-4

Could not delete crosstab index or table. Exceeded file handles error.

-5

Could not delete crosstab index or table. Access denied.

-6

Could not delete crosstab index or table. Invalid handle.

-15

Could not delete crosstab index or table. Invalid drive specified.

-19

Could not delete crosstab index or table. Attempt to write to write-protected media.

-21

Could not delete crosstab index or table. Media not ready.

-23

Could not delete crosstab index or table. CRC error.

-29

Could not delete crosstab index or table. Write error.

-30

Could not delete crosstab index or table. Read error.

-32

Could not delete crosstab index or table. Sharing violation

-33

Could not delete crosstab index or table. Lock violation.

-1000

Could not delete crosstab index. The index may be in use by another process.

-1001

Could not delete crosstab table. The table may be in use by another process.

-1002

Could not open cross-tabulation table. General error.

-1003

Could not open cross-tabulation table. Table lock error.

generate/notepad.gifMost file errors are caused by the table already being opened or accessed by another application or process.

Description

This function scans the contents of a source table, such as a invoice sales file, customer file, supplier file, job file, etc., and will create a table containing a set of consolidated records with accumulated total fields within it. The first field of the returned table is the row field, which is used as the basis for the consolidation. The remaining fields will hold one or more totals based on the consolidation field. The consolidation table will be sorted by the cRowField.

Example #1

Summarise sales by Origin code. The first column is a counter, so it only returns '1'. The second field is the sales total.

Declare Answer1 Type Date

Declare Answer2 Type Date

Declare aColumns Type Array

Answer1 := Today()

Answer2 := Today()

aColumns := {}

Invoice->(OrderTable("DATE"))

AADD(aColumns, { "COUNT", 06, 0, "1" } )

AADD(aColumns, { "SALES", 18, 2, "INVTOT" } )

Invoice->(CrossTab("ORGSUM", "ORIGIN", aColumns,, DTOS(Answer1), "Date > Answer2"))

* Display the result

LookUp("ORGSUM")

Example #2

Summaries sales by customer account code.

Declare Answer1 Type Date

Declare Answer2 Type Date

Declare aColumns Type Array

Answer1 := Today()

Answer2 := Today()

aColumns := {}

Invoice->(OrderTable("DATE"))

AADD(aColumns, { "SALES", 18, 2, "INVTOT" } )

Invoice->(CrossTab("ASALES", "ACCCODE", aColumns, ".NOT. IsPayment()", DTOS(Answer1), "Date > Answer2"))

* Display the result

LookUp("ASALES")

Example #3

This script produces a cross-tabulated file broken into sales and credits, by salesperson.

Declare Answer1 Type Date

Declare Answer2 Type Date

Declare aColumns Type Array

Answer1 := Today()

Answer2 := Today()

aColumns := {}

Invoice->(OrderTable("DATE"))

AADD(aColumns, { "DSALES", 18, 2, "IF(INVTOT > 0, INVTOT, 0)" } )

AADD(aColumns, { "CSALES", 18, 2, "IF(INVTOT < 0, INVTOT, 0)" } )

Invoice->(CrossTab("SALESUM", "SALESMAN", aColumns,, DTOS(Answer1), "Date > Answer2"))

* Display the result

LookUp("SALESUM")

____________________________

Related Topics

Business Function List