Forgive me if this is obvious to all the Foxheads out there, but it’s something that I kind of ignored previously. You don’t have to send a single statement through a SQLEXEC() call.
Read the rest of this entry »
A while back, I wrote a short program showing how to use a ReportListener to change a field’s StringTrimming behavior. At the time, I used the GDIPlus foundation class which came out with VFP9. Now that Bo Durban and the VFPX folks have put together the GDIPlusX library, though, the code is a bit cleaner.
Read the rest of this entry »
Andrew MacNeill asks over on his blog:
…a single function that has been around in VFP for years and that is fairly readable would be replaced with a Regular Expression string, which is tough to even start to understand. (What does \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b mean?)
Well, there are easier ways to do it…
lcWordBoundary = "\\b"
lcOneToThreeDigits = "\\d{1,3}"
lcPeriodLiteral = "\\."
lcIPAddress = ;
lcWordBoundary ;
+ lcOneToThreeDigits + lcPeriodLiteral ;
+ lcOneToThreeDigits + lcPeriodLiteral ;
+ lcOneToThreeDigits + lcPeriodLiteral ;
+ lcOneToThreeDigits ;
+ lcWordBoundary
It’s wordy, but readable. Certainly a lot more readable than…
_CLIPTEXT = ;
Regexp(_CLIPTEXT, ;
"(\\s*?)(.*?)Prov = \\2Prov \\+ 1", ;
1, ;
"\\1\\2Prov = \\2Prov \\+ 1\\n\\1\\2Prac = \\2Prac \\+ 1")
…which I came up with the other day to help add a set of lines that were identical to existing ones, except for the variable names.
Ed Felten asks if this program will ever swear at you.
import sys, sha
h = sha.new(sha.new(sys.argv[1]).digest()[:9]).digest()
if h.startswith(”abcdefghij”): print “Drat”
He doesn’t know either. That’s what makes CS fun. :-) (h/t Laura)
A while ago, I posted about some of the stuff you could do with the FoxTools library and the VFP API. Tracy Pearson, on the FoxTalk list, came up with another neat bit of code.
*-- The following sets the font to Lucida Console 10pt
Local laEnv[25]
Set Library To (Sys(2004) + "FoxTools.fll") Additive
_EdGetEnv(_WOnTop(),@laEnv)
laEnv[22] = "Lucida Console"
laEnv[23] = 10
_EdSetEnv(_WonTop(),@laEnv)
Release Library (Sys(2004) + "FoxTools.Fll")
As part of my voyage into Perl, I’ve been working my way through Perl Best Practices, by Damian Conway. Much of what he suggests works no matter what language you’re in.
There’s one thing I ran into that really messes with my head, because very few people writing Fox sample code do it this way although it makes complete sense. Conway says that instead of writing:
MyTotal = MyFirst + ;
MySecond + ;
MyThird + ;
MyFourth
you should write:
MyTotal = MyFirst ;
+ MySecond ;
+ MyThird ;
+ MyFourth
Since you tend to read down the left side of the page, having the operators there tells you immediately what’s going on. I’ve always done this with Booleans, I think, but never concatenation…
Opinions, anybody?
My recent Twango post broke my XHTML compliance, because of the <EMBED> tag that showed the Flash ticker. After a bit of research, I came up with this wordy set of tags that validates as XHTML 1.0 Transitional and works in both IE6 and Firefox 1.5.
<object type=”application/x-shockwave-flash” data=”http://www.twango.com/tools/twidgets/ticker.swf?feed=SarekOfVulcan.3GradePoolParty” width=”500″ height=”100″><param name=”movie” value=”http://www.twango.com/tools/twidgets/ticker.swf?feed=SarekOfVulcan.3GradePoolParty” /></object>
I’ve let the Twango folks know: now we just have to see if the wordiness makes it unworkable.
I recently decided to write a program to automate part of a monthly job we have here. We have a tab-delimited file that has really long field names, some of which bear little resemblance to the purpose of the field. Rather than maintain a separate list of which old field went with the new names, I used the inline comment ability that was added to VFP a version or two ago, and put each field on a separate line of a CREATE TABLE statement. However, I got tired of typing in each fieldname, and decided to save myself some work.
lcRefStructure = "longFieldName1" + CHR(9) ;
+ "longFieldName2" + CHR(9) ;
+ "reallyLongFieldName3"
lnFldCount = ALINES(laStru, lcRefStructure, .T., CHR(9))
_cliptext = 'CREATE TABLE NewDBF ( ; ' + CHR(13) + CHR(10)
FOR i = 1 TO lnFldCount
_cliptext = _cliptext + CHR(9) + " C()" ;
+ IIF(i < lnFldCount, ",", "") + " ;" ;
+ CHR(9) + "&" + "& " + laStru(i) + CHR(13) + CHR(10)
ENDFOR
_cliptext = _cliptext + ")"
This gives the output:
CREATE TABLE NewDBF ( ;
C(), ; && longFieldName1
C(), ; && longFieldName2
C() ; && reallyLongFieldName3
)
Which makes it easy to run down the list and fill in the specifics.
(Making sure that the format is still what you think you’re importing is left as an exercise for the reader. :-) )
Update: fixed missing tabs in lcRefStructure
I recently had cause to write my first Perl script. Since I had never written Perl before, I wasn’t sure it was the right thing to do, so I went to the perl.beginners newsgroup for help.
My initial post:
I have an ASCII list of addresses that I need to parse into something
more-friendly to the software I need to use it with. I usually use
Visual FoxPro, and can think of a few ways to do it there: it just
strikes me that perl probably has much easier ways to do it. :-)
The response:
Yes, it is trivial in Perl. Enable paragraph-mode (see: perldoc -q
paragraph), read the file one record at a time. Split the record on
the newline (see: perldoc -f split), print the resulting fields
separated by commas (see: perldoc -f join).
I downloaded ActivePerl and went to work. After reading up on the above functions, I came up with the following:
local $/ = "\n\n";
open(ADDRESSES, "c:\\temp\\testing.txt") or die "Could not open input file: $! !";
open(OUTCSV, "> c:\\temp\\test2.txt") or die "Could not open output file: $!";
while() {
$NextRec = "\"".join("\",\"", split("\n"))."\"\n";
print OUTCSV $NextRec;
}
Good grief, if I had realized it was that easy, I would have picked it
up long ago…
The response came back:
just FYI - it gets easier. if your addresses are stored in addr.txt:
$ perl -ln00e 'print join ",", map qq["$_"], split /\\n/' addr.txt
I answered:
I think you just broke my brain.
The response from the person who had originally helped me:
Welcome to Perl. :-)
It just occurred to me that there is an easier way to open an Explorer window to my current directory in Visual FoxPro than going down to the Address Bar I have parked in my Windows Taskbar. This can go into an Intellisense script if you like, instead of the PRG file/utility menu I’m using.
LOCAL loShellEx as _shellExecute OF HOME(1) + "ffc\_environ.vcx"
loShellEx = NEWOBJECT("_shellexecute", HOME(1) + "ffc\_environ.vcx")
loShellEx.ShellExecute(CURDIR())