Sample Program - 1

Foxpro – Calculate and Print the Multiplication Table of a Number Entered

Q : Foxpro –  Calculate and Print the Multiplication Table of a Number entered
Solution:
ans=”y”
do while ans=”y”
                clear
                input “enter the table to print :” to t
                i=1
                do while i <=10
                                p=t*i
                                ?str(t)+ “  *” + str(i,4) + “  = ” + str(p,4)
                                i=i+1
                enddo
                accept “want to print another table :” to ans
enddo


Foxpro – Function for finding Sum of Digits

Function for finding Sum of digit 
Solution:
function sumdigit
para num
sum=0
num=alltrim(str(num))

lgt=len(num)
i=1
do while i <= lgt
            s=substr(num,i,1)
            sum=sum+val(s)
            i=i+1
enddo
return sum

Programme to convert ritu kamal agrwal to R.K. agrwal

Programme to convert ritu kamal agrwal to R.K. agrwal
clear
accept “enter name” to nm

nm = alltrim(nm)

cntSPace= occurs(” “,nm)

res=””
a=0
for i=1 to cntSPace
            res=res + substr(nm,a+1,1) + “. ”
            a = at(” “,nm,i)
            ?”a”,a
endfor
res=res + substr(nm,a)
?”result is : ” + res

this program of foxpro is using POPUP for selection of Department Name from the database.

*this program of foxpro is using POPUP for selection of Department Name from the database.
*It will validate for valid department code also.
close all
set safe off
use dept in 0
scatt memv blank
define wind w1 from 10,10 to 20,40
define popup p1 prompt fields dept.dname
on selection popu p1 do p2
on key label f1 do acti_pop
@4,5 say “Enter dept”
@4,20 get m.dno1 defa 0
@5,5 say “Enter dept”
@5,20 get m.dno valid check_dept()
@5,40 say “Press f1 for selection”
@6,20 get m.dname disa
read
proc acti_pop
***************
activ wind w1
acti popu p1
m.dno = dept.dno
show get m.dno
m.dname = dept.dname
show get m.dname
proc p2
************
hide wind w1
deac popu p1
proc check_dept
*****************
sele dept
index on alltrim(dno) tag dno
set order to dno
if not seek(alltr(m.dno)) then
wait wind “Invalid dept”
return 0
else
m.dname = dept.dname
show get m.dname
endif
return 1

Source Codes Foxpro – Calendar Printing based on Month/Year entered

* foxpro program to print calendar
* input month and year and calendar will be shown
set date brit
set cent on
clear
decl a(5,7)
input “Enter month ” to mn
input “Enter year” to yr
if mn > 12 or mn < 1 then
?”invalid month”
return
endif
store 0 to a
store 0 to r,c,mndays
dt = ctod(“01/” +str(mn,2)+”/”+str(yr,4))
do calcdays
r=1
?dt
c=dow(dt)
for r = 1 to 6
for j = c to 7
rowno = iif(r<6,r,1)
a(rowno,j) = day(dt)
if day(dt)>=mndays then
exit loop
endif
dt = dt + 1
endfor
if day(dt)>=mndays then
exit loop
endif
c=1
endfor
clear
?
?cmonth(dt) + str(year(dt),5)
?”*********************”
?”S” at 7
??”M” at 12
??”T” at 17
??”W” at 21
??”Th” at 27
??”F” at 32
??”SA” at 37
?
colm=0
for r = 1 to 5
for c = 1 to 7
if a(r,c) <> 0 then
?? str(a(r,c),5) at colm + c*5
endif
endfor
?
endfor

proc calcdays
**************
do case
case mn =1 or mn= 3 or mn= 5 or mn= 7 or mn= 8 or mn= 10 or mn= 12
mndays = 31
case mn= 4 or mn= 6 or mn= 9 or mn=11
mndays = 30
case mn = 2
if mod(yr,4) = 0 and not mod(yr,100)<> 0 then
mndays = 29
else
if mod(yr,4)=0 and mod(yr,100) = 0 and mod(yr,400) = 0 then
mndays = 29
else
mndays = 28
endif
endif
endcase