Convert a numeric expression to a character string.
Str( <nNumber>, [<nLength>], [<nDecimals>] ) --> cNumber
<nNumber> is the numeric expression to be converted to a character string.
<nLength> is the length of the character string to return, including decimal digits, decimal point, and sign.
<nDecimals> is the number of decimal places to return.
Str() returns <nNumber> formatted as a character string. If the optional length and decimal arguments are not specified, Str() returns the character string according to the following rules:
Results of Str() with No Optional Arguments
Expression Return Value Length ------------------------ ----------------------------------- Field Variable Field length plus decimals Expressions/constants Minimum of 10 digits plus decimals Val() Minimum of 3 digits Month()/Day() 3 digits Year() 5 digits RecNo() 7 digits
Str() is a numeric conversion function that converts numeric values to character strings. It is commonly used to concatenate numeric values to character strings. Str() has applications displaying numbers, creating codes such as part numbers from numeric values, and creating index keys that combine numeric and character data.
Str() is like Transform(), which formats numeric values as character strings using a mask instead of length and decimal specifications.
The inverse of Str() is Val(), which converts character numbers to numerics.
* If <nLength> is less than the number of whole number digits in <nNumber>, Str() returns asterisks instead of the number.
* If <nLength> is less than the number of decimal digits required for the decimal portion of the returned string, Harbour rounds the number to the available number of decimal places.
* If <nLength> is specified but <nDecimals> is omitted (no decimal places), the return value is rounded to an integer.
? Str( 10, 6, 2 ) // " 10.00" ? Str( -10, 8, 2 ) // " -10.00"
Library is core
StrZero(), Transform(), Val()
Set the number of decimal position to be displayed
SET FIXED on | OFF | (<lFixed>)
<lFixed> Logical expression for toggle
This command activates a system wide fixed placement of decimals places shown for all numeric outputs. If the value of <lFixed> is a logical true (.T.), FIXED will be turned ON; otherwise it will be turned OFF.
When SET DECIMALS OFF is used, the following rules apply to the number of decimal placed displayed.
Addition Same as operand with the greatest number of decimal digits Subtraction Same as operand with the greatest number of decimal digits Multiplication Sum of operand decimal digits Division Determined by SET DECIMAL TO Exponential Determined by SET DECIMAL TO Log() Determined by SET DECIMAL TO Exp() Determined by SET DECIMAL TO Sqrt() Determined by SET DECIMAL TO Val() Determined by SET DECIMAL TO
SET FIXED ON ? 25141251 / 362 SET FIXED OFF
SET DECIMALS, Exp(), Log(), Sqrt(), Val(), Set()
Rounds off a numeric expression.
ROUND( <nNumber>,<nPlace> ) --> <nResult>
<nNumber> Any numeric value.
<nPlace> The number of places to round to.
<nResult> The rounded number.
This function rounds off the value of <nNumber> to the number of decimal places specified by <nPlace>. If the value of <nPlace> is a negative number, the function will attempt to round <nNumber> in whole numbers. Numbers from 5 through 9 will be rounded up, all others will be rounded down.
? ROUND( 632512.62541, 5 ) ? ROUND( 845414111.91440, 3 )
Library is rtl
INT(), STR(), VAL(), SET FIXED
TRUEVAL() Short: ------ TRUEVAL() Returns val of ALL numerics in a string Returns: -------- <nValue> => all numerics value Syntax: ------- TRUEVAL(cString) Description: ------------ Removes all non-numeric characters from a <cString>, and then converts it to numeric. Examples: --------- cString := "SUPERFUNCTION Library version 3.00" cNumber := TRUEVAL(cString) // (returns 3.0) Source: ------- S_TRUEVA.PRG
Clipper 5.x – Drivers Guide
DBPX Driver Installation and Usage
DBPX is the Paradox 3.5 compatible RDD for Clipper. It connects to the low-level database management subsystem in the Clipper architecture. When you use the DBPX RDD, you add a number or features, including the ability to:
. Create access to and modify Paradox tables, records, and fields
. Create, select, and activate secondary indexes on Paradox tables
. Create and modify Paradox table structures, including primary index fields
. Use explicit record and file locks with concurrent execution of other Clipper applications
. Import Paradox tables directly into Clipper arrays
In This Chapter
This chapter explains how to install DBPX and how to use it in your applications. The following major topics are discussed:
. Overview of the DBPX RDD
. Installing DBPX Driver Files
. Linking the DBPX Driver
. Using the DBPX Driver
Overview of the DBPX RDD
The DBPX driver lets you create and maintain (.db), (.px), (.x??), and (.y??) files with features different from those supplied with the original DBFNTX driver and compatible with files created under Paradox 3.5. The new features are supplied in the form of several syntactical additions to database and indexing commands and functions. Specifically you can:
. Create tables that recognize the standard Clipper data types as well as Currency ($) and Short (S) numbers between -32,767 to +32,767
. Create equally efficient keyed and unkeyed tables
. Create, select, and activate secondary indexes on Paradox tables
The DBPX driver provides simple, seamless access to the Paradox database system. The Clipper application programmer who intends to access Paradox tables with the “VIA” clause need only include the RDD header file at compile time and make the appropriate libraries available at link time.
Paradox stores data in tables (known to Xbase developers as data files (.db)’s), consisting of fields and records. Unlike Xbase databases, a Paradox database refers to a group of files that are related to each other in some way, rather than to one file.
Also, Paradox employs the concept of companion files, known as objects, that are related to the table. Some examples of object files are report forms, indexes, and data entry forms. A table and its accompanying objects are referred to as a family.
It is easy to identify objects belonging to a particular family since they all have the same base filename and are distinguished by their extensions as shown in the table below.
Paradox File Descriptions
.PX Primary Index .X?? or Y?? Secondary Index
.F or F?? Data Entry Forms
.R or R?? Report Formats
.G or G?? Graph Specifications
.SET Image Settings
.VAL Field Validity Specifications
The DBPX driver only deals with the table and index files (.db, .px, .x?? and y??) so only these files are discussed here.
Though Paradox tables are limited to 8 character filenames, each table can contain an unlimited number of records in files up to 256M in size. Paradox records in nonkeyed tables can be up to 4000 bytes each while keyed tables have a 1350 byte limitation. Each record can contain up to 255 fields of up to 255 characters each.
There are some field naming restrictions you must observe. Field names may:
. Although the Paradox file structure allows fields to be up to 25 characters long, since Clipper symbols can only be 10 characters, DBPX truncates the field name to 10 characters.
. The Paradox file structure allows embedded spaces in field names. Since this is illegal in Clipper, the DBPX driver converts spaces into underscores (_).
. Not be duplicated in the same table.
Also, most Paradox data types directly match data types in standard Xbase data files, with these differences:
. Paradox tables support both the Numeric (N) data type as well as a more specific Currency ($) data type. Both the N and $ data types can have 15 significant digits. Numeric types that exceed this length are rounded and stored as scientific notation. Also, DBPX supports the Short (S) data type to represent numbers between -32,767 and +32,767.
. The Alphanumeric field type allows all ASCII characters except embedded nulls (ASCII 0). The Alphanumeric type is identical to the Character (C) data type in Xbase. Paradox limits this field type to 255 characters.
. Paradox also supports a Date (D) field type, stored as a long integer. It can contain any value between January 1, 100 A.D. and December 31, 9999.
Installing DBPX Driver Files
The DBPX RDD is supplied as the file, DBPX.LIB:
The Clipper installation program installs this driver in the \CLIPPER5\LIB subdirectory on the drive that you specify, so you need not install the driver manually.
Linking the DBPX Database Driver
To link the DBPX driver, you must specify DBPX.LIB to the linker along with your application object (.OBJ) modules.
1. To link with .RTLink using positional syntax:
C>RTLINK <appObjectList> ,,,DBPX
2. To link with .RTLink using freeformat syntax:
C>RTLINK FI <appObjectList> LIB DBPX
Note: These link commands all assume the LIB, OBJ, and PLL environment variables are set to the standard locations. They also assume that the Clipper programs were compiled without the /R option.
Using the DBPX Database Driver
To use Paradox files in a Clipper program:
1. Place REQUEST DBPX at the top of each program file (.prg) that opens a database file using the DBPX driver.
2. Specify the VIA “DBPX” clause if you open the database file with the USE command.
3. Specify “DBPX” for the <cDriver> argument if you open the database file with the DBUSEAREA() function.
4. Use RDDSETDEFAULT( “DBPX” ) to set the default driver to DBPX.
Except in the case of REQUEST, the RDD name must be a literal character string or a variable. In all cases it is important that the driver name be spelled correctly using uppercase letters.
The following program fragments illustrate:
REQUEST DBPX . . . USE Customers INDEX Name, Address NEW VIA "DBPX"
-OR- REQUEST DBPX RDDSETDEFAULT( "DBPX" ) . . . . USE Customers INDEX Name, Address NEW
The greatest variation from the standard Xbase database design in Paradox tables is index management. As in other systems, Paradox indexes are an efficient method of dynamically sorting or locating specific data within a table without forcing a search of all data in that table. Paradox tables take two forms: unkeyed and keyed.
An unkeyed table has no fields in its structure that have been identified as specific index keys. Therefore, records are maintained in natural order. New records are added to the end of an existing table, and the unique identity for each record is a record number.
Unlike Xbase data files, unkeyed tables are not more efficient in design or faster to traverse than keyed tables. This is because Paradox tables are built as linked lists rather than fixed-length, sequential tables. Therefore, it is actually less efficient to SKIP through a unkeyed table than it is through a keyed table.
A keyed table, on the other hand, can be lightning fast as long as the data you seek is part of the key. Otherwise, just as in an unkeyed table, you are forced to do a sequential search through the table’s data fields.
Paradox tables support two types of keys or indexes.
Primary indexes are directly tied to keyed tables because a primary index indicates the table is keyed. Simply, it is impossible to have a keyed table without a primary index. If you remove the primary index from a keyed table it becomes an unkeyed table.
When you identify one or more of the table’s fields as a key field (by placing an asterisk (*) at the end of the field name) during table creation/restructuring, these fields are used to create a primary index. (Note that all key fields must be together as the first fields in a table). This invisibly rebuilds the table’s structure, though in operation it only seems to change or create the key index.
Once you identify this primary key, the table is automatically maintained in the key field order and all new records are checked to make sure that no duplicate keys are added to the table. This type of index is called a unique key index. You may have only one primary key per table, but this key can be a composite of many fields in the table. You may only modify by restructuring the table.
If it is necessary to change a primary key and restructure a table, all data in the table will still be bound to the unique key restriction. This is important if you change the primary key by adding a new field to it and there is already data in the table where this new composite key would have duplicates.
DBPX handles this situation by generating a runtime error and removing every record that violates this unique key and moving it to another table named KEYVIOL.db which has the identical structure of the offending table.
The KEYVIOL.db is automatically generated whenever this situation occurs. If there is already a KEYVIOL table, it is overwritten. Because of this you should always check for the existence of a KEYVIOL.db table immediately after any type of table restructuring.
Secondary indexes are more like common Xbase-type indexes because they can be generated or modified on the fly without having any effect on the data or table structure and aren’t restricted to unique key data.
Unlike Xbase indexes, secondary indexes can only contain a single field as their key. As mentioned earlier, primary indexes are automatically maintained so that they are always up to date. Secondary indexes are created in two different types.
. Incremental (for keyed tables)
. Independent (for unkeyed tables)
Independent indexes are created only for unkeyed tables and are not dynamically maintained in any way. Because of this they can only be considered accurate at the time of their creation. If data changes inside the table that affects the index, the index must be completely regenerated before it can be considered useful again.
Alternately, incremental indexes are created only for keyed tables and are automatically maintained similarly to primary indexes except that instead of a complete rebuild at every change, only the portion of the index affected is updated. Incremental indexes are preferable when you are handling large tables since they take considerably less time and energy to keep accurate.
ALL, NEXT, RECORD, and REST are all supported in the scoping expressions. The syntax of these keywords is identical to that used in Clipper. Note that you can only use one scope keyword at a time. If more than one of these keywords is encountered in a scoping expression, then the last keyword in the expression is the option used.
The ALL keyword (default) specifies that all records in the table should be included in the operation, starting at the first record.
NEXT processes the specified number of records, starting with the current record. For example, NEXT 5 would process the current record and the four records following it.
The RECORD keyword identifies a specific record to process. The desired record number should follow the keyword RECORD. To process record number 3, you would include “RECORD 3” in the expression.
The REST keyword causes processing to begin with the current record, instead of starting at the beginning of the table.
In the event that you want to reorder a table based on field data but don’t need or want to have an index attached to it, you have the option of sorting the table based on the current index. This entails a simple copy from a keyed table to an unkeyed table using the table sort function.
Passwords and Security
Although the Paradox DBMS cannot be considered a data dictionary system, it does have some special characteristics that make it more suitable to networks than the standard Xbase tables. One of these features is the level of security available.
There are two methods to make sure that your data is secure: master passwords and auxiliary passwords. As the owner of a table, you can limit access by attaching a master password to it. Auxiliary passwords can also be identified to establish access to the table and its family.
Once any type of password is identified for a table, its is encrypted. This protects it not only from unauthorized Paradox users but also from anyone trying to dissect it at the DOS file level. The encryption method used by Paradox is literally unbreakable and if you (or your users) forget a table password, there is no way to recover that information.
Auxiliary passwords allow access control at the table and field levels. Access to tables can be restricted to:
. ReadOnly: No changes to the table can be made
. Update: Changes to nonkey fields are allowed, no records can be added or deleted
. Entry: Same as update except that new records can be added
. InsertDelete: Same as Entry except that records can be inserted and deleted
. All: Full access including restructuring and table deletion
Access to the fields can be identified as:
. None: This field data cannot be displayed to the user
. ReadOnly: User can see the field value, but cannot change it
. All: Full access
With DBPX, you may perform basic database operations on Paradox tables without code changes.
Note that because Paradox tables can have primary indexes which are actually part of the table structure specification, when you open a Paradox table, its associated primary index (if applicable) is also opened and activated. The only exception to this rule is if you indicate that you want a secondary index to be activated at the time you open the table. If no primary index is available and no secondary index is specified, the table is opened in natural sequence order.
You can have up to twenty-four Paradox tables open simultaneously. These may be separate tables or the same table repeatedly or any variation in between. This might be important if you want to have more than one secondary index active for a single table, allowing you to move from one work area to another with the only change being the index order of the data in the table. Be careful with this type of multiviewed approach, however, since you will be eating up memory for each work area, despite the fact that they refer to the same table.
Sharing Data in Networks
The DBPX driver supports the native Clipper single-lock locking scheme. Therefore, in a shared environment, your application and Paradox will not see each other’s record locks. This may result in some concurrency corruption and errors.
In a shared environment, DBPX performs no record buffering; immediately writing all changes to disk.
Concurrency is an issue whenever your application is running either on a network or in some other shared environment. One example of a non- network shared environment is when your application is called from another program (like Paradox, Quatro Pro, etc.) that also has access to the Paradox tables. Even if you don’t have any plans to use your program on a network, you should design it to be smart enough not to become a problem if faced with this type of shared example.
Also be aware that many networks have different rights and privilege restrictions and you should know what they are and how to handle them.
Using (.px) and (.ntx) Files Concurrently
You can use both (.px), as well as (.x), (.y) and (.ntx) files concurrently in a Clipper program like this:
// (.ntx) file using default DBFNTX driver
USE File1 INDEX File1 NEW
// (.idx) files using DBPX driver
USE File2 VIA "DBPX" INDEX File2 NEW
Note, however, that you cannot use (.px) and (.ntx) files in the same work area. For example, the following does not work:
USE File1 VIA "DBFNTX" INDEX File1.ntx, File2.px
In this chapter, you were given an overview of the features and benefits of the DBPX RDD. You also learned how to link this driver and how to use it in your applications.
VAL() Convert a character number to numeric type ------------------------------------------------------------------------------ Syntax VAL(<cNumber>) --> nNumber Arguments <cNumber> is the character expression to be converted. Returns VAL() returns <cNumber> converted to a numeric value including decimal digits. Description VAL() is a character conversion function that converts a character string containing numeric digits to a numeric value. When VAL() is executed, it evaluates <cNumber> until a second decimal point, the first non-numeric character, or the end of the expression is encountered. Leading spaces are ignored. When SET FIXED is ON, VAL() returns the number of decimal places specified by SET DECIMALS, rounding <cNumber> if it is specified with more digits than the current DECIMALS value. As with all other functions that round, digits between zero and four are rounded down, and digits between five and nine are rounded up. When SET FIXED is OFF, VAL() returns the number of decimal places specified in <cNumber>. VAL() is the opposite of STR() and TRANSFORM(), which convert numeric values to character strings. Examples . These examples illustrate VAL() with SET FIXED ON and SET DECIMALS TO 2: SET DECIMALS TO 2 SET FIXED ON // ? VAL("12.1234") // Result: 12.12 ? VAL("12.1256") // Result: 12.13 ? VAL("12A12") // Result: 12 ? VAL("A1212") // Result: 0 ? VAL(SPACE(0)) // Result: 0 ? VAL(SPACE(1)) // Result: 0 ? VAL(" 12.12") // Result: 12.12 Files Library is CLIPPER.LIB.
See Also: ROUND() SET DECIMALS SET FIXED STR() TRANSFORM()
xBase File Types and Extensions
|Ext.||File Type||Introduced or used by|
|.$$$||temporary file||dBASE III|
|.$db||temporary file||dBASE IV|
|.act||FoxDoc Action Diagrams||FoxPro|
|.app||application object file||dBASE Appl. Generator|
|.bar||horizontal bar menu object file||dBASE Appl. Generator|
|.bch||batch process object file||dBASE Appl. Generator|
|.cac||executable when caching on/off||dBASE IV|
|.cat||catalog||dBASE III, IV|
|.cht||interface file for ChartMaster||dBASE|
|.clp||compiler script file (clip list)||Clipper|
|.cmd||command||dBASE – Waffle|
|.cod||template source file||dBASE Appl. Generator|
|.cpt||encrypted memo file||dBASE|
|.crp||encrypted database||dBASE IV|
|.ctl||control file||dBASE IV – Aldus Setup|
|.cvt||backup file for CONVERTed database file||dBASE IV|
|.dbf||database file||dBASE – FoxPro|
|.dbk||database backup||dBASE IV|
|.dbo||compiled program||dBASE IV|
|.dbt||FoxBASE+ style memo||FoxPro|
|.dbt||memo file for database w/same name||dBASE – Clipper|
|.dif||Data Interchange Format. For APPEND FROM, COPY||dBASE – VisiCal|
|.doc||Documentation text file||dBASE Appl. Generator|
|.fil||files list object file||dBASE Appl. Generator|
|.fmo||compiled format file||dBASE IV|
|.fmt||format file||dBASE – FoxPro – Clipper|
|.fr3||renamed dBASE III+ form file||dBASE IV|
|.frg||uncompiled report file, code fragment file||dBASE IV|
|.frm||report file||dBASE – Clipper|
|.fro||compiled report file||dBASE IV|
|.fw2||Framework spreadsheet or database file||Framework – dBASE|
|.gen||compiled template||dBASE Appl. Generator|
|.ind||include index||dBASE IV|
|.key||Key macro library||dBASE|
|.lbg||label generator data||dBASE IV|
|.lbl||label||dBASE – Clipper|
|.lbo||compiled label||dBASE IV|
|.log||Transaction log file||dBASE|
|.mbk||multiple index file backup||dBASE IV|
|.mdx||multiple index file||dBASE IV|
|.mem||memory variable save file||dBASE – FoxPro|
|.mpx||compiled menu program||FoxPro|
|.npi||source for DGEN.EXE interpreter||dBASE Appl. Generator|
|.plt||pre-linked transfer file||Clipper|
|.pop||pop-up menu object||dBASE Appl. Generator|
|.pr2||printer driver||dBASE IV|
|.pr3||PostScript printer driver||dBASE IV|
|.prf||printer driver||dBASE IV|
|.prg||program source file||dBASE – FoxPro – Clipper|
|.qbe||saved query (Query By Example)||dBASE IV – Quattro Pro|
|.qbo||compiled query||dBASE IV|
|.qpr||generated query program||FoxPro|
|.qpx||compiled query program||FoxPro|
|.res||dBASE resources||dBASE IV|
|.rpd||Rapid file. For IMPORT/EXPORT,APPEND FROM, COPY||dBASE|
|.sc3||renamed dBASE III screen mask file||dBASE IV|
|.scr||screen – screen snapshot||dBASE IV|
|.spr||generated screen program||FoxPro|
|.spx||compiled screen program||FoxPro|
|.str||structure list object file||dBASE Appl. Generator|
|.t44||Temporary file for Sort or Index||dBASE IV|
|.tbk||memo backup||dBASE IV – FoxPro|
|.tvf||table view settings||dBASE|
|.upo||compiled update data||dBASE|
|.val||values list object file||dBASE Appl. Generator|
|.vew||view file||Clipper, Lotus Approach|
|.vue||view||dBASE IV – FoxPro|
|.w44||temporary file for Sort or Index||dBASE|
|.wfm||form object||dBASE Form Designer|
|.win||window file||FoxPro – dBASE|
– Such a list can’t be perfect. Some item may be obsolete / forgotten and something may not exist when this list compiled.
– “Clipper” may not include all versions of Clipper.
– Most of Clipper files are supported by Harbour.