Ana səhifə

Computer Studies Grade IX notes- introduction to Visual FoxPro Data Types and Operators


Yüklə 92.48 Kb.
tarix11.06.2016
ölçüsü92.48 Kb.
Computer Studies---- Grade IX

Notes- Introduction to Visual FoxPro

  • Data Types and Operators

  • List of Commonly used commands

Data : is a collection of raw facts and figure

Information :- meaningful data/ processed data/ output

Field : collection of data

Record : collection of field

Database : collection of records

Visual Fox Pro :- Visual FoxPro is a relational database with an object-oriented programming environment from Microsoft that comes with prewritten classes. Visual FoxPro is part of Microsoft's Visual Studio suite of products.

Visual FoxPro is relatively easy to learn and fast for developing reusable code. A programmer can write code to access a FoxPro database or as well as to connect to such databases as SQL Server and Oracle.



What's the basic difference between FoxPro and Access.

  • VFP is a professional-developer tool. MS Access is sold to and geared for end-users as part of MS Office.

  • MS Access has a limitation on the number of concurrent users, number of records. Try 50 users with a 1-million+ table in both products and see the difference. (Hell, just try 10+ users and 50,000+ records and see the difference).

  • VFP is an OOP tool, MS Access is not OOP.

  • VFP has a rich language. MS Access uses a simpler subset of the old (deprecated) VB called VBA (Visual Basic for Applications).

  • VFP can create and consume XML natively.

  • VFP can create and consume Web Services (WSDL and SOAP) natively.

  • VFP has a rich subset of the ANSI SQL language (better and improved in VFP 9.0)

Storing Data

The data that you work with can include amounts of time, money, and countable items, as well as dates, names, descriptions, and so on. Each piece of data is a certain type: it belongs to a category of data that you manipulate in similar ways. You could work directly with this data without storing it, but you would lose most of the flexibility and power of Visual FoxPro. Visual FoxPro provides numerous storage containers to extend your ability to easily manipulate data.

Data types determine how data is stored and how it can be used. You can multiply two numbers together, but you can't multiply characters. You can print characters in uppercase, but you can't print numbers in uppercase. Some of the primary data types in Visual FoxPro are listed in the following table.

Data Types



Type

Examples

Numeric

123 3.1415 – 7

Character

"Test String" "123" "01/01/98"

Logical

.T. .F.

Date

DateTime


{^1998-01-01}

{^1998-01-01 12:30:00 p}



Data Containers

Data containers allow you to perform the same operations on multiple pieces of data. For example, you add the hours an employee has worked, multiply them by the hourly wage, and then deduct the taxes to determine the amount of pay the employee has earned. You'll have to perform these operations for every employee and every pay period. If you store this information in containers, and perform the operations on the containers, you can just replace the old data with new data and run the same program again. This table lists some of the main containers for data in Visual FoxPro.



Type

Description

Variables

Single elements of data stored in your computer's RAM (Random Access Memory).

Table Records

Multiple rows of predetermined fields, each of which can contain a predefined piece of data. Tables are saved to disk.

Arrays

Multiple elements of data stored in RAM.

Manipulating Data

Containers and data types give you the building blocks you need to manipulate data. The final pieces are operators, functions, and commands.

Using Operators

Operators tie data together. Here are the most common operators in Visual FoxPro.



Operator

Valid Data Types

Example

Result

=

All

? n = 7

Prints .T. if the value stored in the variable n is 7, .F. otherwise

+

Numeric, Character, Date, DateTime

? "Fox" + "Pro"

Prints "FoxPro"

! or NOT

Logical

? !.T.

Prints .F.

*, /

Numeric

? 5 * 5

? 25 / 5


Prints 25 Prints 5

NOTE :-----A question mark (?) in front of an expression causes a new line character and the results of the expression to be printed in the active output window, which is usually the main Visual FoxPro window.

Remember that you must use the same type of data with any one operator. The following statements store two numeric pieces of data to two variables. The variables have been given names that start with n so we can tell at a glance that they contain numeric data, but you could name them with any combination of alphanumeric characters and underscores.

nFirst = 123

nSecond = 45

The following statements store two pieces of character data to two variables. The variables have been given names that start with c to indicate that they contain character data.

cFirst = "123"

cSecond = "45"

The following two operations, addition and concatenation, yield different results because the type of data in the variables is different.

? nFirst + nSecond

? cFirst + cSecond

Output


168

12345


Because cFirst is character data and nSecond is numeric data, you get a data type mismatch error if you try the following command:

? cFirst + nSecond

You can avoid this problem by using conversion functions. For example, STR( ) returns the character equivalent of a numeric value and VAL( ) returns the numeric equivalent of a character string of numbers. These functions and LTRIM( ), which removes leading spaces, enable you to perform the following operations:

? cFirst + LTRIM(STR(nSecond))

? VAL(cFirst) + nSecond

Output


12345

168


Visual FoxPro Data Types

Data type

Description

Size

Range

Blob

Binary data of indeterminate length.

Blob values are in a memo (.fpt) file.

No code page translation is performed on Blob data.


4 bytes in a table

Limited by available memory and/or 2GB file size limit.

Character

Alphanumeric text

For example, a customer address



1 byte per character to 254

Any characters

Currency

Monetary amounts

For example, the price of an item



8 bytes

- $922337203685477.5807 to $922337203685477.5807

Date

Chronological data consisting of month, day, and year

For example, an order date



8 bytes

When using strict date formats, {^0001-01-01}, January 1st, 1 A.D to {^9999-12-31}, December 31st, 9999 A.D.

DateTime

Chronological data consisting of month, day, year, hours, minutes, and seconds

For example, date and time of arrival



8 bytes

When using strict date formats, {^0001-01-01}, January 1st, 1 A.D to {^9999-12-31}, December 31st, 9999 A.D., plus 00:00:00 a.m. to 11:59:59 p.m.

Logical

Boolean value of True or False

For example, whether or not an order has been filled



1 byte

True (.T.) or False (.F.)

Numeric

Integers or decimal numbers

For example, the quantity of items ordered



8 bytes in memory; 1 to 20 bytes in table

- .9999999999E+19 to .9999999999E+20

Varbinary

Binary values.

Varbinary data is similar to Varchar data in that values do not include padding with zero (0) bytes. The length of the contained value is stored internally.

No code page translation is performed on Varbinary data.


1 byte per hexadecimal value up to 255 total bytes

Any hexadecimal value

Variant

Variant data can be any of the Visual FoxPro data types and the null value.

Once a value is stored to a variant, the variant assumes the data type of the data it contains.

Variants are designated with an e prefix in language syntax.


See other data types.

See other data types.

In addition, Visual FoxPro provides data types that apply only to fields in tables.

Visual FoxPro Field Types



Field type

Description

Size

Range

Character (Binary)

Any Character data that you do not want translated across code pages

For example, user passwords stored in a table and used in different countries or regions.



1 byte per character to 254

Any characters

Double

A double-precision floating-point number

For example, scientific data requiring a high degree of precision.



8 bytes

+/-4.94065645841247E-324 to +/-8.9884656743115E307

Float

Same as Numeric

8 bytes in memory; 1 to 20 bytes in table

- .9999999999E+19 to .9999999999E+20

General

Reference to an OLE object

For example, a Microsoft Excel worksheet.



4 bytes in table

Limited by available memory.

Integer

Numeric value with no decimals

For example, a line number in an order.



4 bytes

-2147483647 to 2147483647

Integer (Autoinc)

Same as Integer but also an automatically incrementing value. Read-only.

4 bytes

Value controlled by autoincrement Next and Step values.

Memo

Alphanumeric text of indeterminate length or reference to a block of data

For example, notes about a phone call in a phone log.



4 bytes in table

Limited by available memory.

Memo (Binary)

Same as Memo except that memo field data does not change across code pages

For example, a login script used in different countries or regions.



4 bytes in table

Limited by available memory.

Varchar

Alphanumeric text.

Varchar is similar to Character except values in Varchar fields do not include padding with additional spaces. The length of the contained value is stored internally.



1 byte per character up to 254 total bytes

Any characters

Varchar (Binary)

Varchar type data that you do not want translated across code pages.

1 byte per character up to 254 total bytes

Any characters

Using Commands

A command causes a certain action to be performed. Each command has a specific syntax, which indicates what must be included in order for the command to work. There are also optional clauses associated with commands that allow you to specify in more detail what you want.


Here is brief overview and examples of the basic FoxPro commands like Append, Set, Record, Go to, Skip, Edit, List, Display, Browse and Replace.

  1. Append command is used to add new record in the table.

  2. Set status on displays status bar at the bottom of the screen. It shows the screen active database file, the current record pointer position, number of records in the database file. And the command used to close the status bar is Set status off

  3. Set default to A is used to change the default root directory from C: drive to A: drive. Set carry on specifies static enter or duplicate for the present record into a new record when the append command is entered. Set carry off command is used to delete or to stop duplication. Dir command displays the database file.
  4. Record Pointer:- FoxPro marks its position with a table by means of a internal maker called the record pointer. A table first opens the Record Pointer normally pointing the first record in the table.

  5. Go to:-Go 2 command is used to show the positioning of the record pointer on the 2nd record.
    Go Top command moves the record pointer on first record.
    Go Bottom moves the record pointer on last record.

  6. Skip -command moves the record pointer from the current location to next location. Skip 2 command jumps 2 record. Skip -2 goes back to 2 records, that is current record - 2.


  7. ? RECNO() command displays the current record number.
  8. Modify the Record:- To modify data in the existing records the following commands can be used:
    --> EDIT displays the required record to be edited on the screen.
    EDIT fields stuno, stuname, fee: displays the above fields on the screen.
    EDIT For Fee >300 and Fee < 300 EDIT For DOJ = {06/11/09} displays data relating to that date of joining.
    EDIT for DOJ < {06/11/09} EDIT for DOJ > {06/11/09}

  9. Viewing the Record:- After adding the record to the table, the next logical step is to view the data. Data can be viewed with the list and display command with the command window.
    The default scope of the List command is to display all the record on the screen. The scope can be changed by using various options of the list command.
    For example--
    --> LIST record 4 displays the record no. 4
    --> LIST stuno, stuname, fee (field name) displays the said field names only.
    --> LIST stuname, Fee +50 displays the figures of student name adding 50 to the previous amount. LIST stuname, Fee -50 displays the figures deducting 50 from previous amount.

    ( Note: Val is used for the conversion of characters into numeric. )

    LIST for Val (marks) > 50

    LIST stuname, Fees x 2 multiplies

    LIST stuname, Fees / 2 divides

    LIST for Fees > 2450 displays the fees greater than the amount 2450.

    LIST for Fees > 2450 and < 4000 displays fee amounts that fall between 2450 and 4000. For 'and' condition all conditions should be satisfied. For 'or' condition any condition if satisfied it displays the data.

    LIST for stuname = "rao" displays rao's data only. Here strings used for characters only and for numbers there is no usage of any strings.

    LIST for stuname != "rao" or LIST for stuname <> "rao" displays data except rao's.

    LIST for stuname = "Raghu" and Fees >200 displays the data for Raghu if the fee is greater than 200. Here note that the character names are unique as in data.

    LIST for doj>{06/11/99} displays data of students joined after the specified date of joining (doj).

Display Command


Display command is somewhat similar to LIST command. Display All and List command are interchangeable. Both commands display the list of the records in the table. The default scope of the Display command is current record position. For example, using the command,

go 6 Display we can display the 6th record.

Disp all stuno, stuname, fees displays all the field names.

Disp all stuno for course = "FoxPro" displays the number of students in foxpro course.


10.Set Headings:-


Set Headings off command displays the record without the field headings.Set Headings on command displays the records with field headings.

11.Set Print:-


The Set Print command sends output to the printer in addition to the screen.
Set Printer on
Set Printer to LPT1
?Date() command displays the current date (mm / dd /yy)
Set Date Japan
?Date()
00/07/25
Set Date Germany
?Date()
25/07/00
Set Date America
?Date()
07/25/00
Set Century on
?Date()
07/25/2000
Set Century off
?Date()
07/25/00
Set Century off
LIST

12.Browse Command:-


It usually difficult to view a number of records on the screen at the same time. FoxPro browse mode displays the large amount of information at the same time.
Browse displays the records shows in a spreadsheet format.
Browse fields stuno, stuname, fee Displays those fields only.
New record is not acceptable but modifications only acceptable.
Browse fields stuno, stuname, fee Freeze fee command restricts the edition of the specified field.

13.Replace Command:-


The replace command overwrites the contents of the specified fields in a table with new contents. It replaces the contents of only current record. For example,

Replace all fees with fees + 50 command replaces all the fees adding amount 50 to all.


Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©kagiz.org 2016
rəhbərliyinə müraciət