Microsoft Visual FoxPro 6.0 Programming

Using the several commands and function in a sequence to do a particular job is called a Program.

Memory Variable: A Memory Variable is a location that provides a reference to the storage space where the actual value is stored temporarily. Instead of the actual value, the variable name is used in any operation. Valid characters that are used to give a variable name are as follows: A-Z (26 Letters), a-z (26 Letters), 0-9 (10 digit), _ (underscore).

* The first character of a variable name must be a Letter and the maximum length is 10.

Example: ✖SL NO=0, ✔SL_NO=0.

Data Type of Variable: There are different types of data type such as Numeric, Character, Logical, Date etc. The type of a variable depends on the value that has been assigned to that variable. For example:

  • A=0 (A is Numeric Variable)
  • A=SPACE(10) or ” ” or “AMIT” (A is Character Variable)
  • A= DATE () (A is Date Variable)

Operators: An Operator is a symbol that tells the interpreter (অনুবাদক) / compiler (সংকলনকারী) to perform specific mathematical or logical manipulation. There are three types of operators:

  1. Arithmetic:
    • + : Addition
    • : Subtraction
    • * : Multiplication
    • / : Division
  2. Logical:
    • AND or .AND.
    • OR or .OR.
    • NOT or .NOT.
  3. Relational:
    • > : Greater than
    • < : Less than
    • = : Equal
    • >= : Greater than Equal to
    • <= : Less than Equal to
    • #,!= or <> : Not Equal to

Statement: There are two types of Statement are as follow:

  1. Conditional Statement: When user specify the action which based on conditions, then user use the Conditional Statement. There are two types of conditional statement.
  • If…..Else…..EndIf

Syntax:

IF CONDITIONS

STATEMENT [True]

ELSE

STATEMENT [False]

ENDIF

  • Do Case…..EndCase

Syntax:

DO CASE

CASE CONDITION-1

STATEMENT [True]

CASE CONDITION-2

STATEMENT [True]

OTHERWISE

STATEMENT [False]

ENDCASE

  1. Looping Statement: This statement allow a set of instructions to be performed until a certain condition is reached. There are two types of looping statement.
  • Do While…..EndDo

Syntax:

DO WHILE CONDITION

STATEMENT [True]

ENDDO

STATEMENT [False]

  • For…..EndFor

Syntax:

FOR VARIABLE=N1 TO N2

STATEMENT [True]

ENDFOR

STATEMENT [False]


START ➔ All Programs ➔ Microsoft Visual Studio 6.0 ➔ Microsoft Visual FoxPro 6.0

Write in Command Window:

MODIFY COMMAND <Name>[Enter]

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

?”Youth Computer”

SET TALK ON

SET SAFE ON

Save: Close the program window ➔ Yes or CTRL+W (for Save and Close)

Write in Command Window:

DO <Name>[Enter]

or

Run: CTRL+E ➔ Yes (for Save and Run)

*If user want to display the text at different position:

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

@7,12 SAY”Youth Computer”

SET TALK ON

SET SAFE ON

Run: CTRL+E ➔ Yes (for Save and Run)


Example: Character Variable

1. Write a program for input two character and show both character.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=SPACE(20)

B=SPACE(20)

@7,12 SAY”FIRST NAME:-“GET A

@9,12 SAY”LAST NAME:-“GET B

READ

C=A+B

@11,12 SAY C

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

FIRST NAME:- AMIT

LAST NAME:- DAS

AMIT DAS

Example: Numeric Variable

2. Write a program for input three number and show the result of (A+B)-C.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=0

B=0

C=0

@7,12 SAY”A=”GET A

@9,12 SAY”B=”GET B

@11,12 SAY”C=”GET C

READ

D=(A+B)-C

@13,12 SAY “(A+B)-C”+STR(D)

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

A= 1

B= 2

C= 3

(A+B)-C= 0

Example: Highest & Lowest Value

3. Write a program for input three number and show which is Highest & Lowest value.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=0

B=0

C=0

@7,12 SAY”First Number:-“GET A

@9,12 SAY”Second Number:-“GET B

@11,12 SAY”Third Number:-“GET C

READ

M=MAX(A,B,C)

N=MIN(A,B,C)

@13,12 SAY “Highest Value=”+STR(M)

@15,12 SAY “Lowest Value=”+STR(N)

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

First Number:- 1

Second Number:- 2

Third Number:- 3

Highest Value= 3

Lowest Value= 1

Example: Temperature Converter

4. Write a program for input temperature number in Celsius, Fahrenheit and convert to opposite temperature number.

Note: C/5=(F-32)/9

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

C=0

@7,12 SAY”Celsius Number:-“GET C

READ

CF=9*C/5+32

@9,12 SAY”Fahrenheit Number=”+STR(CF)

F=0

@11,12 SAY”Fahrenheit Number:-“GET F

READ

CC=(5*F-160)/9

@13,12 SAY “Celsius Number=”+STR(CC)

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

Celsius Number:- 0

Fahrenheit Number= 32

Fahrenheit Number:- 32

Celsius Number=0

Example: Marksheet

5. Write a program for input Student Name, Six Subject number and calculate best of five Total, Average, Grade.

Note:

Grade “A+” for Average >=90

Grade “A” for Average >=80

Grade “B+” for Average >=70

Grade “B” for Average >=60

Grade “C” for Average >=50

Grade “D” for Average >=40

Otherwise Grade “Fail”

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

N=SPACE(25)

B=0

E=0

M=0

G=0

H=0

C=0

@7,12 SAY “Student Name:-“GET N

@9,12 SAY “Bengali:-“GET B

@11,12 SAY “English:-“GET E

@13,12 SAY “Mathematics:-“GET M

@15,12 SAY “Geography:-“GET G

@17,12 SAY “History:-“GET H

@19,12 SAY “Computer:-“GET C

READ

L=MIN(M,G,H,C)

T=(B+E+M+G+H+C)-L

A=T/5

IF A>=90 THEN

D=”A+”

ELSE

IF A>=80 THEN

D=”A”

ELSE

IF A>=70 THEN

D=”B+”

ELSE

IF A>=60 THEN

D=”B”

ELSE

IF A>=50 THEN

D=”C”

ELSE

IF A>=40 THEN

D=”D”

ELSE

D=”FAIL”

ENDIF

ENDIF

ENDIF

ENDIF

ENDIF

ENDIF

@21,12 SAY “Total=”+STR(T)

@23,12 SAY “Average=”+STR(A)

@25,12 SAY “Grade=”+D

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

Student Name:- Amit Das

Bengali:-50

English:-50

Mathematics:-30

Geography:-50

History:-50

Computer:-50

Total= 250

Average= 50

Grade= C

Example: Balance Calculate

6. Write a program for input Product Name, Quantity, Rate and calculate Value, Netamount.

Note:

Discount 20% for Value >=20000

Discount 10% for Value >=10000

Otherwise Discount 5%

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=SPACE(25)

Q=0

R=0

@7,12 SAY “Product Name:-“GET A

@9,12 SAY “Quantity:-“GET Q

@11,12 SAY “Rate:-“GET R

READ

V=Q*R

IF V>=20000 THEN

D=V*20/100

ELSE

IF V>=10000 THEN

D=V*10/100

ELSE

D=V*5/100

ENDIF

ENDIF

N=V-D

@21,12 SAY “Value=”+STR(V)

@23,12 SAY “Discount=”+STR(D)

@25,12 SAY “Netamount=”+STR(N)

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

Product Name:- Soap

Quantity:-5

Rate:-50

Value= 250

Discount= 12.5

Netamount= 237.5

Example: Voting

7. Write a program for Voting machine.

Write in Program Window:

S=0

M=0

B=0

DO WHILE .T.

V=SPACE(1)

@3,6 SAY “Press ‘S’ for SONIA……………”

@4,6 SAY “Press ‘M’ for MAMATA……………”

@5,6 SAY “Press ‘B’ for BUDHADEV……………”

@6,6 SAY “Press ‘E’ for EXIT……………”

@9,6 SAY “Put your vote here:- “GET V

READ

V=UPPER(V)

DO CASE

CASE V=”S”

S=S+1

CASE V=”M”

M=M+1

CASE V=”B”

B=B+1

CASE V=”E”

@11,6 SAY “SONIA:- “+STR(S)

@13,6 SAY “MAMATA:-“+STR(M)

@15,6 SAY “BUDHADEV:-“+STR(B)

@17,6 SAY “SPOILD:-“+STR(P)

W=MAX(S,M,B)

IF W=S

@19,6 SAY “SONIA is winner”

ELSE

IF W=M

@19,6 SAY “MAMATA is winner “

ELSE

IF W=B

@19,6 SAY “BUDHADEV is winner “

ENDIF

ENDIF

ENDIF

L=S+M+B

D=W/L*100

@21,6 SAY “Poling Vote:-“+STR(L)

@23,6 SAY “% of vote of winner candidate is:-“+STR(D,6,2)

EXIT

OTHERWISE

P=P+1

ENDCASE

ENDDO

Run: CTRL+E –> Yes (for Save and Run)

Press ‘S’ for SONIA……………

Press ‘M’ for MAMATA……………

Press ‘B’ for BUDHADEV……………

Press ‘E’ for EXIT……………

Example: Serial Number

8. Write a program for show 1 2 3..ten natural number.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=1

K=1

DO WHILE K<=10

?A

A=A+1

K=K+1

ENDDO

SET TALK ON

SET SAFE ON

or

SET TALK OFF

SET SAFE OFF

CLEAR

FOR A=1 TO 10

?A

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

1

2

3

4

5

6

7

8

9

10

Example: Ten *

9. Write a program for show ten *.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=1

K=1

DO WHILE K<=10

?”*”

A=A+1

K=K+1

ENDDO

SET TALK ON

SET SAFE ON

or

SET TALK OFF

SET SAFE OFF

CLEAR

FOR A=1 TO 10

?”*”

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

*

*

*

*

*

*

*

*

*

*

Example: 1 3 5 7..upto 10 number

10. Write a program for show 1 3 5 7..upto 10 number.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=1

K=1

DO WHILE K<=10

?A

A=A+2

K=K+1

ENDDO

SET TALK ON

SET SAFE ON

or

SET TALK OFF

SET SAFE OFF

CLEAR

K=1

FOR A=1 TO 10

?K

K=K+2

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

1

3

5

7

9

11

13

15

17

19

Example: 5 9 13 17..upto 10 number

11. Write a program for show 5 9 13 17..upto 10 number.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=5

K=1

DO WHILE K<=10

?A

A=A+4

K=K+1

ENDDO

SET TALK ON

SET SAFE ON

or

SET TALK OFF

SET SAFE OFF

CLEAR

K=5

FOR A=1 TO 10

?K

K=K+4

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

5

9

13

17

21

25

29

33

37

41

Example: 1 8 27 64..upto 10 number

12. Write a program for show 1 8 27 64..upto 10 number.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=1

K=1

DO WHILE K<=10

?A*A*A

A=A+1

K=K+1

ENDDO

SET TALK ON

SET SAFE ON

or

SET TALK OFF

SET SAFE OFF

CLEAR

K=1

FOR A=1 TO 10

?K*K*K

K=K+1

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

1

8

27

64

125

216

343

512

729

1000

Example: 5 9 14 20..upto 10 number

13. Write a program for show 5 9 14 20..upto 10 number.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=5

B=4

K=1

DO WHILE K<=10

?A

A=A+B

B=B+1

K=K+1

ENDDO

SET TALK ON

SET SAFE ON

or

SET TALK OFF

SET SAFE OFF

CLEAR

K=5

B=4

FOR A=1 TO 10

?K

K=K+4

B=B+1

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

5

9

14

20

27

35

44

54

65

77

Example: A B C D..upto 26 character

14. Write a program for show A B C D..upto 26 character.

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=65

K=1

DO WHILE K<=26

?CHR(A)

A=A+1

K=K+1

ENDDO

SET TALK ON

SET SAFE ON

or

SET TALK OFF

SET SAFE OFF

CLEAR

K=65

FOR A=1 TO 26

?CHR(K)

K=K+1

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

Example: Number Pyramid Structure

15. Write a program for show number in Pyramid Structure .

1

12

123

1234

12345

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

FOR I=1 TO 5

FOR J=1 TO I

??J

ENDFOR

?

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

1

12

123

1234

12345

16. Write a program for show number in Pyramid Structure .

1

22

333

4444

55555

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

FOR I=1 TO 5

FOR J=1 TO I

??I

ENDFOR

?

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

1

22

333

4444

55555

17. Write a program for show number in Pyramid Structure .

1

2  3

4  5  6

7  8  9  10

11 12 13 14 15

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=1

FOR I=1 TO 5

FOR J=1 TO I

??A

A=A+1

ENDFOR

?

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

1

2  3

4  5  6

7  8  9  10

11 12 13 14 15

Microsoft Visual FoxPro 6.0 Programming – Character Pyramid Structure

18. Write a program for show character in Pyramid Structure.

A

B C

D E F

G H I J

K L M N O

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

A=65

FOR I=1 TO 5

FOR J=1 TO I

??CHR(A)

A=A+1

ENDFOR

?

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

A

B C

D E F

G H I J

K L M N O

Microsoft Visual FoxPro 6.0 Programming – Name Pyramid Structure

19. Write a program for input “JYCTC” and show in Pyramid Structure .

J

JY

JYC

JYCT

JYCTC

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

J=”JYCTC”

L=LEN(J)

FOR K=1 TO L

?LEFT(J,K)

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

J

JY

JYC

JYCT

JYCTC

20. Write a program for input “JYCTC” and show in Pyramid Structure .

JYCTC

JYCT

JYC

JY

J

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

J=”JYCTC”

L=LEN(J)

N=L

FOR K=1 TO 10

?LEFT(J,N)

N=N-1

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

JYCTC

JYCT

JYC

JY

J

21. Write a program for input “JYCTC” and show in Pyramid Structure .

J

JY

JYC

JYCT

JYCTC

JYCT

JYC

JY

J

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

J=”JYCTC”

L=LEN(J)

FOR K=1 TO L

?LEFT(J,K)

ENDFOR

N=L-1

FOR K=1 TO N

?LEFT(J,N)

N=N-1

ENDFOR

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

J

JY

JYC

JYCT

JYCTC

JYCT

JYC

JY

J

Microsoft Visual FoxPro 6.0 Programming – Opposite Character

22. Write a program for input “COMPUTER” and show it as “RETUPMOC” (Opposite Character).

Write in Program Window:

SET TALK OFF

SET SAFE OFF

CLEAR

Z=””

C=”COMPUTER”

L=LEN(C)

FOR I=1 TO L

N=SUBSTR(C,L,1)

Z=Z+N

L=L-1

ENDFOR

?Z

SET TALK ON

SET SAFE ON

Run: CTRL+E –> Yes (for Save and Run)

RETUPMOC