What is Array?
An array is a set of related data items that can be accessed by a common name. normally values stored in an array should be of same data type, but FoxPro allows to store values of different data types in an Array. An Array is made up of rows and columns. Arrays in FoxPro are of two types.
1) Single Dimensional Array
Having a multiple rows and one column. Each location in the Array is called as an Element.
2) Double Dimensional Array
Has one or more rows and one or more columns.
Creating an Array
An Array name can be of 10 Characters only. Involves specifying a name for the Array, and the size of the Array in terms of Number of Rows and Columns. Syntax:
Dimension <Array Name> (No of Rows)[<Number of Columns>]
Single Dimensional Array
Specifying number of columns is optional. If the number of columns is not specified, then the array is assumed to have only one column. This is the single dimensional array. E.g.
Dimension arr1 (4)
This will create a single dimensional array arr1 having 4 rows and 1 column.
Single Dimensional Array
If number of rows and columns are specified the array is treated as double dimensional array.
For Example:
For Example:
Dimension arr2(3,6)
This will create a double dimensional array having 3 rows and 6 columns. When Array is create all elements are initialized to a logical False (.F.).
Accessing Array Elements
Elements of Single Dimensional Array can be accessed by specifying array name, row number, enclosed within the parenthesis. As follows:
Dimension Arr5(3)
Arr5(1)
Arr5(2)
Arr5(3)
Elements of a double dimensional array can be accessed by specifying the array name, row number and the column enclosed within the parenthesis.
Dimension Arr(2, 3)
Arr(1, 1)
Arr(1, 2)
Arr(1, 3)
Arr(2, 1)
Arr(2, 2)
Arr(2, 3)
Number used to access an elements of array is called as a subscript.
Initializing an Array Elements
Elements of any array can also be assigned values with store command or assignment statement.
Dimension Arr6(4)
Arr6(3) = 30
Third element of the array Arr6 is assigned a value of 30.
Dimension Arr8(4,3)
Arr8 = “Hello”
Check Box
Check boxes appear singly or in all small groups. They are used to indicate a state that is one of the two values as on or off. When a check box is checked or unchecked choice is to be stored in a memory variable, field which is specified with option.
Check Box With Function Clause:
Store 0 to mcheck
@ 10,10 get mcheck function ‘* C Eco’
@ 10,30 get mcheck function ‘* C Executive’
Read.
Check Box With Picture Clause:
Store .F. to mcheck
@ 10,10 get mcheck picture ‘@* C Economy’
@ 10,30 get mcheck picture ‘@* C Executive’
Read.
Hot Keys
Hot key allows immediately chose or change the state of the check box. A hot key can be assigned with a backslash ‘\’ and less than sign ‘<’ before desired character. Character serves as hotkeys is underlined. For Example
Store 0 to mcheck
@ 10,10 get mcheck picture ‘*’picture ‘\< Economy’
Read.
Message
Message clause character expression is displayed when a check box is selected. E.g.
Store 0 to mecheck
@ 2,10 get mcheck function ‘* C Economy’ font ‘Roman’,16 style “BI”;
message “Economy Class is selected”
@ 4,30 get mcheck function ‘* C Executive’ font ‘Roman’,16 style “BI”
message “Executive class is selected”
Read
From Clause
Creates a list from an array. If the array is one dimensional, contents of the first array element is the first item in the list, contents of second array element is second item, so on.
Dimension Arr(4)
Arr( 1)=“Woes”
Arr( 2)=”Excel”
Arr( 3)=”PowerPoint”
Arr( 4)=”Access”
Read
Store 1 to Mlist
@ 2,10 get mlist from Arr
read
pop-Ups
Are used for setting values or choosing from a list of related items. Pop-ups are represented by a text box with a down arrow button to the right. When a pop-up is activated it displays list of options. We can select only a one option among the list. Eg.
Store 1 to mpop
@ 2,10 get mpop function ‘^Excel; World; PowerPoint, Access’
Read
Default
Default expression determines the type of memory variable created and its initial value.
@ 2,2 get mop function ‘^Excel; Word ; PowerPoint; Access’; Default ‘Word’
Read
OR
@ 2,2 get mop function ‘^Excel; Word ; PowerPoint; Access’ Default 3
Read
Push Buttons
Push buttons allows to perform the action that described by button’s prompt. For Example
Store 1 to mpush
@ 2,10 get mpush picture ‘@*OK;Cancel ‘
Read
Store 1 to mpush
@ 2,10 get mpush function ‘*OK;Cancel ‘
Read
Store 1 to mpush
@ 2,10 get mpush function ‘*’ picture ‘@*OK;Cancel ‘ size 1,8
Read
Hot Keys
A hotkey is the shortcut key by pressing which we can access the action by the button’s prompt.
Store 1 to mchoice
@ 2,8 get mchoice function ‘*\<Ok;\<Cancel’
Read
Radio Buttons
Allow to get information that typically indicates an action or an option.
Store 1 to Mradio
@ 2,10 get Mradio function ‘*R None; Single ; Double’
Read
Spinners
Spinners lets you spin through a set of numeric values displayed in text box.
1) Store 1 to mspin
@ 2,10 get mspin spinner 1-5, 25
Read
2) Store 1 to mspin
@ 2,10 get mspin spinner 1,1,100 function ‘I’
Read
3) Store 1 to mspin
@ 2,10 get mspin spinner 1,1,100 picture ‘***’
Read
The other functions are used are:-
‘B’, ‘J’, ‘Z’, ‘L’, ‘K’
Range
Range clause is used to specify range of acceptable spinner values. If a value entered in spinner text box is not within the specified range, the message showing the correct range is displayed.
Store 1 to mspin
@ 2,10 get mspin spinner 1,1,100
Range 1,100
Read
Valid
Valid clause includes a numeric expression is used to specify which object is activated after a spinner is chosen.
Store 1 to mspin
@ 2,10 get mspin spinner 1,1,100
Valid 1
Read
Accept ten numbers in an array and display its sum.
Set talk off
Dime Arr[10]
No=0
i=10
S=0
Do while i<=10
Arr[i]=0
@ 10,10 say “Enter a Number” Get no
Read
i=i+1
S= S+Arr[i]
Enddo
@ 10,10 say “Sum of the Array Numbers” +srt(s)
Accept an Array of 10 elements to enter names and display it.
Set talk off
Dime Arr[10]
i=1
r=4
do while i<=10
Arr[i] =Space(10)
@ 5,10 say “Enter Name” get Arr[i]
Read
i=i+1
enddo
i=1
clear
@ 12,10 say “The Names Enter are”
do while i<=10
@ r,10 say Arr[i]
i=i+1
r=r+1
Enddo
No comments:
Post a Comment