Search This Blog

Showing posts with label foxpro. Show all posts
Showing posts with label foxpro. Show all posts

Number to Words FoxPro Code

Here is a sample of a FoxPro code on how to change the numbers you typed into words or number to words functions.

PARAMETER numAmt

PRIVATE numAmt, chrAmt, cDNums, wordAmt, cDvar

*Covert amount to string, add leading zeros
numAmt = VAL(THISFORM.Text1.Value)
chrAmt=RIGHT('000000000'+LTRIM(STR(numAmt,12,2)),12)

*Initialize literal string
Dol1 = 'ONE'
Dol2 = 'TWO'
Dol3 = 'THREE'
Dol4 = 'FOUR'
Dol5 = 'FIVE'
Dol6 = 'SIX'
Dol7 = 'SEVEN'
Dol8 = 'EIGHT'
Dol9 = 'NINE'
Dol10 = 'TEN'
Dol11 = 'ELEVEN'
Dol12 = 'TWELVE'
Dol13 = 'THIRTEEN'
Dol14 = 'FOURTEEN'
Dol15 = 'FIFTEEN'
Dol16 = 'SIXTEEN'
Dol17 = 'SEVENTEEN'
Dol18 = 'EIGHTEEN'
Dol19 = 'NINETEEN'
Dol20 = 'TWENTY'
Dol30 = 'THIRTY'
Dol40 = 'FORTY'
Dol50 = 'FIFTY'
Dol60 = 'SIXTY'
Dol70 = 'SEVENTY'
Dol80 = 'EIGHTY'
Dol90 = 'NINETY'
wordAmt=''
IsHundred = .F.
checkMillion =.T.
FOR Counter = 1 TO 3

* First time through the For loop to check for millions
* Second time through the FOR loop to check for thousands
* Third time through the FOR loop to check for hundreds, tens and ones
DO CASE
CASE Counter = 1
cDNums = SUBSTR(chrAmt,1,3)
CASE Counter = 2
cDNums = SUBSTR(chrAmt,4,3)
CASE Counter = 3
cDnums = SUBSTR(chrAmt,7,3)
ENDCASE

* Check hundreds
IF LEFT(cDNums, 1) > '0'
cDvar = 'Dol'+LEFT(cDNums,1)
wordAmt = wordAmt + EVAL(cDvar)+SPACE(1)+'HUNDRED'+SPACE(1)
IsHundred = .T.
IF Counter = 2
CheckMillion = .T.
ENDIF
ENDIF

* Check tens and ones
Dtens = VAL(SUBSTR(cDNums,2,2))
IF Dtens > 0
IF Dtens > 20
cDvar = 'Dol'+SUBSTR(cDNums,2,1)+'0'
wordAmt = wordAmt + EVAL(cDvar)
IF SUBSTR(cDNums,3,1) > '0'
cDvar = 'Dol'+SUBSTR(cDNums,3,1)
wordAmt = wordAmt + '-'+ EVAL(cDvar) + SPACE(1)
ELSE
wordAmt = wordAmt + SPACE(1)
ENDIF
ELSE
cvar = 'Dol'+LTRIM(STR(Dtens))
wordAmt = wordAmt + EVAL(cDvar) + SPACE(1)
ENDIF
IsHundred = .F.
IF Counter = 2
CheckMillion = .T.
ENDIF
ENDIF

* Add in Million, if needed
IF numAmt > 999999.99 .AND. Counter = 1
wordAmt = wordAmt + SPACE(1)+'MILLION'+SPACE(1)
CheckMillion = .F.
ENDIF

* Add in Thousand, if needed
IF CheckMillion
IF numAmt > 999.99 .AND. Counter = 2
IF Dtens > 0
wordAmt = wordAmt + SPACE(1)+'THOUSAND'+SPACE(1)
ENDIF
IF IsHundred
wordAmt = wordAmt + SPACE(1)+'THOUSAND'+SPACE(1)
ENDIF
ENDIF
ENDIF
ENDFOR

* Construct the complete dollar amount in words
wordAmt = IIF(numAmt<1, 'ONLY'+SPACE(1), '** ' + wordAmt + ' **') &&+SPACE(1)) + RIGHT(chrAmt,2)+'/100 ' + IIF(numAmt>1,'S','')
RETURN wordAmt

Subsidiary Ledger

Subsidiary Ledger account in the Chart of Accounts from the Account field and scroll and click the desired branch on the Branch field.   Indicate in the Start Date and End Date the desired transaction period to be displayed for the chosen account.  Ok button allows the user to refresh screen and current entries for a particular period, account and Branch will be displayed in the transaction field.

Journal Entries in FoxPro


The Journal Entry window inputs transactions and posts these transactions to the General Ledger. Although multiple users are allowed to input transactions, only the GL Bookkeeper can post transactions.

Activity Log in FoxPro

This is my first sample form of Activity Log in FoxPro. My current project which is a General ledger required me to have Activity Log. It is easy to make a log but requires me to update the table from different form and command such as login, logout, add, edit, delete and post. But will be handy of traceability purpose.

Changing Signatory Code

Most of the program I made out of FoxPro required signatory. This signatory can be achieve upon login into the system.

SELECT Signatory
LOCATE FOR signnum = 1
IF FOUND()
REPLACE SignName WITH THISFORM.Text1.Value
REPLACE SignPostion WITH THISFORM.Text2.Value
ENDIF
LOCATE FOR signnum = 2
IF FOUND()
REPLACE SignName WITH THISFORM.Text3.Value
REPLACE SignPostion WITH THISFORM.Text4.Value
ENDIF
LOCATE FOR signnum = 3
IF FOUND()
REPLACE SignName WITH THISFORM.Text5.Value
REPLACE SignPostion WITH THISFORM.Text6.Value
ENDIF
=MESSAGEBOX("Signatories successfully save.")

Day Month Year Code

THISFORM.TEXT1.VALUE = DAY(DATE())
THISFORM.TEXT2.VALUE = CMONTH(DATE())
THISFORM.TEXT3.VALUE = YEAR(DATE())

Log Out Code

PUBLIC pCurrUser
SELECT SviewAccess
=REQUERY("SviewAccess")
LOCATE FOR ALLTRIM(UserName) = ALLTRIM(pCurrUser)
IF FOUND()
REPLACE AccessStatus WITH "LOGOUT"
THISFORM.REFRESH
ENDIF

CLEAR EVENTS
ON ShutDown
QUIT

SQL Connections

Using SQL Server, you will need a connection string to be able to access the database. Here is the basic connection string format.

DRIVER=sql server;SERVER=ServerName;UID=UserName;PWD=Password;APP=Microsoft Visual;WSID=PcName;DATABASE=DatabaseName

Do not forget to verify connection.

Trial Balance Report

Here is the sample report designer or FRX. You can use groups in the report designer. As you can see, I used Data Groupings. You will group by the field "Name" for example. In the group footer, you can use a variable which sums the field "amount". Right click your report and look at the tabs Data Grouping and Variables.

Special Thanks to Samir of Foxite.

Opening a PDF File

You can open a PDF file in VFP b using below codes. Just specify the location of your PDF file on cFileName

DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin
cFileName = "c:\GenLed\Images\CC.pdf"
cAction = "open"
ShellExecute(0,cAction,cFileName,"","",1)

Report Code

Calling a report from a form is very easy. You can even call a multiple reports that comes from your application. Microsoft Visual FoxPro is very flexible, you do not have to install other application in making print reports. VFP 's built in reports can call view from a table either local or through local area connection such as SQL from a server.

txtName = ALLTRIM(THISFORM.txtName.VALUE)
txtBirthDate = ALLTRIM(THISFORM.txtBirthDate.VALUE)
txtBirthPlace = ALLTRIM(THISFORM.txtBirthPlace.VALUE)
REPORT FORM "C:\ProjectName\Reports\Resume" TO PRINTER PROMPT NODIALOG PREVIEW

Edit Save Code

Microsoft Visual FoxPro programming language has a lot of code to edit, insert, replace or save. Using select, append, insert or replace is some of the ways to save data. I always use the select and replace because it is easy to troubleshoot when your code has a problem.

SELECT InfoNumber
LOCATE FOR IdNum = THISFORM.txtIdNum.VALUE
IF FOUND()
SELECT InfoNumber
REPLACE LastName WITH ALLTRIM(THISFORM.txtLastName.VALUE)
REPLACE FirstName WITH ALLTRIM(THISFORM.txtFirstName.VALUE)
REPLACE MiddleName WITH ALLTRIM(THISFORM.txtMiddleName.VALUE)

Do Case Code

When you have a multiple case which you would want a different action, you can use the Do Case. Do case is very useful code when used wisely.

DO CASE
CASE THISFORM.txtSqlId.VALUE = 1
MESSAGEBOX("Argentina", "Information")
CASE THISFORM.txtSqlId.VALUE = 2
MESSAGEBOX("Bangladesh", "Information")
CASE THISFORM.txtSqlId.VALUE = 3
MESSAGEBOX("Malaysia", "Information")
CASE THISFORM.txtSqlId.VALUE = 4
MESSAGEBOX("Philippines", "Information")
CASE THISFORM.txtSqlId.VALUE = 5
MESSAGEBOX("Taiwan", "Information")
CASE THISFORM.txtSqlId.VALUE = 6
ENDCASE

Export Code

Use this code when you want to export data from table to Excel File. Plus with a message box informing you if you want to do so. There is also a message box that telling you that you have successfully exported your table to an Excel File.

lAnswer = MESSAGEBOX("Generate Report, do you wish to continue?", 4, "Generator")
IF lAnswer = 6
SELECT SeafarerList
=REQUERY("SeafarerList")
COPY TO "C:\SEAFARER.XLS" XL5
=MESSAGEBOX("File successfully generated.", "Successful")
ENDIF

FoxPro Window


Above image shows the working interface window of Microsoft Visual FoxPro.

  • Data
  • Documents
  • Class Libraries
  • Code
  • Other

FoxPro Accounting Form



Sample accounting form using text box, command button, grid and page frame. This is one of my interface I used in Accounting Units. It has complex functions.

Image one has motif of blue and consist of grid, page frame, several text box and several combo box. It has a function of add, edit, save, delete and other function that was require to make the User usage comfortability. It also allows you to search for a certain name and shows or retrieve the dat data on text and combo box.

Image two has more complex function than the first one. It is use for cash and check voucher. Aside from that the viewing of data being save are also incorporate. As you can see there is a five page frame available. These page is utilize to the step by step documentation of data.

While the third image for the purpose of viewing of queued data from the Operation Department thus using the Local Area Connection.

Microsoft Visual FoxPro


Microsoft Visual FoxPro is a data-centric object-oriented and procedural programming language produced by Microsoft. It is derived from FoxPro originally known as FoxBASE which was developed by Fox Software beginning in 1984. Fox Technologies merged with Microsoft in 1992, after which the software acquired further features and the prefix "Visual". The last version of FoxPro 2.6 worked under Mac OS, DOS, Windows, and Unix: Visual FoxPro 3.0, the first "Visual" version, dropped the platform support to only Mac and Windows, and later versions were Windows-only. The current version of Visual FoxPro is COM-based and Microsoft has stated that they do not intend to create a Microsoft .NET version.

FoxPro originated as a member of the class of languages commonly referred to as "xBase" languages, which have syntax based on the dBase programming language. Other members of the xBase language family include Clipper and Recital. A history of the early years of xBase can be found in the dBase entry.
Visual FoxPro, commonly abbreviated as VFP, is tightly integrated with its own relational database engine, which extends FoxPro's xBase capabilities to support SQL query and data manipulation. Unlike most database management systems, Visual FoxPro is a full-featured, dynamic programming language that does not require the use of an additional general-purpose programming environment. It can be used to write not just traditional "fat client" applications, but also middleware and web applications.