Monday, December 19, 2005

[VBScript] Deriving user name from computer name

I found a brilliant bit of code for deriving the username from the computer name. It's found inside Matt Williams's "ManagePC v1.31" HTA. His description of the routine is as follows
This bit of code is "cheating" slightly in that all it's doing is getting the owner of the explorer.exe process. Seeing as explorer.exe only runs if a user is logged on it is a reliable (but sneaky) way of getting the logged-on user. It does, however, mean that even if a user is logged on locally or the account is a generic account, it will retrieve the correct values (WMI cannot do this).
-- Matthew Williams, ManagePC
Below is my routine, combining his code with some extra housekeeping. Of course, if no one is logged in, you get nothing. My own take on Matt's routine adds in a check to see if the computer is actually running, using ResolveIP() below:

[VBScript] Plugins

I had written a plugin architecture for one of my HTA applications. Now I discover that I can have plugins using almost any scripting language available. I found this bit of brilliance in a google search: I can now pass whatever information I like to and fro from application to plugin and back again. And if another scripting languages does something better than VBScript I can use it (provided it gives access to the volatile store).

Wednesday, December 07, 2005

[Working Again]

After a short stint on the support queue at iiNet (part-time), I'm now on contract at Department of Land Information. L1 and L2 support with a bit of scripting on the side. VBScript again, sadly.

Friday, November 04, 2005

[Pharmacy Software]

One of my clients has suggested I write pharmacy software. He has a home-grown Clipper app that does everything from Dispensing to Cash Register. I give him a hand with it from time to time. He reckons there's a market for a low-cost package which would fit the Western Australian situation better than the off-the-shelf ones now available.

So comes then the ever-present question: Closed Source, or Open Source.

No knowing a lot about how Open Source works as an income generator, I fear that there is the risk that my non-Open Source competitors may steal my ideas and woo my customers away because they have the resources to bring them (the ideas, not the customers) to the market faster than I can. Is that a valid concern?

Closed Source isn't without its problems either.

And then comes the other questions: programming language / IDE / RAD. I wonder if anyone's come up with a template for software projects in the style of Word / Excel / PowerPoint templates.

[Visual Studio 2005 Team System Beta 2]

I went to a Microsoft do yesterday and that's what they gave me (amongst other things.) Now to find a machine to install it on (only Linux, MacOSX and Win98 at home).

Eventually I want to start bidding on jobs at Get A Coder and Get a Freelancer.

Until then ... Khuda janta he.

Thursday, October 20, 2005

[VBScript] Shell and Heap Sorts

The final versions of the Shell sort and Heap sort classes. First the ShellSorter:
and then the HeapSorter


By the way, I'm unemployed again. Things might be a bit quiet around here for a while.

Saturday, October 15, 2005

[VBScript] sorting algorithms

Thanks to Dr Hans Werner Lang for his helpful comments on the sorting routines, as below:
Hi,
but there is no need to rewrite the outer loop, is it?
    for i=h to n-1
    ...

The inner loop, with the problem of the conditional And, could be written as
    do while j>=h
        if a(j-h)<=t then exit do
        ...
    loop

In my opinion, exit do should be avoided (when possible).

Regards
H.W. Lang
I've made the changes to the class as suggested but haven't posted them as yet.

[MetaCard] Starter Kit script size limit, Part 2

And if anyone was curious what happened to the MetaCard script size issue, Ken Ray said,
>I've been told, via the MetaCard list, that you have a technique for
>getting around the script size limit in MetaCard. If that's so, please
>can you tell me whence I can download the whitepaper about it.

Sorry to disappoint you, Bruce, but I don't. In fact, given that DreamCard is only $99, it seems counterproductive to attempt to get around the script size limits when you can pick up a full development environment very inexpensively.
and Geoff Canyon said
I don't recall that I wrote anything in particular. I did write an exporter for the documentation for earlier versions of Revolution, and they had a small section on dealing with the script limits in the starter kit. The basic point is to understand how to write tight code. You can insert scripts in front and back, and "start using" stacks, and use nested groups to your advantage. You can also store scripts in custom properties and use the "do" command on them.

If you ask on the mailing list, there are several people there who spent significant time working within the script limits who can probably help you with any specific issues. I bought a license early on so I don't have much practical experience.

Finally, if you're concerned about whether Rev is a good fit for what you want to do, ask on the list. People will tell you the truth. There are (many) things Rev is very good for, and (almost as many) things it isn't well suited for.
>I'm told that, sometime late last century, you wrote
>something about side-stepping the script size limit in
>the MetaCard unregistered version.
So the upshot of all this is: spend some money and stop complaining.

Thursday, October 13, 2005

[xbScript] Hooley Dooley! Move over VBScript, here comes xbScript

This is just amazing! "xbScript.dll enables xBase scripting (exactly like MS vbScript and JScript) in any MS ActiveScript compliant Host." Now I can help a friend, who has a large legacy Clipper app running in DOS under Windows, to integrate his software into the Windows environment. And he won't have to learn another language when he wants to tweak things. Hallelujah!!

[EOC] T minus 2 and counting

It's Thurday. I'm busily updating the documentation.

Friday 14 October is "The Last Day". (I wish it was THE last day, that is, the day Jesus returns.)

Of the 19 agencies I've written to, 4 have replied to say they're working on it. Looks like it's back to getting suited up and walking from agency to agency in the Perth CBD saying, "G'day, remember me? Yeah, I'm actually 3D and have feelings."

There's this disease one can get -- I get it often -- called PLOM disease: Poor Little Old Me.

Wednesday, October 12, 2005

[VBScript] Please, please, no more sorting!!

After so many tries, I had thought I was done with it. Well the virtual memory limit on my machine still stands so when the shellSort encountered an array of 1.5 million records, it failed. I could have gone ahead with getting the VM size increased but decided it was better to deal with the limitation as it stood. Who knows, the next bloke may not have much virtual memory either (though, I suppose, he's more likely to have lots more.)

I handed the job over to SORT.EXE and used the Exec method to call it. Like this:
The actual call to SortFile is what were talking about but the oSamples stuff needs some explaining. SuperContainer is a class based on the ADODB.Streams object. Interestingly I had a lot of trouble with the ReadFromFile method in ADODB.Stream. I think this had to do with it expecting Unicode but getting ASCII. When you hand a Unicode file over to SORT.EXE, it sorts it okay but changes it into ASCII. ReadFromFile tries to interpret the file as Unicode and you end up with a mess. Thus the GetFile()/Split/For Each thing in my ReadFile method.

The code for the sorting routine is:
I have a global in my stdFunctions.vbs called bDebugging. It's normally False but I can change it and get some useful feedback thereby.

The upshot of all this is that the sorting seems to be working ... but still not perfectly -- when I gave SORT.EXE a 63 Gigabyte file it didn't like it. But the likelihood of generating datasets that large is low.


[VBScript] read and write local and remote files

Check out a wonderful write up by Antonin Foller of PSTRUH Software on reading and writing files in VBScript. Note the very helpful stuff on Binary Files.

[General] Mergesort

This is a great site for algorithms, like Mergesort. A round of applause for the author, Prof. Dr. H. W. Lang.

It's mostly German language, but there are some English translations and the Java code is fairly human-language-neutral.

Tuesday, October 11, 2005

[VScript] At last, a working shell sort

Finally found a shell sort that works. The problems I had previously might have been had because of this: I converted that straight to VBScript and kept crashing because a[j-h] with a negative index would get evaluated. By using a do/loop and breaking the test up into two parts ... I got stuff to work. Here's the code. Usage is similar to that for heap sort.

[VBScript] Arrrghh!! Sorting out sorting ...

Just when I thought my problems were all over ... or at least the sorting ones ... I found that my machine didn't have enough virtual memory to handle the sort using ADODB (and I don't have the privilege level to do anything about it).

So I ported a heap sort to VBScript and ... so far ... everything look like it's going to work.

Here's the code
... and to use it, something like this ...

[VBScript] Sorting ... another way

I have tried and tried to get Shell sorts working but every algorithm I've tried ends up crashing out with negative indexes into the array.

So below is another way around the whole issue: create a RecordSet, populate it with fields, add data to it and use the RecordSet's own internal sorting routines.
And a trivial example of its use

Monday, October 10, 2005

[VBScript] Synthetic Includes in Traditional VBScript Files

Most of us are aware of the entry "Synthetic Includes in Traditional VBScript Files" in the Rube Goldberg Memorial Scripting Page.

Today I stumbled across how to embed test routines in the include file without causing these routines to be activated when the file is included.

My include file is called "StdFunctions.vbs". At the bottom of the file I've put
When StdFunctions.vbs is included by a script, ScriptFullName evaluates to the name of that script. It's only when StdFunctions.vbs is run by itself that ScriptFullName ends with "StdFunctions.vbs".

BaseName is one of my routines and look a bit like this:
[later that same day]

Read the manual, Bruce, read the manual: why use Basename with .ScriptFullName when you can just use .ScriptName?

[EOC] Other things it could mean

MeaningContributor
Elongated Orbital CrocodileBruce Axtens
Emu-Olive CrossDaniel Axtens
Extra Old CodgerRobert Glanville, Icon Recruitment

Friday, October 07, 2005

[EOC] End of Contract

I've got one more week and then I'm unemployed again.

I feel down. I wish there was something "cutting edge" I could do. Everything I can think of is diametrically opposed to the cutting edge, being either the blunt bit at the back of the knife or the even blunter bit on top of the chisel handle.

Who cares about MetaCard? Who cares about S*BOL but a few diehard fanatics (who are mostly older and greyer than me)? Who cares about Clipper or xHarbour but a few South Americans into retro memorabilia? As for VBScript, this is just one of thousands of websites and I'm a relative newcomer to a tool that's been around for very long time.

Eventually I'll have posted all my MoonRock BASIC, Fitted Software Tools Modula-2, Turbo Pascal 5 and Euphoria code. Whooptie do. Even if I finish my CCNA, learn Haskell, and write Kiwi CatTools equivalents ... who cares?

[MetaCard and Tcl] Blogs.mc

I got asked to describe the stack a little better. Here goes:
My blogs.mc stack has two text fields (fSource and fGenerated) and some buttons at the bottom (create_card, first, prev, next, last, render, preview, delete).

With some marked-up text in the fSource field, I click 'render' and the output of the Tcl script (HTML) is put into the fGenerated field (line 6 of the 'Render' script).

Then when I click on 'preview' the HTML in the fGenerated field gets dumped to a file and passed to Safari. The fGenerated field is modifiable so I can play with things to get what I want and then tweak the Tcl script appropriately afterwards.
About the same time I posted this to the MetaCard list:
On my blog, codeaholic.blogspot.com, I've posted an item about MetaCard (on OS X) using Tcl to more-or-less bypass the script size limit of the unregistered version of MetaCard.
Richard Gaskin wrote back, saying (in part):
since there is no MetaCard anymore anyway, and since Rev only offers a 30-day trial for the engine, I'm not sure how helpful the article will be.

At $99 for the low-end Rev license, is the pricing really so prohibitive?
Also Alejandro Tejada wrote
i do not see how this could get around the 10 lines limit, but Geoff Canyon wrote an extensive tutorial to manage longer scripts within the 10 lines limits.

This tutorial is still useful for developers that want to run longer scripts in their standalone applications.

I get it from Ken Ray's website within the RR v 1.1 docs (saved as a pdf file). i'm not sure if this tutorial is still available in any website.

You could ask directly to Geoff Canyon. Look for his website: inspiredlogic.com
I answered with
> i do not see how this could get around the
> 10 lines limit,

bad choice of words on my part. It doesn't so much get around it as it does acquiesce to the fact and try to use other tools to do what can't otherwise be done. Instead of using MetaCard's HTML mechanism or writin8g something in MetaTalk, I've farmed out the functionality to a Tcl script.

> but Geoff Canyon wrote an
> extensive tutorial to manage longer scripts
> within the 10 lines limits.

of this I was unaware. I have thought about doing something similar. What I usually end up doing however, when I need to hang more closely to MetaCard is to use AppleScript and 'do script' or 'evaluate' the things I need. I will nevertheless make enquiries now that I know better.

Wednesday, October 05, 2005

[General] Five year from now, Google will dwarf Microsoft

Networking Pipeline | Blog | Will Google Buy AOL?

[General] Neuronstorm website update

I'm supposed to be one of the admins for Neuronstorm and when I successfully extract the digit, I'm to implement the Neuronstorm OSI (operating system interface) in GTk for Windows (and possibly Mac OS X).

Daniel's a good developer and there's certainly a fair bit of interest at his school in an open-source version of Inspiration™.

Monday, October 03, 2005

[Clipper 5.3 / xHarbour] .DBF to .CH (Clipper Header)

The client had Clipper 5.3. I had xHarbour. The client had a database of constants. I turned them into a .ch (Clipper Header) file with this bit of code which compiled both under xHarbour and Clipper 5.

[VBScript] 99 bottles of beer - "class" version

Check out my 99 bottles of beer submission.

Look at the entries for your own favourite language. Some of them a dead boring. Submit an example that would show off the real power of the language.

If you're using a language that isn't on the board, submit a version of the song in that too.

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.

Monday, August 29, 2005

[Cygwin] using Cygwin to make .cmd files. Eeeww...

Actually the whole thing is a bizarre mix of Cygwin, Win2k CMD and Euphoria. When I get some more time I'll go into the issue a little more deeply. Here's the line that the title refers to:

Thursday, August 25, 2005

[VBScript/HTA] Broggle on Steroids

Big changes to Broggle.hta. No more #code/#endcode etc. Just #text, #code, #quot and #end. Now the HTA is more in line with the MetaCard and Tcl version at home on the iBook. I've also put in a preview button (which should probably be somewhere other than where it is right now) which puts the conversion results into a <DIV> at the bottom (thus the scrollbar at the side.)

Enjoy


[VBScript] Classes in VBScript, the definitive article?

Article Information
Article Title: 4GuysFromRolla.com - Using Classes within VBScript
Article Author: Mark Lidstone
Published Date: Thursday, September 23, 1999
Article URL: http://www.4GuysFromRolla.com/webtech/092399-1.shtml

[VBScript] Changes to existing stuff

Just a couple of changes. To the Container class I've added

    public sub Clear
        redim vat(0)
        itemCount = 0
    end sub


and I forgot to include the DQuote for PArray

Function DQuote( aText )
    DQuote = Chr( 34 ) & aText & Chr( 34 )
End Function

[VBScript] Arrays within arrays and debugging them

Array() can contain Array(). I do it lots. But there's the issue of debugging things and of knowing what's in an array full of embedded arrays.

So I wrote PArray().
Tcl has a function of the same name which does the same thing. And the output looks very like an Euphoria sequence (now there's a nice language) but you can change that if you want to.

I suppose the next thing to do is to write a compiler of PArray() decompilations that would allow me to write nested arrays out to a text file and then read them back in. One day.

[VBScript] My first class

A "Container" class, which I can add stuff to and then pull it all out nicely Join()-ed or else as a raw array. And the nice thing is I can have multiple collections rather than the single instance thing I had a couple of days ago. Some test code ran like this:

Monday, August 22, 2005

Template changes

Right, now we have black code instead of that faded out look. I think I'm finally starting to get the hang of CSS.

Good news about Modula-2 on Mac OS X

Hooray! Finally I get to leverage all my Modula-2 skill into the Mac OS X environment. Bring on the Objective Modula-2!! Objective Modula-2 and An Overview of Objective Modula-2 by the founder of the project, Benjamin Kowarsch. http://en.wikipedia.org/wiki/Objective_Modula-2 See also Objective Modula-2 – A Discussion and Working Paper

Friday, August 19, 2005

Leftovers after a meal of Bruce the Goose

I had a blog. It was called "Bruce the Goose" (aka Virtual Unknowns) and it listed programming languages and tried unsuccessfully to keep up with them all. The names of all that I found are in the links list on the left. If you find any dead links or want to suggest additions or changes, please contact me.

Thursday, August 18, 2005

Broggle - a blogging tool in an HTML application

Okay, now a quick shift from straight VBScript to VBScript inside an HTML application. It's to deal with formatting issues I have with Blogger. The solution is probably way simpler than this.

Saved as Broggle.hta and then double-click launched in Explorer.

Just put "#code" and "#endcode" around code and "#text" and "#endtext" around text, click on [Evaluate], then click on [Copy to Clipboard], and then paste into the blog.

How I used the CalculateState function

It's awful, and I'm glad I don't have to follow this any further. By the way, if you see any routines you would like to see elucidated, please let me know.

Toward a state table generator (VBScript)

This bit of code I used to create a two-state table for 5 variables. It would have been fairly easy to add more states -- by changing the if to a select case in 'state' and giving the for loops more things to loop through -- and to add more variables -- by specifying another loop and and another call to 'state'.

I won't be writing the generator ... the whole need for state tables disappeared in a meeting earlier today.

Wednesday, August 17, 2005

Once I wrote a global search and replace ...

... and now I find that a simple bit of unix command line replaces hundreds of lines of MoonRock BASIC.

$ for x in *.chk; do cat $x | sed -e s/Database=/Filename=/ > tmp; mv tmp $x; done

Get every file ending in .chk, pipe it through sed to change the relevant string, capture the result into a temporary file and then copy it over the original.

Found another use for Eval() in VBScript - state tables

Imagine trying to keep track of all possible combinations of four variables. Big if/then/else/end if, right? Not necessarily.

Tuesday, August 16, 2005

Cygwin again - Oh how I love the unix command line

$ getclip | gawk '{ print "convert.vbs /profile:" $1 ".cvt\ndaily.vbs /profile:" $1 ".dly\n" }' | putclip

It gets the word I put in the clipboard (selected and copied out of SciTe) and puts back on the clipboard the word as commands and filenames to be pasted back in. For example, I put

Marble_Bar

on the clipboard, reissue the command, and get

convert.vbs /profile:Marble_Bar.cvt
daily.vbs /profile:Marble_Bar.dly

HTA - HTML applications

I've played with this one from time to time and would like sometime to take it a bit further. It's a text editor written as an HTML application, good for doing CScript and WScript.

Simple VBScript Development Tool

It's also good an example of what you can do with HTML applications, especially the idea of being able to put a functional interactive GUI front end over VBScript (and JScript).

Monday, August 15, 2005

A printf for VBScript - derivative work

Uwe Keim, on the CodeProject site, has a "printf"-ish VBScript function. Here's my version (which I now realise is almost word for word the same as someone else's take on Uwe's original.) So ...

Sven Axelsson, on the above site, has a version of Uwe's original, called "FormatMessage-like formatting in VBScript" which looks almost exactly like that below (except he calls his "Fmt", rather than "Subst").
function Subst(str, args)
    dim res
    dim i
    res = str

    for i = 0 to UBound(args)
        res = Replace(res, "%" & CStr(i+1) & "%" , args(i) )
    next

    res = Replace(res, "\n", vbCrLf)
    res = Replace(res, "\t", vbTab)

    Subst = res
end function
And an example of use:
theSelector = "SELECT * FROM %1% WHERE [aKey] >= (DATESERIAL(%2%, %3%, %4% ) + TIMESERIAL( %5%, 0, 0 )) AND [aKey] <= (DATESERIAL(%2%, %3%, %4% ) + TIMESERIAL( %5%, 59, 59 ))"
theSelect = Subst( theSelector, Array( theTable, theYear, theMonth, theDay, theHour ) )