Friday, December 30, 2005

Intro to RSS and Some RB News Feeds

The purpose of this entry is to introduce RSS news feeds in general and some RB news feeds in particular. If you are aware of other worthwhile RB news feeds not listed here, please let me know, so that I can mention them in a future entry.

Although people agree on what "RSS" news feeds are, there is no such agreement on what "RSS" stands for. There are at least three options: "Rich Site Summary," "Really Simple Syndication," and "RDF Site Summary," where "RDF" stands for "Resource Data Framework," which makes it all sound much more complicated than it really is.

Let's see if I can explain it in simpler terms. If a site has an RSS news feed, using it is similar to your subscribing to a "what's new" newsletter related to that site, with some important advantages to a news feed.

For example, there is no mailing list (thus no hassle for the provider in maintaining and updating one and no hassle for the person reading a news feed (e.g., receiving spam mail as a result of getting on a mailing list he or she doesn't want to be on).

To get full benefit, you do need a "news reader" or "feed reader" program (sometimes also called an "aggregator") which automatically goes out on a regular basis (say, once an hour) to check your favorite sites for anything new in their RSS news feed, but many such programs are available for free (such as Abilon for Windows).

Here's a fairly large list of news reader programs available:

http://snurl.com/2dwz

And here's where you can find some smaller lists:

http://snurl.com/4b14

http://snurl.com/l5s1

A common way to set up such a program is to get the headlines and the first paragraphs of "what's new" on the site. You then can decide whether you're interested enough in a particular item to read the entire article. Many news channels (CNN, New York Times, etc.) make use of news feeds to get out the news in general, but there are also some news feeds that are specifically oriented toward REALbasic.

Before I mention a few, let me just briefly say that there is a competing format to RSS known as Atom, but you don't really have to concern yourself much with that, since many news feed reader programs can handle either format.

Now for the RSS news feeds for RB. Here are some to start with:

This blog (RB's: Where's the Beef?):

http://feeds.feedburner.com/RbsWheresTheBeef

REAL Software:

http://www.realsoftware.com/news/rss/

RB Garage:

http://feeds.feedburner.com/rbgarage

I'm new to this myself, so I make no guarantees regarding the quality of these particular feeds (except for the RSS for this blog, of course, which is guaranteed to be an amateur production <grin>).

Barry Traver

P.S. I was away from home visiting family for the Christmas holidays. That's why for a few days there have been new blogs without new programs to accompany them, but that should change now that I'm back home again.

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

Thursday, December 29, 2005

Method "Overload" Comments: Further Discussion

Note at the end of each blog entry there is an indication of how many comments have been posted to that particular entry. Sad to say, most of them say "0 comments," but after the immediately previous entry there were "4 comments" (well, actually 2 comments plus 2 responses from me).

If you click on the "... comments" you will be taken to an area where you can read comments people have posted or you can post a comment yourself. Before you can post a comment, you do have to register with Blogger.com, but you can register without having to start a blog.

Some helpful comments were posted by "silverpie":
Two improvements I would suggest: CStr() instead of Str(), so that if the user's format isn't US, it will still display as the user expects. Second, have the numeric version take a double as its parameter--it will still accept integers, but can thus show fractional values too.
Actually, even by itself CStr does much of what my "overloaded" S function does, i.e., it Converts to a Str a number of different data types. But I would argue that my S function still has at least two advantages: (1) It is easier to type one character ("S") rather than four ("CStr"), and (2) my S function has other features built in (specifically, EndOfLine and "|"). Here's the improved version of one of my definitions, thanks to silverpie's comments:
Function S (Param1 As Double) As String
Return EndOfLine + CStr(Param1) + EndOfLine
End Function
(The other definitions remain as they were before.)

I'd be interested to hear if people reading this have any of their own suggestions for worthwhile Method "overloads."

Also posted was this comment from Darryl of "glenarbourtech":
Hey Barry,

I just wanted to comment that as a RealBasic newbie, I really appreciate what you are doing here. Keep up the good work!

Darry|
Both posts are important because they both encourage me to keep this blog going. Writing a blog and writing programs takes time and effort (in short, it's a lot of work!), and what keeps me going is getting feedback from readers. So please feel free to post a helpful comment or a relevant question and/or please feel free to write me a private email at rb@ix.netcom.com.

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

Tuesday, December 27, 2005

Method "Overload" Example: A Debugging Aid

Don't let the word "overload" bother you. We won't be "overdoing" anything. In RB, "overload" means giving more than one method (i.e., Function or Sub) the same name, but with a different number or different types of passed parameters. [Originally I had said "(or different return type)," but that was wrong - see the helpful comment by Will Leshner smong the comments to this blog entry.] Many languages do not allow you to do that, but REALbasic does.

Let me give as an example something I use regularly as a debugging aid. Now, many people use MsgBox to help in debugging by displaying the value of a particular variable at a certain point in the Project. For example, suppose you want to check on the value of the integer XMLLineNumber. You can insert the following at the desired place in your program:
MsgBox "XMLLineNumber" + EndOfLine + Str(XMLLineNumber)
(The "EndOfLine" is there to put the value on a new line in the MsgBox.)

Or suppose you want to check on the value of the string XMLLine. You can insert the following:
MsgBox "XMLLine" + EndOfLine + "|" + XMLLine + "|"
(The "|" is used so that you can see if there is any blank space at the beginning or end of XMLLine.)

Or suppose you want to check on the value of the Boolean IsSource. You can do that with this:
If IsSource Then MsgBox "IsSource" + EndOfLine + "True" 
Else MsgBox "IsSource" + EndOfLine + "False"
It's a headache, however, to have to use three different formats (integer, string, and Boolean) and remember which one to use for which situation.

Instead of doing that, let's define (and "overload") a Function called S, all forms of which return a String (my reason for choosing to call it "S"), but which respond to different types of passed parameters.

First, define S with an integer Param1 as a passed parameter in this way:
Function S (Param1 As Integer) As String
Return EndOfLine + Str(Param1) + EndOfLine
End Function
Second, define S with a string Param1 as a passed parameter in this way:
Function S (Param1 As String) As String
Return EndOfLine + "|" + Param1 + "|" + EndOfLine
End Function
Third, define S with a Boolean Param1 as a passed parameter in this way:
Function S (Param1 As Boolean) As String
If Param1 Then Return "True" Else Return "False"
End Function
Once this is done, you can just use S, regardless of which of the three types of passed parameter we have in mind. Example:
MsgBox "XMLLineNumber" + S(XMLLineNumber)

MsgBox "XMLLine" + S(XMLLine)

MsgBox "IsSource + S(IsSource)
or even
MsgBox "XMLLineNumber" + S(XMLLineNumber) + "XMLLine" 
+ S(XMLLine) + "IsSource" + S(IsSource)
Try it -- you may like it!

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

Sunday, December 25, 2005

What's Planned for the Future for This Blog?

You may be interested in some of the things planned for the future for discussion in this blog and, more particularly, interested in some of the programs whose source code serves as the basis for the discussion. If so, read on!

Future TraverToys and/or longer programs are designed to illustrate how to perform these tasks:

(1) download a particular file from a certain Web address
(2) download all of the files of a particular type (e.g., .mp3 or .gif) from a certain Web page
(3) "harvest" email addresses (or http links) from a certain Web page
(4) "obfuscate" mailto links on a Web browser so as to let Web browsers access them normally but make it less likely that a "spambot" can harvest them
(5) convert simple text to simple HTML
(6) handle standard Unix-style "diff" files to update text files
(7) display a standard (e.g., .jpg or .gif) graphics file
(8) show one cross-platform technique to allow multiple file selection (plus one technique that works only with Windows)
(9) present a slideshow (including several ways to select multiple files
(10)modify source code so that blank lines appear before and after logicial units (if/end if statements, for/next loops, etc.) for increased readability
(11) modify source code to eliminate unnecessary spaces on each line
(which, along with the routine to remove blank lines, will reduce the amount of paper needed to print out source code)
(12) add a blank space in source code on each line after commas or before and after mathematical symbols (+, -, *, /, ^) or parentheses for increased readability.
(13) add automatic comments on source code lines starting with "Next," "Else," or "End If" to make it easier to follow the thought of long, complicated, or nested If/End If or For/Next loops.
(14) "obfuscate" source code by switching around the names of controls, properties, methods, variables, etc. (or "unobfuscate" it, if desired)
(15) change the name of a method, control, property, etc. throughout an RB Project
(16) count the lines in the source code for a program and indicate the type (normal source code, blank line in the source code, source code containing "hex bytes," etc.)
(17) check to make sure that no properties and variables have been given the same name or that no two counter variables on different levels of a nested For/Next loop are given the same name in an RB Project
(18) check to make sure that all Functions in an RB Project contain a Return statement
(19) add automatic headers (e.g., identification of purpose, programmer name, date, etc.) or automatic footers (e.g., exception handler) to each method in an RB project.
(20) enhance William Yu's Shisen-So game program to include the ability to move Back one or more steps, to move Forward again, to Re-set the gameboard to its original position, to Save to disk or Open from disk a game position at any point, to save on disk the "Top performance," or to Pause the game at any point.
(21) illustrate various "Coney Games," such as NimRow, 31 or Die!, or Tic Tac Toe Philadelphia Style
(22) show my own approach to a "Diff/Patch" program for providing updates to text files
(23) modify the "text editor" in the Tutorial to work not with "styled text" (or "Rich Text") but with plain ASCII text
(24) show how to add a "whole word" Search option (making use of RegEx routines)
(25) convert simple HTML to simple plain text
(26) suggest changes in, or additions to, the Language Reference

In addition, there are plans for the following Windows-specific programs:

(1) a simple API-based "mini-player" that can play audio CDs, .mp3 files, .mpg files, and .midi files
(2) a utility to show how to remove, as desired, display of Windows desktop icons, task bar, system tray, clock, etc.
(3) a utiltiy to allow "block comment" for all comment markers ("//" and "Rem " as well as "'")
(4) a simple Windows clipboard utility that will simplify insertion of boilerplate text of snippets into RB Projects

IMPORTANT: Thus far I have posted eight blog entries and four RB Project files, but I have gotten back almost no feedback as to whether people are getting any use of, or benefit from, them. If you are reading this, please let me know by sending a private email to rb@ix.netcom.com or by posting a comment here. It doesn't have to be a long note, but I need to know that I'm not just talking to myself! Thanks.

Incidentally, all RB Projects are now available in three formats: .rb, .xml, and .zip (one Mac person reported getting "gibberish" when he downloaded the .rb files).

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

Saturday, December 24, 2005

XML: All You Need to Know in One Easy Lesson

This will be simple. I promise. It won't be "all you need to know" if you are a professional programmer working with XML files, but it will be "all you need to know" to understand the basics of how REALbasic's own XML format works. And you'll have all the foundation you'll need to understand many of the TraverToys. But it will be simple.

After you've mastered this lesson, if you want further details on the "REALbasic XML Project Format" you will find it here:

http://www.realsoftware.com/support/whitepapers/xml/

First, what is XML? XML stands for "eXtensible Markup Language." The "eXtensible" part merely means that the language can be extended, but that's another topic for another time. The important thing to note now is that it is a "markup language."

Second, what does "markup language" mean? Well, suppose you have data that can be expressed as text. That data may be information about a Web page (in which case we might use "XHTML," i.e., eXtensible HyperText Markup Language) or an RB Project (which also has its own XML format, which we'll call "XRBML" for the purposes of this lesson).

So that the textual data is not just a jumble, it must be organized and "marked up" to show what each piece means and/or how the pieces fit together. You need to "mark up" the original textual data with comments or descriptions (also in textual format) to the textual data to fit it into categories and make it understandable.

Third, how can you distinguish the added comments and descriptions from the original textual data? The answer is simple: enclose it within "less than" ("<") and "greater than" (">") symbols.

Example from XHTML:

Suppose your text is "This is really simple!" and you want to show that the word "really" is to be put in bold type. Here's how it is done:

This is <b>really</b> simple!

And it is really simple to separate the original text from the added "mark-ups."

Fourth, XML does have two important rules to know. The first is that the comments always come in matching pairs (note the "<b>" and the "</b>" in the preceding example. The presence of "/" normally means "ends here"; its absence meana "starts here." The matching pairs requirement meants that this is NOT valid XHTML:

This is one paragraph.<p>This is another paragraph.

This IS valid XHTML:

<p>This is one paragraph</p><p>This is another paragraph</p>

That is, valid markup-language "tags" are like bookends. They come in matching pairs, and you need both for it to be valid XML.

Fifth, the other important rule is that the matching pairs need to be "nested" properly. "LIFO" ("Last In, First Out" and FILO ("First In, Last Out") apply here. You have to close the innermost pair before you close any other pair, and so on.

Example from XHTML:

The following is valid XHTML:

This is <i><b>really</b></i> simple!

But the following is invalid XHTML:

This is <i><b>really</i></b> simple!

These two rules followed by XHTML also apply to XRBML, i.e., the XML format for RB Projects. The difference is with the "tags" used (for example, RB uses "<SourceLine>" and "</SourceLine>" as tags to indicate the start and the end of a line of source code.)

Easy, eh? And that's all you need to know about XML to follow the source code and explanations for the TraverToys that work with the XML versions of RB Projects.

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

Thursday, December 22, 2005

Language Reference Utility1 for RB Browser/Editor

Suppose you are in the RB IDE consulting the Language Reference. Suppose further that you're on a particular page and you would like to add your own comment to that page.

Well, with the RB Browser/Editor for Language Reference (see yesterday's post), you can indeed add your own comment to that page. But there's a problem: how do you know which of the thousands of files that make up the HTML version of the Language Reference is the one you want to annotate?

It would be nice if you could know from within the RB IDE which file it is that you are looking at, but the RB IDE does not have an "address bar" you can consult to find out. Is there a solution to this problem? Certainly! Just edit the Language Reference files so that at the top of each file the name of the file is displayed.

"Sure," I hear you saying cynically, "the 'solution' is for me to edit thousands of HTML files. That would take forever!" Nope, it can be done in minutes, and you can let the computer do the work for you. That's why I wrote Language Reference Utility 1 (LR-Util1.rbp is the source code for it).

First, you need to find where on your computer the three folders are that need changing: Language Reference, Categories, and Topics. (Categories and Topics are subfolders under Language Reference.) Here's where the default installation puts the Language Reference folder in Windows:

C:\Program Files\REAL Software\REALbasic 2005r4\Resources\Language Reference

(I'm not sure where the RB installation puts it on the Mac or in Linux.)

Second, you run LR-Util1.rbp and process each of the three folders. To confirm that it has worked, go into the RB IDE and consult the Language Reference, and at the top of each page now should be displayed the HTML filename for that page, making it simple to write down the filename and use it when you run the RB Browser/Editor to annotate that page in the Language Reference.

Incidentally, I like the older Language Reference format better in one way: it was easier for me to choose things from an alphabetical list rather than trying to guess what category something might be placed in. I've been thinking of preparing a new index page set up alphabetically which could be accessed through (or, if desired, even take the place of) the normal starting page (index.html) for the Language Reference.

Has anyone done anything like that yet? Would you have any interest in its being done? (Or am I the only one who prefers to look up something alphabetically?) Or do you have any other suggestions of ways the Language Reference can be modified?

The nice thing is that if you don't like something, you can change it. For example, suppose you want to look up "FileOpenFolderItem." You select "Files" and then "Input/Output," but where is "FileOpenFolderItem"? It should be in that third column, right along with "FileSaveFolderItem," but it isn't. So add it yourself!

If you've run LR-Util1.rbp, you know that the file that needs to be changed is 31.html. You can also easily find that "GetOpenFolderItem" is discussed in 913.html. So you make the following change in 31.html , from this:

<p><a href="../Topics/908.html">GetFolderItem</a></p>
<p><a href="../Topics/920.html">GetSaveFolderItem</a></p>

to this:

<p><a href="../Topics/908.html">GetFolderItem</a></p>
<p><a href="../Topics/913.html">GetOpenFolderItem</a></p>
<p><a href="../Topics/920.html">GetSaveFolderItem</a></p>

inserting the new entry in the appropriate location. Save the result to disk, and you're all set. It's that simple!

Barry Traver



Blog Home Page: http://traverrb.blogspot.com

Page for Programs and Files: http://traver.org/traverrb/

Wednesday, December 21, 2005

RB Browser/Editor for Language Reference

I've written a "quick and dirty" RB Browser/Editor that not only makes it easy to add your own annotations and code snippets to the Language Reference files so that your additions can be accessed from within the RB IDE, but also makes it easy to add links to relevant outside materials in HTML.

Some Mac users may have discovered the book (in HTML format) I Declare: Calling External Functions in REALbasic by Charles Yeomans. If not, you can find it at this address:

http://www.declaresub.com/iDeclare/

After downloading the HTML files to disk (making sure all links in the book to other places in the book were in relative rather than absolute format), I used my RB Browser/Editor program to modify the first page of the Language Reference so that it contained a link to the home page on disk of that shareware book.

It works beautifully! (I've since removed the link, since the book seems to be more oriented toward Mac users than Windows users, but the experiment confirmed how simple it is to increase the material that is accessible from within the RB IDE.)

My program can be used, of course, not only with the Language Reference in HTML format (it is that version rather than the PDF version that is being accessed from within the RB IDE), but also with any normal collection of interlocking Web pages (including CSS as well as HTML). Warning, however: Although it works fine in Windows, it has not been tested on the Mac or in Linux.

Since the program's primary function is to edit Web pages but it contains no provision for FTP, it is designed to work not on the Internet but with disk files, especially Web sites on disk (and that is basically what the Language Reference and the book I Declare are). Instead of linking to I Declare, you could link , say, to your own collection of code snippets (after you've put them on HTML pages)..

One more thing I should perhaps mention. Although my program makes it possible to surf fowards or back through HTML pages and makes it possible to preview the results of your changes and/or additions before you decide whether or not to save them, therre is one shortcoming: Any annotations and code snippets and outside links you may add are NOT included in RB's Search within the RB IDE. But I do not consider that to be an especially significant drawback.

The program (including source code) is available at this address:

http://traver.org/traverrb/

It's called RB-BE-LR.rbp because it's an RB Browser/Editor for the Language Reference.

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

Tuesday, December 20, 2005

CardTrick for Windows Only

Even though REALbasic is a cross-platform language, I sometimes write programs that work only in Microsoft Windows. That's because that's what my computer runs, and I used to program primarily in Visual Basic, a language very similar to REALbasic. I was accustomed to being able to use API calls to access the Windows operating system, so as to put to use the DLLs (Dynamic Link Libraries) that already existed as part of the Windows OS.

Well, one of those DLLs, specifically Cards.dll, makes it easy to do the graphics for playing cards in any program in which playing cards play a part: solitaire (e.g., Klondike), card games (e.g., Poker), and even magic (card tricks)! Aaron Ballman shows how to make a card game for Windows on his Web site. Here's what he says:

Making a card game with Microsoft's Cards.dll
If you're like me and enjoy making fun card games,
but hate the tedium of the graphics logic, then you'll
be very interested in this simple set of classes which
make use of the Microsoft Cards.dll library. The sample
project includes a simple demonstrating of the classes
by implementing the game "War."

You can find Aaron Ballman's article and code here

Well, I thought I'd write a card trick based on Aaron's code. The program is called CardTrick.rbp and it works only for Microsoft Windows. Most of the programs I reference here in this blog will work on all three platforms, - Mac, Windows, and Linux - but occasionally (as in this case) I'll write a program that will only work in Windows.

The trick isn't especially impressive. If you're familiar with how doing a "binary search" is an efficient way to locate an item, similarly a "ternary search" is efficient as well. Mathematically, it is only necessary for you to tell the computer which of the three columns three times in order for the computer to narrow the choice down to one card out of twenty-seven (since 3 x 3 x 3 = 27). So it's not much of a magic trick, but the main purpose of the program is just to show another simple use of the Windows Cards.dll.

Doing graphics can be a bit tricky. Working with graphics on the screen causes the Paint event to take place, and if the Paint even does some painting itself, you can easily get lost in a vicious circle. My solution to that was to insert this at the top of the Paint event handler:

If DontDoPaintStuff = True Then Exit

DontDoPaintStuff is a global Boolean, and before I do some graphics work (like dealing a card) I set DontDoPaintStuff to True and then set it back to False as soon as I've finished. This keeps me out of vicious loops and keeps the graphics from getting messed up, as you'll see if you try out the program.

If you've got a Mac and have access to playing card graphics, you may want to see if you can modify CardTrick.rbp to work on the Mac. The fifty-two cards are numbered from 0 to 51 (four complete suits, no joker), and here's how I shuffled the deck:

Dim I, RandomPosition, Holder As Integer
Dim r as New Random
For I = 0 To 51
N(I) = I
Next I
For I = 51 DownTo 0
RandomPosition = r.InRange(0,I)
Holder = N(I)
N(I) = N(RandomPosition)
N(RandomPosition) = Holder
Next I

What's happening is that you're taking the last card and swapping it with a random card chosen from the rest of the deck, taking the next-to-last card and swapping it with a random card chosen from the (now one card smaller) remainder of the deck, and so on. The end result is that the entire deck has been randomized (shuffled), and you haven't had to worry about accidentally choosing the same card twice. This is simpler than some methods I've seen of shuffling a deck and is no less random than any other method.

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

TraverToy2 and Platform Determination

First, let me mention that I've replaced TraverToy1 with an improved version. I should have run TraverToy1 through my CodeHelper program before I uploaded the source code. The revised version eliminates Dimensioned but unused variables and alphabetizes the Dim statements and removed a bug that in effect removed the end-of-line markers in a processed file. So I thought I make make the topic of today's blog end-of-line markers, which (interestingly enough) is one of the ways we can determine the platform on which a program is running.

In a text file, the Mac, Linux, and Windows all use a different way of indicating the end of a line. The Mac uses a Chr(13) or "carriage return" character, Linux uses a Chr(10) or "line feed" character, and Windows - to be different - uses a Chr(13) followed by a chr(10) character (CR/LF or "carriage return"/"line feed"). (Well, actually Windows isn't consistent on using that end-of-line marker - it does something different in EditFields - but that's another topic for another time. Suffice it to say that in a text file it does what I have just said it does.)

What practical use does this information have? Not very much. It is likely that all of the text files you have fit" your platform, so it's not that helpful to be told that a file on a Mac computer is a Mac file, a file on a Linux system is a Linux file, or that a file on a Windows PC is a Windows file. Whan might it be otherwise? Well, if you download from the internet a file that came from a friend using a different platform, you could end up with, say, a Windows file on your Mac computer. Even so, you're unlikely to have problems in accessing the file, since your computer will know what to do with it, even if it did come originally from a different platform.

What TraverToy2 does is allow you to do something like this: If you own a Mac and you're sent a Linux or Windows text file, you can modify the file with an RB program and send back the file as a Linux or Windows file based on the type of file you were sent. And so on. I have no idea where you'd find a situation where it would be important to do that, but I never promised that all the TraverToys would be useful. I just indicated that you'd find things here you wouldn't find elsewhere (and sometimes for good reason!)

To analyze the type of file, some "RegEx" routines are used. I won't try to explain RegEx at this point other than to say that it's a way to do some rather complex searches. Here it simply checks to see what chr(13) or chr(10) or Chr(13)+Chr(10) is being used as an end-of-line marker, and then reports accordingly that it's a Mac, Linux, or Windows text file. If you already know how to use RegEx, you won't need an explanation from me; if you don't know what "RegEx" is all about, I won't try to explain it here in "one easy lesson."

Acknowledgment: I think it was "dda" (Didier) who taught me how RegEx makes it possible to do thing like this, so I do hope to be getting back to a somewhat detailed explanation of RegEx later when we do some "whole word" searches of XML files.

Incidentally, you may be wondering what sort of goals I have for this blog. Well, I'm hoping (if I get feedback that there is some interest in people's reading what I write) to add at least one new entry every two days, and to add at least two new programs (usually short TraverToys, but occasionally larger programs) each week (but, again, that is dpendent upon there being evidence that people are reading the blog, so please take the time to send me a private email or to post a short comment if you want me to continue).

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

Sunday, December 18, 2005

TraverToy1 and Removing Blank Lines

TraverToy1 has arrived, and its purpose is show how to remove all blank lines from the source code. Before you use it, you have to save the RB Project you want to process as an XML file. (Cheer up you won't need to know anything about XML in order to understand the program.) An XML file is just a simple text file in a particular format. In it you'll see "tagged" text, similar to what you see in an HTML or XHTML file. Well, that's the alternate way you can save an RB Project, but we will be looking at it as just a bunch of lines of text (strings) that we will manipulate as strings.

Here's all you need to know for the moment: There are two types of lines in the XML file: lines the contain source code and lines that don't. The source code lines start with a "<SourceLine>" tag and end with a "</SourceLine>" tag. What is between the two tags is the source code for the program. If the tags have no text between them (other than, say, blank spaces), then that is a blank source code line.

To remove the blank lines of source code, then, all you need to do is to go through the lines of the file and check each line. If a line has "
<SourceLine>" and"</SourceLine>" tags it is source code. If there's no real text between the two tags (but just "empty space"), then remove that line. Then save the result back to disk.

There are a number of ways to read in the information from the file. You can read it in a line at a time, or you can (as this program does) load the whole file in at once as a super-long string, and then break that super-long string up into an array of smaller strings, each of which represents one line in the original XML file. Thus in TraverToy1, FileStreamA.ReadAll reads the whole file into memory as a super-long string and then uses the RB's built-in Split Function to break it up into individual lines, each of which becomes an element in an array. (In the program, the super-long string is called "MainBuffer" and the array of lines is called "XMLLines.")

For the processing, it's a simple matter of looping through the lines in the array, one line at a time, and removing from the array those elements that are blank lines. Then the lines of the array (XMLLines) are put back together in a super-long string (MainBuffer).

Finally, the result is saved back to disk. There are a number of ways this could be done. It could be written a line at a time, but the program saves the whole super-lone string Miainbuffer using FileStreamB.Write MainBuffer. That's all there is to it!

When you've finished, simply load the modified XML file into the RB IDE, from which it can be saved as a normal RB Project. Look at the source code, and you will indeed see that all of the blank lines have now been removed!

Similarly, it would not be difficult to write a short TraverToy to make other changes in line spacing, such as double- or triple-spacing the source code (to make more room for annotating source code that is printed out) or using blank lines to separate out logical units of code (e.g., putting a blank line before and after If/Then/Else/EndIf statements or For/Next loops). We may in fact do that in a future TraverToy or two, but we may do some other interesting things before then.

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

Saturday, December 17, 2005

REALbasic (RB): A Cross-Platform Language

REALbasic (RB) is a cross-platform computer language used to develop programs for Windows, Mac, and Linux. In some ways, it is very similar to Visual Basic 6.0, except that an RB program will run without the hassle of a complicated installation procedure or the presence of a separate runtime file: you can put your program into a single file on a CD-ROM, and run it from there! "Where's the beef?" (the complaint) with RB? There is none.

Well, maybe there is one: the lack of availability of any quantity of sample source code comparable to the amount of Visual Basic source code available at places like Planet Source Code. The purpose of this blog is to two-fold: (1) to share comments about things I've learned about RB and (2) to announce the availability of RB source code for (I hope) hundreds of short RB programs to be called "TraverToys."

The emphasis will be upon short programs that are "simple samples," learning examples that may serve as building blocks for larger programs. In many cases the programs will do things that you won't find elsewhere, in spite of the small size of the TraverToys. Only source code will be provided, so this blog (or RBlog) is intended specifically for REALbasic programmers. Executables are not "cross-platform," but the source code should be, unless otherwise noted, although most of the programs have only been tested for Windows (using RB 2005 on Windows XP, although earlier versions of RB or Windows may often work as well).

Disclaimer: No promises, warranties, guarantees, etc. of any kind are made here. The code may or may not work for the purpose you intend. If it doesn't, then I warned you of that. If it does, and if you would like to say "Thank you" in some concrete way (e.g., by sending a donation), then that would be great and much appreciated (although I will have to earn it first by providing enough useful TraverToys that you will want to do so). I'll explain in a future entry how that may be done.

The plans are also to include comments on and make reference to longer programs from time to time. Links will be provided to those larger programs as well. The TraverToys collection, however, will all be "barebones," not much more than enough code snippets to accomplish the purpose.

Example: The first TraverToy, TraverToy001, will show you how to remove automatically any blank lines from the source code for an RB Project. It will involve these steps:

1. Saving the RB Project as an XML file.

2. Running TraverToy1 and "processing" that XML file.

3. Loading the modified XML file into the RB IDE, and saving it back to disk as a normal RB Project.

Incidentally, TraverToy1 is based on a larger Project in progress called RBCodeHelper, which offers over a hundred tasks that can be performed. If you are interested in being involved in the development process for RB CodeHelper, please let me know by sending a private email to rb@ix.netcom.com, listing "RB CodeHelper" as the Subject of the email.

Another disclaimer: I'm not a professional programmer (although I've been programming in Visual Basic since before version 3.0). I've been using REALbasic for only about a year, and there is much yet for me to learn. Thus I am very much interested in getting feedback and constructive suggestions from any readers of this blog. (Again, you're invited to
send a private email to rb@ix.netcom.com, but this time listing "TraverRB Feedback" as the Subject of the email.)

Finally, for their sake, I probably should mention that I am in no way officially connected with REAL Software. I just like RB, and I like writing RB programs that I hope will be useful or enjoyable to other people.

Brry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/