Search This Blog

Showing posts with label endif. Show all posts
Showing posts with label endif. 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

Changing Image or Picture of a Button

You can definitely change the picture of your bitton upon clicking, try these codes and play with the images. But first you have to prepare the image in JPEG.

IF THIS.Picture = "c:\images\edit.jpg"
THIS.Picture = "c:\images\save.jpg"
THISFORM.cmdClose.Picture = "c:\images\cancel.jpg"
ELSE
IF THISFORM.Combo1.Value = 'PESO'
lAnswer = MESSAGEBOX("Save changes?", 4, "Confirmation")
IF lAnswer = 6
THISFORM.cmdClose.Picture = "c:\images\close.jpg"
THISFORM.cmdEdit.Picture = "c:\images\edit.jpg"
ENDIF
ELSE THISFORM.COMBO1.Value = 'DOLLAR'
lAnswer = MESSAGEBOX("Save changes?", 4, "Confirmation")
IF lAnswer = 6
THISFORM.cmdClose.Picture = "c:\images\close.jpg"
THISFORM.cmdEdit.Picture = "c:\images\edit.jpg"
ENDIF
ENDIF
ENDIF

Empty Box

This code lets you use an Edit Box and will saved "Y" if the edit box is not empty otherwise save "N" if the edit box is blank. This is useful if you need to show in a View what Edit Box has an input and will not include blank.

SELECT QuestionTable
REPLACE q1comment WITH THISFORM.EDIT1.Value
IF EMPTY(THISFORM.EDIT1.Value)
REPLACE Q1Indicator WITH "N"
ELSE
REPLACE Q1Indicator WITH "Y"
ENDIF

If Else EndIf Code

You can utilize this code if you want your Command box caption to be change.

IF This.Caption = "Edit"
This.Caption = "Save"
Thisform.cmdClose.Caption= "Cancel"
ELSE
This.Caption = "Edit"
Thisform.cmdClose.Caption = "Close"
ENDIF