Some old-school-ic filterin’ code

Filed Under (Visual FoxPro, work.BLOG) by WildFire on 09-08-2004

Early dawn-worm-code snippet:

if .chkMonth.value != 0 .and. !isblank(.cmbMonth.value)
cFilterDate = upper(alltrim(.cmbMonth.value))
cFilterYear = "(year(DATAAMPM.DATE) == year(date()))"
cFilter = "(upper(alltrim(cmonth(DATAAMPM.DATE))) == cFilterDate)"
cFilter = cFilter + " .and. " + cFilterYear
**' cFileName = cFilterDate + alltrim(str(year(date())))

dDate = cFilterDate + alltrim(str(year(date())))
report form Report_AMPM preview for &cFilter
else
cMess = 'Please specify the month first' + chr(13) + ;
'and check the Monthly Report filter'
messagebox(cMess)
endif

One… the above code is not ‘extremely optimized’ and was done around 2:16AM. So get over it.

Two… I’m just testing the preformatted tag and the colors. I recall someone blogging about a tool that ‘autocolorizes’ code in blogs, but I just can’t remember the URL. At two in the morning I don’t want to be involve in any searches.

Three it’s nice to know that the ELSE statement functions as ‘Everything Else’ in most programming language. Foxpro included.

In the above code, given lCondition_01 = .chkMonth.value != 0 and lCondition_02 = !isblank(.cmbMonth.value), the ELSE clause would execute when:

A. lCondition_01 == .F. and lCondition_02 == .F.
B. lCondition_01 == .T. and lCondition_02 == .F.
C. lCondition_01 == .F. and lCondition_02 == .T.

… and not just when A is satisfied. Which if this was done in one of our Math subjects (Automata-related) back in college will be the only basis for the output.

The cFileName line has been weeded out in comments just for the sake of this post. It has been my practice to save and export some filtered queries (‘native Foxpro filter’ and SQL queries) generated by the program to an .xls file.