Wednesday, September 28, 2005

[MetaCard and Tcl] Broggle's cousin at home on the iBook

MetaCard's great but I can't afford to buy it (not that you can anyway, now that it's been subsumed into Runtime Revolution). But using the demo version means I keep bumping up against an inbuilt limit for scripts. So I hit upon the idea of bypassing the issue by calling external scripts.

The tool I use to write blogs at home (as opposed to the HTA I use elsewhere) is written in MetaCard and does the render and preview passes using Tcl.

[Aside: Not that there's anything about Tcl that lends itself to the job. I could have used Perl, Lua, Python, sed (maybe), awk, or any number of other languages from Algol68 (there's an implementation for Mac OS X believe it or not) right through to Zen BASIC. It's just that Tcl is familiar ground.]

Right, where was I. Oh yes ...

First the script in my "Render" button ...
... which creates a file in the temporary folder (I'm on Mac OS X here ... might work on Linux ... have to do something drastic for Windows), and puts my marked-up text from field fSource into it. Then it shells out to render.tcl and captures its output into the fGenerated field. The temporary file is deleted.

Render.tcl looks like this (in its current incarnation):
This script inhales the file specified on the command line, splits it on newline and works its way through the lines, outputting HTML according to the rules of the markup: @ in column 1 identifies markup and there are currently four types: text, code, quot and end. Very simple, but it does me fine ... for now.

So after this runs, there's HTML in the fGenerated field. If I want to see how it's going to turn out in a browser, then I click on the Preview button. Okay, so it won't have all the CSS definitions that blogspot/blogger would apply but I get a useful approximation.

The script for the Preview button ...
... is similar to that of the Render button except this time I create an .html file in /tmp and and write the contents of the fGenerated field to it. I ignore the output of the shell() command.

I haven't quite figured out how to delete the temporary file because, if I uncomment the "delete file", by the time Safari is ready to load the file it's gone. There might be some way of making the shell synchronous, the way that /WAIT does on Win2k's START command, but then that'd probably mean waiting until Safari quits before I can use my blog writer again ... definitely sub-optimal. Then again, it'd be waiting for "open" to close, which happens as soon as it's launched Safari. And it's 10:48 pm and ...

Well, that's it. I really enjoyed this short break away from the long run of VBScript posts. I've got more stuff cooking here at home including a short foray into Javascript (a language I should have learned ages ago). Till then ...

Tuesday, September 27, 2005

[VBScript] function parameters

Things just got very interesting ... function parameters. This is where late binding helps. The mind reels: Dictionaries of references to procedure and function objects?

[VBScript] allsorts (not licorice)

Assorted sorts. I figured out I didn't need them after all. The BubbleSort is the slowest on large datasets.

[VBScript] using Watcher

And I've discovered that my Zerofill routine, which can be given any number of leading zeroes, never gets called with anything other than 2 leading zeroes. I discovered that by changing 'watch "Zerofill"' to 'watch "Zerofill." & nWidth'. Zerofill gets called > 700,000 times in a session.

So I create a new version of Zerofill
which I call Zerofill2 and get a slight speed-up

[VBScript] "Watcher" - on the way to code profiling ... sort of

I've just implemented a new class, Watcher, which is giving me an idea of what routines in my stdFunctions.vbs are actually being used, and how frequently.

At present the class depends on some of the routines it would otherwise be watching so those routines can't refer to Watcher until such time as I make the class self-contained.

The class gets instantiated in the usual way right at the start of my stdFunctions.vbs file
and then at the beginning of each of the subs and functions in stdFunctions.vbs there is a reference to watch, e.g. When the class terminates the data is saved in Watcher.txt as lines of tab-delimited text, for example: and these are then read back in at the initialisation of class next runtime round.

If you find this useful please let me know. Code below.

[VBScript] Map. Is there a more useless function?

Map is great for other languages. I've implemented it for no good reason. And I really can't think of a good use for it. Anyone?

Monday, September 19, 2005

[VBScript] Timer class

A class to set multiple timers and get back program run time in seconds, or as a nicely formatted hours-minutes-seconds. An example: ... which gave (at time of testing) ...

[VBScript] Classes, classes, classes

Over at Win32Scripting where I've been hanging out of late, some bright spark, Tony Hinkle by name, put up code to
"Use IE as an output device! This script is an example of how to make a DIV element an object and then change the innerHTML property. This is a vbs file, not an .asp file. ..."
Being adventurous, I turned it into a class and added a bit of WMI to get the screen dimensions. And some test code which puts boxes at 9 different points on the screen:

Thursday, September 15, 2005

[VBScript] Helping out with wildcarded directory searches

At Emulate The Dir Command Via Vbscript... ( Vbscript ) Christian D'heureuse had written a ListDir Function to list files using wildcards. Someone else wanted filtration and another suggested regular expressions. The following works a little faster than the latter and gives fine control over what is acceptable and what is not.

The following collects all the files to a comma delimited list (you may want to put it in an array).
I then used this function to do the filtration and tied it all together as below (this is cut from a project file and the ellipses indicate code removed.) The inclusions and exclusions are handled through arrays, and in my project these were drawn from .ini files, a part of which is recorded below This all ran fairly fast and is better for speed than a regular expression mechanism, albeit at the cost of code size.

Wednesday, September 14, 2005

[VBScript] Helping out with DateDiff

Another from helping out at Automate Excel In Vbscript... ( Vbscript )
Please tell me how to subtract to time values. eg: 10.15 AM - (minus)8.30 Am Using example explain me
The DateDiff function is the one to use in this case. Using your data

Tuesday, September 13, 2005

[Neko] Check it out!

For another take on the Virtual Machine idea, see "Neko" via the weblog of it's creator Nicolas Cannasse

Friday, September 09, 2005

[VBScript] Evaluator

A quick scripting environment so that I could bash out a few lines, get the results easily and put them on the clipboard.

Have been using the Vrode Editor 1.1 for HTA development.

Thursday, September 08, 2005

[VBScript and Excel] Relative/Absolute references

Again at Automate Excel In Vbscript... ( Vbscript ), Pentium10 wrote
I have a script which fills cells with exce.range.value function, but I have columns more than A-Z, how can I handle AA,AB, AC... columns???

Here is the script what I have:
excel.Range(chr(65+i) + str(excelrow), chr(65+i) + _
 str(excelrow)).value = lstOrder.cell(i,1)
And I wrote:

Re: I have a script which fills cells with ...

That does me, but for you I'd suggest adding a few more items to the Split(). After Z put in ",AA,AB,AC," etc until you have what you need. Then code your references in terms of numeric column and a row and let the function generate a meaningful address.

For example:
(iCount in this case is the number of rows in an array I was committing to the spreadsheet.)

[VBScript and Excel] Moving a sheet to the end of the list

Here's how to put the first sheet in a new spreadsheet at the end. This is a copy of a recent submission of mine at Automate Excel In Vbscript... ( Vbscript ) Note the comma after the space that is after the .Move. I'm specfying the "after" clause rather than the "before" and saying to move the sheet to after the last.

BTW, one of the best ways of finding out syntax is to record a macro and adapt the resulting code.

Wednesday, September 07, 2005

[VBScript] Sorting agonies

After hours spent trying this algorithm and that algorithm, trying Bubble sort (too slow for my massive datasets), QuickSort (which dies from lack of stack space), and ShellSort (which runs at least), I finally stumble over something completely different: Sorting Data by Using a Disconnected Recordset.

After you read the Microsoft blurb, check out what DevGuru has to say about .Sort: PROPERTY: Recordset::Sort.

It's good, but sometimes it seems I spend ages looking for something on the 'net, implementing what I find and then stumble over what I needed in the first place when looking for something else. Aarrrgghh!

To cap the whole episode off, I find I don't need a sort at all! Access will actually protect its indexes whether I "SELECT * FROM" or whether I "SELECT TOP 1 * FROM".

"I'm a teapot, I'm a teapot ..."

[VBScript/HTA] More Broggle

The next version of Broggle with the readonly textarea for the code.

Sunday, September 04, 2005

[SNOBOL4] Parsing text: OnLine Bible to text markup

As a SNOBOL4 script, this gets about as far as I got before getting sidetracked again into other languages. This is a filter converting the NOTES file out of my pre-OSX version of OnLine Bible into docScript, a markup language for my own version (written in REALbasic 3) of Will Duquette's brilliant Notebook.