Making REALbasic impersonate VFP

When transitioning from one language to another, there's always an awkward time where you're thinking like the old language, and struggling with the new. In the past it has been of help to create functions in the new language to help the transition process. Eventually the "transition" function set is abandoned for the pure implementation of the language.

This is what I've done to help me convert over to RB. I'm not completely in the RB mindset yet however, but I thought I'd at least blog about my transition class. RB (unlike VB) is object oriented so it is only natural that I've created a class the contains my VFP functions within it. I've started adding some of the jewels in VFP to this class and kept the same interfaces. Here are some of the methods of the class:

  • AT(cSearchExpression, cExpressionSearched) - Returns integer location of the search expression.
  • FileToStr(cFileName) - Returns string of the contents of the file reference.
  • StrToFile(cContents, cFileName) - Writes the contents of a string to a text file.
  • GetWordNum(cSource, nWord, [cDelimiter]) - Returns the Nth word from a string.
  • MessageBox(cMessage, nDisplayOptions, cTitle) - Creates a simple window to display the information.
  • StrExtract(cContents, cFirstParameter, cSecondParameter) - Returns string between two delimiters. Great for HTML or XML.
  • StrTran(cSource, cExpressionSought, [cReplacement]) - Replaces all strings with another in the source string.
  • Substr(cSource, nStart, [nLength]) - Returns a substring from the source, starting at a location for nLength number of chars.

Some of these methods are trivial conversions over to RB, but it's nice to have this as a reference. For example, the oVFP.SUBSTR() method really just calls the RB method of MID(). Simple but it makes me feel at home while I'm transitioning. FILETOSTR() and STRTOFILE() are MUCH more complex however. I guess were spoiled in VFP in this case. Remember that files are case sensitive in Linux!

To take advantage of my class in an application, I just add it to the project. I normally keep it external so that multiple projects can take advantage of enhancements to this class. To instantiate it, I can create a property on the application called oVFP and in the application OPEN() method, I just:


So, from that point I can reference:

DIM cMyWord AS String = ""

cMyWord = APP.oVFP.GetWordNum("Now is the time for all good men", 4) // returns 'time'

cMyWord = oVFP.GetWordNum("Now is the time for all good men", 7) // returns 'good' but in a more simple object reference way

Simple but handy. At some point, I'll stop using the oVFP.AT() and just use the InSTR() method, but it's nice to have that available, and it is handy to have it as a reference to immediately make the transition. FILETOSTR() and STRTOFILE() may live longer however as it is more complex in RB than what I'm used to in VFP.

I'm wrapping this in project that does unit tests on the methods as well. It will keep me honest as I'm developing it and moving through the versions of RB. RB2008R1 will be out in a month or so.

If anyone wants a copy of the project, just let me know and I'll be happy to send you a copy or to post it somewhere. If I'm missing a method that is preventing you from trying RB, just let me know and I'll see if I can get it built in.