1. What is difference between Free Table and Database Table ?
Ans:
Database: A database table is a table file that is associated with a database.
These have properties that free tables do not have, such as field-level and record-
level rules, triggers, and persistent relationships
Free table :.A free table is a table (.dbf) file that is not associated with any
database and is very simple
2. Explain the usage with an Example ?
Ans:
1. strtran() : Searches a character expression for a second character expression
and replaces each occurrence with a third character expression or memo field. You
can specify where the replacement begins and how many replacements are made.
Syntax: STRTRAN(cSearched, cExpressionSought [, cReplacement]
[, nStartOccurrence] [, nNumberOfOccurrences] [, nFlags])
2. at(): searches for a character expression for another character expression
Syntax: (cSearchExpression, cExpressionSearched [, nOccurrence])
Example:
STORE 'Its the time to disco' TO gcString
STORE 'the time' TO gcFindString
*-------in the above statement "the time" is given string to be found ---------*
CLEAR
? AT(gcFindString,gcString) && Displays 5
*-------in the below statement "THE" is given string to be found ---------*
STORE 'THE' TO gcFindString
? AT(gcFindString,gcString) && Displays 0, case-sensitive
O/P : From the above program we get the value as 5
3. substr() : Returns a character string from the given character expression or
memo field, starting at a specified position in the character expression or memo
field and continuing for a specified number of characters
Syntax: SUBSTR(cExpression, nStartPosition [, nCharactersReturned])
Example :
STORE 'RAHUL S JOSHI' TO myString
CLEAR
? SUBSTR(myString, 1, 1)
? SUBSTR(myString, 6)
o/p : R
S JOSHI
*----------------------------------------------------------------------------------
---------------------
3. Datatypes used in VFP Tables ?
Ans: there are various datatypes used in vfp and they are :
Data Type
Description
Character
* To store string data type i.e., names, words.
* Can hold up to 254 characters
* A-Z, a-z, 0-9, underscore & special symbols
* Default length : 10
Numeric
* To store numerical value with decimal places
* 0-9, .
* Can hold up to 20 digits.
* Decimal part can be 0 to 18 digits
* E.g. usage : Marks, Roll Number
Float
* It has signed numbers
* Can hold up to 20 digits
* E.g. usage : percentage, average
Date
* Used to store date value
* Default format dd/mm/yy
Logical
* Used to store Boolean value : True or False
* Y, N
[Link] Types in VFP ?
Ans :
Extension
File Type
.DBC
FoxPro Database
.CDX
Compound Index File
.DBF
Database File
.DBT
Database Text File
.DCT
FoxPro Database Memo
.DCX
FoxPro Database Index
.PJT
FoxPro Project Memo File
.PJX
FoxPro Project
.PRG
Visual FoxPro Program File
.SCT
FoxPro Form Memo
.SCX
FoxPro Form
.VCT
Visual Class Library Memo
.VCX
Visual Fox Pro Class Library
[Link] to create a Table Programmatically ( Command Line) ?
Ans.
syntax : Create [Link] && by using this command will show the table .
*----------------------------------------------------------------------------------
-----
[Link] to Modify a table Programmatically ( Command Line)?
Ans. syntax :
* After creating [Link]
* Use [Link]
* Then using modify structure we can modify the table
*----------------------------------------------------------------------------------
-----
7. How many Fields max allowed in a table ?
Ans. we can define up to 255 fields in a table.
*----------------------------------------------------------------------------------
-----
8. To Find How many record ?/ How many Fields()
Ans. reccount() is the syntax used for checking how many records are there
*----------------------------------------------------------------------------------
-----
9. What are the possible way End of File in table can happen ?
Ans. by using seek(),locate() and also by skip commands
*----------------------------------------------------------------------------------
-----
10. Write a Program to generate odd/ Even numbers?
Ans:
user _input = val(inputbox(“enter “, “odd_even”))
If mod (user_input,2)==0
Message box(“even”)
Else
messagebox(“odd”)
Otherwise
(“invalid entry”)
*----------------------------------------------------------------------------------
-
11. What is an Array. Syntax to create a two dimension array.
Ans :
An array is a collection of items stored at contiguous memory locations. The idea
is to store multiple items of the same type together.
Syntax Declare ncars[5]
ncars = 12
*----------------------------------------------------------------------------------
-
12. How to increase the size of an array declared already.
Ans.
Syntax : DIMENSION | DECLARE ArrayName( nRows [, nCols ] )
[, aArray2( nRows2 [, nCols2 ] ) ...]
*----------------------------------------------------------------------------------
------
[Link] an Array with 5 rows and 3 columns. Add values into this array elements
programmatically by using FOR loop and variables. Array will be looks like this.
[10] [11] [12]
[20] [21] [22]
[30] [31] [32]
[40] [41] [42]
[50] [51] [52]
Code:-
DIMENSION newArray(5,3)
FOR i = 1 to 5
FOR j = 1 to 3
newArray[i,j] = 10*i + j - 1
ENDFOR
ENDFOR
*----------------------------------------------------------------------------------
-----------
14. How to check the type of a variable. Write an example.
Ans: syntax: VARTYPE(eExpression)
VARTYPE( ) is tha command used as it is faster and does not require quotation marks
to enclose the expression for which the data type is returned.
15. Difference between Public and Private variables.
Ans:
Public
A public member is accessible from anywhere outside the class but within a program.
We can set and get the value of public variables without any members.
Private
PRIVATE doesn't create variables; it simply hides variables declared in higher-
level programs from the current program.
[Link] between Relational Operators "=" and "=="
Ans:
“=" : operator to determine if two object references refer to the same object
“==”: This operator can be used when an exact comparison of character strings is
needed
17. What is the function to check a file exists in disk ?. Also write a sample to
create a file and add a string into to the file.
Ans:
Syntax : ?FILE("filename with extension ")
Example: ?File(“[Link]”)
o/p : shows in logical form that is “T”
18. Difference between fwrite() and fputs().
Ans:
fwrite() : communication port opened with a low level file function. It doesn't
place a carriage return and a line feed at the end of the character string.
fputs() : Writes a character string, carriage return and
line feed to a file or a communication port
opened with a low-level file function
19. Date/Time functions
a) Function to convert a date to character type. Write example.
Syntax: DTOC({^dd-mm-yy},1)
Example : SET STRICTDATE TO 1
STORE CTOD('10/31/98') TO getdate
CLEAR
? DTOC(getdate)
STORE DTOC({^1998-10-31}+90) TO getdate
? DTOC({^1998-10-31},1)
Output:10/31/98
19981031
b) Function to get the name of the current month. Write example.
Syntax:
Example : cmonth(dExpression | tExpression)
d = DATE(2012,05,19)
? CMONTH(d)
Output:May
c) Write a single line command (use date/time functions as many as required) to
get same date of previous month.
For eg: Today is 30-Nov-2021 then the result will be 30-Oct-2021.
: Today is 31-Dec-2021 then the result will be blank
as November have 30 days only.
Ans:
Syntax: ?GOMONTH(DATE(),-1)
Output
SET CENTURY ON
STORE GOMONTH({^1947-02-16}, 5) TO nextyr
CLEAR
? nextyr && Displays 07/16/1998
? GOMONTH({^1999-12-31}, -2) && Displays 10/31/1998
? GOMONTH({^2000-12-31}, 2) && Displays 02/28/1999
Output:
07/16/1947
10/31/1999
02/28/2001
20 a) Function to get the minimum value from the list of values.
Ans: MIN() is a function to get the minimum value from the list of values.
b) Command to get the sum of field Total_Qty to variable lnTot.
Ans:- InTot = SUM(Total_Qty)
c)Command to get the number records from a table where State field value is
Telangana
Ans: SET TALK ON
Count for state = “telangana” && display count on status bar
*----------------------------------------------------------------------------
21) What is editable cursor in vfp & how to create it?
Ans.
1. We have to create a cursor using the SELECT command it will create the cursor in
read mode only.
2. To switch its mode in read-write mode we have to use the USE command.
3. To change the mode of cursor from read to read-write
Syntax :
SELECT * FROM CUSTOMER INTO CURSOR custm1 READWRITE
[Link] to create cursor and import csv/xls/txt file?
Ans
CREATE CURSOR emp ;
(EmpID N(4), Name Character(20), DOB D(8))
DISPLAY STRUCTURE
APPEND FROM [Link] TYPE CSV
&& empinfo is a comment separated value file in which data is there and it is
appended to the cursor.
23. How to create index on cursor?
Ans
INDEX ON cursor_table_field TAG any_name
[Link] to create filtered index on cursor?
Ans. INDEX ON cursor_table_column TAG any_name FOR expression
Again if we have to go back to original cursor table use SET ORDER TO
[Link] is SET ORDER TO command?
Ans.
Set order to command is used to specify the index file to open as well as sort the
given data in table open opened as per the user.
But the default way is by setting the order in ascending order
26. What is the use of SEEK() and FOUND()?
Ans.
seek() : Searches an indexed table for the first occurrence of a record whose index
key matches a specified expression
Found () :
Determines whether the record pointer is positioned past the last record in the
current or specified table.
For example :
1: Firstly we have to set index
INDEX on contact TAG contact2
2: then we have set order to so that the command will find the required value from
that column
SET ORDER to CONTACT2 && CONTACT
3. Then printf the found() command
? found()
And then search for the required user details
SEEK ("martin")
[Link] is BROWSE command?
Ans. Opens the Browse window and displays records from the current or selected
table.
28. How to use SQL SELECT to retrieve sorted data?
Ans.
The ORDER BY keyword is used to sort the result-set in ascending or descending
order. The ORDER BY keyword is used to sort the result-set in ascending or
descending order.
sorts the records in ascending order by default.
29. How to create sql cursor and use it?
To use cursors in SQL procedures, you need to do the following:
1. Declare a cursor that defines a result set.
2. Open the cursor to establish the result set.
3. Fetch the data into local variables as needed from the cursor, one row at a
time.
4. Close the cursor when done
30. Is it mandatory to define variable/cursor in SQL before use?
Ans. yes it is mandatory to define because SQL is a static type as in static type
we have to define the variable /cursors first before executing the program.