Saturday, January 31, 2015

Accurate Age Calculator


I never gave thought to calculating an age of a person in terms of years, months and days. But since I read a thread in Foxite pertaining to such need, then I decided to find out how hard it really is.  And it really is not simple as problems appear in months and days.

Anyway, I always try to think beyond the box meaning I do not limit my tools from within VFP itself so I realize a way to do that easy is via automation using Excel.  Excel has this cool function called DATEDIF to get an accurate difference between years, months and days.  So that is where the experiment went.  And here it is:

Public oAge
oAge = Createobject('EMPTY')
AddProperty(oAge,'Year',0)
AddProperty(oAge,'Month',0)
AddProperty(oAge,'Day',0)

Create Cursor junk (Person c(10),birthdate d, enddate d, nYear I, nMonth I, nDay I)
Insert Into junk Values ('Jun',Date(1971,7,13),Date(),0,0,0)
Insert Into junk Values ('Rolly',Date(1952,9,21),Date(),0,0,0)
Insert Into junk Values ('Whoever',Date(2012,6,11),Date(),0,0,0)
Insert Into junk Values ('Baby 1',Date(2014,8,3),Date(),0,0,0)
Insert Into junk Values ('Baby 2',Date(2014,12,29),Date(),0,0,0)

* Create an Excel file
Local loExcel As excel.Application
loExcel = Createobject('excel.application')
With loExcel
      .Workbooks.Add()
      .DisplayAlerts = .F.
Endwith
Scan
      GetAge(birthdate,enddate,loExcel)
      Replace nYear With oAge.Year, nMonth With oAge.Month, nDay With oAge.Day
ENDSCAN

loExcel.Quit
Browse Normal

Thursday, January 29, 2015

TitleBarX Class

* Updates February 2, 2015

Added NoMax property to hide Max Button.  This should not be confused with _noMax property which simply disables the max button

Added NoMin property to hide Minimum Button

Added 3 shapes at the bottom to give an illusion of a gradient bottom border.  Although GDI+X is good for gradient, I want my classes to not be dependent of an external file like an .app.  Maybe in the future I may change decision or not

Added Form Pinning capability on Controlbox section.  When it is pinned, the pin icon will turn into red and you won't be able to move the form.  To unpin, click on it again

Removed the date and showed instead plain time().  Made it bigger

Added _shade method.  That is what you can use to get a different shade of the current color you  pick for other objects in the form (using _SwapColor Method).  So now you can implement color themes with variying shades not only on the class itself but on any objects you wish.  Here is how it looks like


Friday, January 16, 2015

Tick/Untick a checkbox on Grid with AllowCellSelection = .F.

Normally, when we want to put a checkbox on grid for the purpose of ticking and unticking it, then most probably most of you do it this way:



  • Set AllowCellSelection = .T.
  • Drill to every textbox object inside each columns and put under When method Return(.f.).  That is to prohibit the cell in getting focus


An alternative way is to set AllowCellSelection = .F. and use grid's double-click on toggling the value of the logical field bound to that checkbox, then perform a grid refresh

Monday, January 12, 2015

ShellExecute, Force open file to non-default application

As most of us know, ShellExecute() is a very useful tool to open a file on its external associated application.  When you issue this command:

Local lcFile
lcFile = Getfile('doc,docx')
If !Empty(m.lcFile)
      ShellExecute(0,'open',m.lcFile,'','',1)
Endif

Then that document file will be opened by MsWord or its counterpart like say on LibreOffice

Or if you do:

Local lcFile
lcFile = Getfile('xls,xlsx')
If !Empty(m.lcFile)
      ShellExecute(0,'open',m.lcFile,'','',1)
Endif

Or even: