Past (20 years or so) and present code. A variety of languages and platforms. Some gems. More gravel. Some useful stuff and some examples of how not to do it.
Wednesday, January 11, 2006
[VBScript] A CLI framework
Here's a simple framework for building your own CLI (Command Language Interface)
Keywords at this point are: quit, exit, bye, eval, echo, set and run. Below is a sample session.
Now my own version adds a little to this framework by including a .vbs file full of extra symbols, procedures and classes. I've reproduced it below just so that you can see how to do a synthetic include in VBScript. Interestingly, the technique also works in HTAs.
Enjoy.
[VBScript] CSV to variables using Execute
Nico wrote, on microsoft.public.scripting.vbscript:
Data, stored in DEMO.CSV Then the code which does nothing other than read the file, store the data in variables for each line of data, and for effect, echoes the first and last names And here's the results of the run, taken from SciTE's output window A possible extra step would be to read the header line, strips the spaces, build the "Dim" statements and execute them as well. Or maybe, create an instance of "Scripting.Dictionary" and use that. Or ... well, there must be more than two ways to do it, even in VBScript!
I need ASP to read the CSV file to read lines 2 on-wards and display it back to the user for verification. Each line has aprx 8 "," that control user properties.I wrote a response but thought a fuller treatment was in order, thus the following:
I am looking for each line to be displayed back to the user without the "," so they can verify and write to an access db.
All i am looking for is a simple way to read the text display to the user for acceptance before writing it back to the db.
Data, stored in DEMO.CSV Then the code which does nothing other than read the file, store the data in variables for each line of data, and for effect, echoes the first and last names And here's the results of the run, taken from SciTE's output window A possible extra step would be to read the header line, strips the spaces, build the "Dim" statements and execute them as well. Or maybe, create an instance of "Scripting.Dictionary" and use that. Or ... well, there must be more than two ways to do it, even in VBScript!
Labels:
CSV,
data-driven code,
VBScript
Tuesday, January 10, 2006
[VBScript] Threads ... thin ones
The following is an attempt at threads in VBScript. The code owes a lot to Greg Chapman of MouseTrax Computing Solutions. There are two scripts, the first calling the second (in many instances). The means for communicating between the two is via the Volatile environment. When the script runs, Outlook flickers (don't know why).
There are comments, but the basic idea is to keep a watch over how many instances of cscript.exe there are running and while there's only so many, add more. Use the Volatile environment for semaphores and make sure there's enough delay in there to get stuff to and from Volatile (which is actually in Registry and not blazingly fast).
First the controller. Then the controlled. There are quite a few extra useful routines in all that code, including an AADD(), and assorted WMI related routines.
I'm in the process of putting the thread functionality inside a Class so that I can change how things are done without causing drastic rewrites of the original VBScripts. I'm not entirely pleased with the Volatile environment and may end up playing with something else that can be used as a shared storage area between many programs ... like subdirectory structures.
There are comments, but the basic idea is to keep a watch over how many instances of cscript.exe there are running and while there's only so many, add more. Use the Volatile environment for semaphores and make sure there's enough delay in there to get stuff to and from Volatile (which is actually in Registry and not blazingly fast).
First the controller. Then the controlled. There are quite a few extra useful routines in all that code, including an AADD(), and assorted WMI related routines.
I'm in the process of putting the thread functionality inside a Class so that I can change how things are done without causing drastic rewrites of the original VBScripts. I'm not entirely pleased with the Volatile environment and may end up playing with something else that can be used as a shared storage area between many programs ... like subdirectory structures.
Labels:
ActiveDirectory,
GetDomainComputers,
semaphores,
threads,
VBScript,
winmgmts,
WMI
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).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:
-- Matthew Williams, ManagePC
[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).
Labels:
command language interpreter,
VBScript,
VOLATILE
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.
Labels:
Department Land Information,
DLI,
iiNet
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.
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.
Labels:
Clipper,
Pharmacy Software
[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.
Eventually I want to start bidding on jobs at Get A Coder and Get a Freelancer.
Until then ... Khuda janta he.
Labels:
Get A Coder,
Get A Freelancer,
Visual Studio 2005
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.
By the way, I'm unemployed again. Things might be a bit quiet around here for a while.
Labels:
heap sort,
shell sort,
sorting,
VBScript
Saturday, October 15, 2005
[VBScript] sorting algorithms
Thanks to Dr Hans Werner Lang for his helpful comments on the sorting routines, as below:
Hi,I've made the changes to the class as suggested but haven't posted them as yet.
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
Labels:
sorting
[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 forand Geoff Canyon said
>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.
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.So the upshot of all this is: spend some money and stop complaining.
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.
Labels:
MetaCard,
Revolution
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!!
Labels:
ActiveScript,
VBScript,
xBase,
xbScript,
xharbour
[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.
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.
Labels:
end of contract,
EOC,
PLOM
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.
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.
Labels:
binary files,
reading and writing files,
VBScript
[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.
Labels:
shell sort,
sorting,
VBScript
[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 ...
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
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
Labels:
ADODB.RecordSet,
sorting,
VBScript,
XML
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?
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?
Labels:
Synthetic Include,
VBScript
Subscribe to:
Posts (Atom)