Showing posts with label kixtart. Show all posts
Showing posts with label kixtart. Show all posts

Wednesday, September 8, 2010

Script Tip: Determine the Script File Path

With BAT/CMD scripts you can simply prefix any path references with %~dps0 to get to things in the same location (folder/UNC) where the script itself resides.  So if you run..

start /wait %~dps0setup.exe /silent /norestart

It runs setup.exe from the same folder location. (that is not a typo, there should be NO space between the zero and the rest of the file path)

It's just as easy with KiXtart using the @scriptdir macro, but with VBscript it's not that simple.  But it's not difficult either…

scriptPath = Replace(Wscript.ScriptFullName, "\" & Wscript.ScriptName, "")

An example of running setup.exe in the same folder with VBscript might be…

filePath = scriptPath & "\setup.exe"
result = objShell.Run(filePath & " /silent /norestart", 7, True)

However, be careful to wrap paths in double-quotes if they contain spaces…

filePath = Chr(34) & scriptPath & "\setup.exe" & Chr(34)
result = objShell.Run(filePath & " /silent /norestart", 7, True)

Monday, April 5, 2010

Converting “YYYYMMDDHHMMSS” Dates

Sometimes you end up dealing with date values which are in the form of “YYYYMMDDHHMMSS:00000-GMT” (where “GMT” is a multiple of hours * 60 deviation from Greenwich Mean Time).  Formatting those into usable date values can be done several ways.  This is just one way.  And I threw in a somewhat not-so-obvious KiXtart version of this function for the hell of it.

VBScript version

Function mDate(strDate, format)
Dim tmp, retval
On Error Resume Next
Select Case Lcase(format)
Case "short":
tmp = Mid(strDate, 5, 2) & "/" & _
Mid(strDate, 7, 2) & "/" & _
Left(strDate,4)
retval = FormatDateTime(tmp, vbShortDate)
Case "datetime":
tmp = Mid(strDate, 5, 2) & "/" & _
Mid(strDate, 7, 2) & "/" & _
Left(strDate,4) & " " & _
Mid(strDate, 9, 2) & ":" & _
Mid(strDate, 11, 2) & ":" & _
Mid(strDate, 13, 2)
retval = FormatDateTime(tmp, vbShortDate) & " " & _
FormatDateTime(tmp, vbLongTime)
Case "long":
tmp = Mid(strDate, 5, 2) & "/" & _
Mid(strDate, 7, 2) & "/" & _
Left(strDate,4) & " " & _
Mid(strDate, 9, 2) & ":" & _
Mid(strDate, 11, 2) & ":" & _
Mid(strDate, 13, 2)
retval = FormatDateTime(tmp, vbLongDate)
End Select
mDate = retval
End Function


wscript.echo mDate("20100305132705.00000-520", "short")
wscript.echo mDate("20100305132705.00000-520", "long")
wscript.echo mDate("20100305132705.00000-520", "datetime")


KiXtart Version



Function FormatDateTime($v, $f)
Dim $sc, $result
$sc = CreateObject("ScriptControl")
$sc.Language = "vbscript"
$result = $sc.Eval('FormatDateTime("'+$v+'",'+$f+')')
$sc = 0
$FormatDateTime = $result
EndFunction

Function mDate($strDate, $format)
Dim $tmp, $retval
Select
Case $format = "short"
$tmp = Substr($strDate, 5, 2) + "/" +
Substr($strDate, 7, 2) + "/" +
Left($strDate,4)
$retval = $tmp
Case Lcase($format) = "datetime"
$tmp = Substr($strDate, 5, 2) + "/" +
Substr($strDate, 7, 2) + "/" +
Left($strDate,4) + " " +
Substr($strDate, 9, 2) + ":" +
Substr($strDate, 11, 2) + ":" +
Substr($strDate, 13, 2)
$retval = $tmp
Case Lcase($format) = "long"
$tmp = Substr($strDate, 5, 2) + "/" +
Substr($strDate, 7, 2) + "/" +
Left($strDate,4)
$tmp = FormatDateTime($tmp, "vbLongDate")
$retval = $tmp
EndSelect
$mDate = $retval
EndFunction


? mDate("20100305132705.00000-520", "short")
? mDate("20100305132705.00000-520", "long")
? mDate("20100305132705.00000-520", "datetime")


Yes, the KiXtart version is somewhat “cheating” but who cares.  It works, and it saves me a little bit of coding.  The performance overhead delta is near-zero, unless you’re running on 1990’s hardware.

Tuesday, March 2, 2010

Now vs Now: VBScript and KiXtart

Date values are a very common aspect to script writing and most any programming situation in general.  How dates are stored, presented and manipulated varies widely from one programming language to another.

Let’s look at the “Now” function included with Windows Scripting Host’s VBScript.  This function returns the current date and time in “mM/dD/YYYY hH:MM:SS XM” format.

In case you’re wondering what the hell “mM” and “hH” imply: they imply zero-trim numbers.  In other words 8:01:42 AM is not stored as 08:01:42 AM. The leading zero is omitted.  Same for month (“mM”), and day (“dD”) as well.

But KiXtart, one of my all-time favorite scripting languages, handles date values quite differently.  At first it may seem almost identical, but as you pick things apart you start to see the deltas.

(kixtart)
? @date+" "+@time
>> 2010/03/02 08:20:01

(vbscript)
Wscript.echo Now
>> 3/2/2010 8:20:01 AM


When you compare the output of each result above, not only are the order of YYYY/MM/DD flipped from M/D/YYYY, but the zero-trim is not used with KiXtart.  Is this “bad” or “wrong”?  No.  Just different.  There are times when this is actually a very handy benefit to have as the default.  But also notice that the time stamp is formatted differently.  And the AM/PM suffix is not shown.


So, how can we make KiXtart do it the way VBScript does it?  This is assuming you need to make it do that, of course, which you may not.  But this is for demonstration purposes, so cut me some slack - if you will.


Below are two examples for producing a VBScript formatted “Now” result.  The first one uses a rudimentary date->string parsing technique.  The second does a cop-out and simply knocks on the door of the ScriptControl COM interface to make VBScript do the work and hand back a result.  The performance overhead is about the same at this scalar load level.  If you start piling in a lot more, the results can shift the balance of performance in either direction, depending upon the nature of what your doing (math, string, date, or object management tasks).


------------------------------------------------
Break ON

Function Now1()
$today = ""+@monthno+"/"+@mdayno+"/"+@year
$arrTime = Split(@time, ":")
$hour = $arrTime[0]
$min = $arrTime[1]
$sec = $arrTime[2]
If Int($hour) < 12
$sfx = "AM"
Else
$sfx = "PM"
EndIf
$Now1 = $today+" "+Int($hour)+":"+$min+":"+$sec+" "+$sfx
EndFunction

Function Now2()
Dim $sc, $result
$sc = CreateObject("ScriptControl")
$sc.Language = "vbscript"
$result = $sc.Eval('Now()')
$sc = 0
$Now2 = $result
EndFunction

? "Kix: "+Now1()
? "VBs: "+Now2()


The results should be identical.  Could I/you refactor the Now1() function to nest statements and further compact the code?  Sure.  Does it buy any performance gains? Not really.



Consider this variation…



Function Now1()
$today = ""+@monthno+"/"+@mdayno+"/"+@year
$arrTime = Split(@time, ":")
If Int($arrTime[0]) < 12
$Now1 = $today+" "+Int($arrTime[0])+":"+$arrTime[1]+":"+
$arrTime[2]+" AM”
Else
$Now1 = $today+" "+Int($arrTime[0])+":"+$arrTime[1]+":"+
$arrTime[2]+" PM”
EndIf
EndFunction


More compact for sure.  But there’s a hidden, even if trivial price: The repeated use of an array index request.  There are other ways to compact/refactor this of course, but for such few lines of code the pay-offs are difficult to justify beyond elegant coding form (aesthetics).  Oh well, blah blah blah.  What do I know anyway.  I just finished a huge “breakfast-for-dinner” and was then told my car repairs would cost way too much, so I’m blabbering to let off steam.  I hope you enjoyed this.

Friday, December 25, 2009

Convert INI to XML with KiXtart

Sometimes you may want/need to read a standard INI data file and output it to an XML format.  There are several ways to do this, but here is just one.  You’ll need KiXtart 4.61 in order to use the Replace() function. Enjoy (and Merry Christmas!)

KiXtart Code

Break ON
; requires KiXtart 4.61 or later!!!
If @kix <= "4.60"
? "this script requires 4.61 or later!"
Exit
EndIf

$strFileName = "s:\scripts\test.ini"

$quote = Chr(34)
$tab = Chr(9)

Dim $linecount, $fHandle, $strLine, $outer, $keyset, $subkeyformat
Dim $name, $value

$subkeyFormat = 1
$fHandle = FreeFileHandle()
$outer = ""

If Open($fHandle, $strFileName) = 0
$strLine = ReadLine($fHandle)
While @error = 0
Select
Case Left($strLine,1) = "["
$outer = Replace(Replace($strLine, "]", ""), "[", "")
? "<$outer>"
Case InStr($strLine, "=") <> 0
$keyset = Split($strLine, "=")
$name = $keyset[0]
$value = $keyset[1]
If $subkeyFormat == 1
? "$tab"
Else
? "$tab<$name>$value</$NAME>"
EndIf
Case 1
If $outer <> ""
? "</$OUTER>"
$outer = ""
EndIf
EndSelect
$strLine = ReadLine($fHandle)
Loop
$=Close($fHandle)
EndIf

Scraping Web Pages with VBScript and KiXtart

Here’s a quick example of how to scrape HREF and IMG strings from a web page using VBScript and KiXtart with the InternetExplorer.Application COM object.  Thanks to Paul Sadowski for the basis of the VBScript example (with only very slight modifications).

VBScript Code

url = "http://www.textpad.com"

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate url

Wscript.Echo "DOCUMENT HYPERLINKS" & vbCRLF
Do Until ie.ReadyState = 4
Wscript.Sleep 2
Loop
For each link in ie.Document.Links
Wscript.Echo link, link.InnerText
Next

Wscript.Echo "------------------------------------"
Wscript.Echo "DOCUMENT IMAGE TAGS" & vbCRLF

For each img in ie.Document.Images
Wscript.Echo img.Src
Next

ie.Quit


KiXtart Code



break ON

$url = "http://www.textpad.com"

$ie = CreateObject("InternetExplorer.Application")
$ie.Navigate($url)
? "DOCUMENT HYPERLINKS"

While $ie.ReadyState <> 4
Sleep 2
Loop

For each $link in $ie.Document.Links
? $link+"="+$link.InnerText
Next

? "DOCUMENT IMAGE TAGS"

For each $pix in $ie.Document.Images
? $pix.Src
Next

$ie.Quit()

Thursday, November 19, 2009

KiXtart: Using FSO File.ReadAll()

Another example of making use of one scripting language or API from another.  In this case, I’m calling on the FileSystemObject API to invoke the ReadAll() function on a file from a KiXtart script.  Just to show that there are all sorts of things you can do like this…

function ReadFile($filepath)
$fso = CreateObject("Scripting.FileSystemObject")
if exist($filepath)
$file = $fso.OpenTextFile($filepath)
$text = $file.ReadAll()
$file.Close()
$file = 0
else
? "error: file not found"
endif
$readfile = $text
endfunction

; example...

? readfile("c:\myfile.txt")

Sunday, November 1, 2009

Am I a VMWare Guest Machine or Not?

VBScript Version
Function IsVmWareClient()
Dim objWMIService, colBIOS, objBIOS, retval
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colBIOS = objWMIService.ExecQuery("Select SerialNumber from Win32_BIOS")
For each objBIOS in colBIOS
If Left(objBIOS.SerialNumber, 6) = "VMware" Then
retval = True
Exit For
End If
Next
IsVmWareClient = retval
End Function

' test

If IsVmWareClient() Then
wscript.echo "yes - this is a vmware guest machine"
Else
wscript.echo "not a vmware guest machine"
End If

KiXtart Version

Function IsVmWareClient()
Dim $wmiService, $colBIOS, $objBIOS, $retval
$wmiService = GetObject("winmgmts:\\.\root\CIMV2")
$colBIOS = $wmiService.ExecQuery("select SerialNumber from Win32_BIOS")
For Each $objBIOS in $colBIOS
If Left($objBIOS.SerialNumber, 6) = "VMware"
$retval = 1
EndIf
Next
$IsVmWareClient = $retval
EndFunction

; test

If IsVmWareClient()
? "yes - this is a vmware guest machine"
Else
? "not a vmware guest machine"
EndIf

Saturday, July 11, 2009

KiXtart: Customize OEM Support Information


? "[OEMSupportTag].....: Configuring OEM Support applet..."
Dim $oeminfo, $oemlogo, $oemsupp, $x, $regkey
Dim $logfile, $oemlogosrc, $oemsuppsrc
Dim $wmi, $wmi_compsys, $wmi_comp, $model, $desc, $asset
$weblink = "https://intranet.company.com/helpdesk"

$regkey = "HKLM\System\CurrentControlSet\Control\Windows"
$value = ReadValue($regkey,"SystemDirectory")
$windir = ExpandEnvironmentVars($value)

If $windir <> ""
$oeminfo = $windir+"\oeminfo.ini"
$oemlogo = $windir+"\oemlogo.bmp"
$oemsupp = $windir+"\web\support.htm"
$logfile = $windir+"\custom_oem.ini"
$oemlogosrc = @lserver+"\netlogon\oemlogo.bmp"
$oemsuppsrc = @lserver+"\netlogon\support.htm"

If Exist( $oeminfo ) = 1
? "[OEMSupportTag].....: removing existing oeminfo.ini file..."
Del( $oeminfo )
Else
? "[OEMSupportTag].....: no existing oeminfo.ini file found."
EndIf

? "[OEMSupportTag].....: attempting to create new oeminfo.ini file..."
If Open(2, $oeminfo, 5) = 0
? "[OEMSupportTag].....: file created successfully, updating contents..."
$wmi = "WINMGMTS:{IMPERSONATIONLEVEL=IMPERSONATE}!//"+@wksta
$wmi_compsys = "SELECT * FROM Win32_ComputerSystemProduct"
$wmi_comp = GetObject($wmi).ExecQuery($wmi_compsys)
For Each $objsys In $wmi_comp
$model = $objsys.Name
$desc = $objsys.Description
$asset = $objsys.IdentifyingNumber
Next
$=WriteLine(2,"[General]" + @crlf)
$=WriteLine(2,"Manufacturer=MY COMPANY, INC." + @crlf)
$=WriteLine(2,"Model="+$model + @crlf)
$=WriteLine(2,"SupportURL=$weblink" + @crlf)
$=WriteLine(2,"LocalFile=%windir%\web\support.htm" + @crlf + @crlf)
$=WriteLine(2,"[OEMSpecific]" + @crlf)
$=WriteLine(2,"SubModel=" + @crlf)
$=WriteLine(2,"SerialNo=" + @crlf)
$=WriteLine(2,"OEM1="+$asset + @crlf)
$=WriteLine(2,"OEM2=" + @crlf + @crlf)
$=WriteLine(2,"[ICW]" + @crlf)
$=WriteLine(2,"Product=Computer Asset" + @crlf + @crlf)
$=WriteLine(2,"[Support Information]" + @crlf)
$=WriteLine(2,"Line1=COMPUTER HELP DESK" + @crlf)
$=WriteLine(2,"Line2= " + @crlf)
$=WriteLine(2,"Line3=Contact Technical Support by web or phone:" + @crlf)
$=WriteLine(2,"Line4= " + @crlf)
$=WriteLine(2,"Line5= $weblink" + @crlf)
$=WriteLine(2,"Line6= 1-800-555-1212" + @crlf)
$=WriteLine(2,"Line7= " + @crlf)
$=WriteLine(2,"Line8=After hours/weekends/holidays..." + @crlf)
$=WriteLine(2,"Line9=support options may be limited." + @crlf)
$=WriteLine(2,"Line10=------------------------------" + @crlf)
$=WriteLine(2,"Line11=Computer Name: " + @wksta + @crlf)
If Trim($asset) <> ""
$=WriteLine(2,"Line12=Asset Tag: " + Trim($asset) + @crlf)
$=WriteLine(2,"Line13=IPAddress: " + @ipaddress0 + @crlf)
Else
$=WriteLine(2,"Line12=IPAddress: " + @ipaddress0 + @crlf)
EndIf
Close(2)
? "[OEMSupportTag].....: oeminfo.ini file has been successfully updated!"
Else
? "[OEMSupportTag].....: Error: failed to create new oeminfo.ini file!"
EndIf

? "[OEMSupportTag].....: oeminfo logo graphic updated already?..."
If Exist( $logfile ) = 0
? "[OEMSupportTag].....: attempting to create new oeminfo update log file..."
If Exist( $oemlogosrc ) = 1
? "[OEMSupportTag].....: downloading oeminfo logo graphic file..."
Copy $oemlogosrc $oemlogo
If Open(3, $logfile, 5) = 0
WriteLine(3,"[General]"+@crlf)
WriteLine(3,"DateAdded="+@date+@crlf)
Close(3)
? "[OEMSupportTag].....: oeminfo log updated."
EndIf
Else
? "[OEMSupportTag].....: oeminfo graphic file missing: "+$oemlogosrc
EndIf
Else
? "[OEMSupportTag].....: "+$logfile+" previously recorded."
EndIf
Else
? "[OEMSupportTag].....: Error: windir variable not set, aborting process."
EndIf

KiXtart: Get Asset Number

WMI query for asset number (e.g. Dell Asset, HP Serial number, etc.)


Function AssetNumber()
Dim $objWmi, $objWmiCS, $obj, $retval, $pc
$pc = @wksta
$objWmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$pc\root\cimv2")
$objWmiCS = $objWmi.ExecQuery("select * from Win32_ComputerSystemProduct")
For Each $obj in $objWmiCS
$retval = $obj.IdentifyingNumber
Next
$AssetNumber = Trim($retval)
EndFunction

KiXtart: Open Browser / Display Web Page

Great for login banners and bulletins...


Function OpenWebPage($url, $show, Optional $height, $width, $fixed)
$ie = CreateObject("InternetExplorer.Application")
If $ie <> 0 and @ERROR = 0
$ie.Navigate($url)
If $show = 1
If $height > 0
$ie.Height = $height
EndIf
If $width > 0
$ie.Width = $width
EndIf
If $fixed = 1
$ie.Resizable = 0
$ie.StatusBar = 0
$ie.Toolbar = 0
EndIf
$ie.Visible = 1
Sleep 1
Else
? "(openwebpage): accessing document in silent-mode"
Sleep 1
$ie.Quit
$ie = 0
EndIf
Else
? "(openwebpage): error / unable to launch IE application object"
EndIf
EndFunction

Friday, July 10, 2009

KiXtart: Enumerate HOSTS file Entries


Break ON

$systemRoot = ExpandEnvironmentVars("%systemroot%")
$hostsFile = $systemRoot+"\system32\drivers\etc\hosts"
$fileHandle = FreeFileHandle()
$entries = 0

If Exist($hostsFile)
? "info: hosts file found at "+$hostsFile
If Open($fileHandle, $hostsFile, 1) = 0
? "info: reading file..."
$line = ReadLine($fileHandle)
While @ERROR = 0
If Left($line, 1) <> "#"
; ignore lines beginning with # as they are comments
? "line --> $line"
$entries = $entries + 1
EndIf
$line = ReadLine($fileHandle)
Loop
$=Close($fileHandle)
? "info: $entries entries found"
Else
? "fail: unable to open hosts file!"
EndIf
Else
? "fail: hosts file cannot be found!"
EndIf

Tuesday, July 7, 2009

KiXtart: Update Desktop Shortcuts


Break ON

$oldPath = "\\server1\shareName1"
$newPath = "\\server2\shareName2"

$shell = CreateObject("WScript.Shell")
$DesktopPath = ExpandEnvironmentVars("%userprofile%")+"\Desktop"

$FileName = Dir("$DesktopPath\*.lnk")
While $FileName <> "" And @error = 0
? $FileName
$link = $shell.CreateShortcut("$DesktopPath\$FileName")
If Ucase($link.TargetPath) = Ucase($oldPath)
$link.TargetPath = $newPath
$link.Save
EndIf
$FileName = Dir()
Loop

KiXtart: Enumerate Access Database Tables with ADOX


$dbfile = "\\servername\share\folder\database.mdb"

Function ListTablesADOX($db)
Dim $Conn, $strConn, $Catalog, $Table, $Column
$strConn = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=$db"

? "Database: $db @CRLF"

$Conn = CreateObject("ADODB.Connection")
$Catalog = CreateObject("ADOX.Catalog")
$Table = CreateObject("ADOX.Table")
$Column = CreateObject("ADOX.Column")

$Conn.Open($strConn)
$Catalog.ActiveConnection = $Conn

For Each $Table In $Catalog.Tables
? "Table: " + $Table.Name
For Each $Column In $Table.Columns
? Chr(9) + "Column: " + $Column.Name
Next
Next
$Conn.Close
EndFunction

$=ListTablesADOX($dbfile)

KiXtart: Enumerate Local Shares


Break ON

$strComputer = "."
$tab = Chr(9)

$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$strComputer\root\cimv2")
$colShares = $objWMIService.ExecQuery("Select * from Win32_Share")
$numshares = $colShares.Count

? "shares found: $numshares"

For each $objShare in $colShares
$n = $objShare.Name
If Right($n,1) = "$$"
$shareType = "HIDDEN"
Else
$shareType = "OPEN"
EndIf
? $objShare.Name + $tab + $shareType + $tab +
$objShare.Path + $tab + $objShare.Caption + $tab +
$objShare.Type
Next

Sunday, July 5, 2009

VBscript Outsourcing to KiXtart

If you register the Kixtart.dll component you can invoke the "KiXtart.Application" interface to handle some basic inventory chores. This does not work from PowerShell v2 by the way.


On Error Resume Next
Set objKiX = CreateObject("KiXtart.Application")
If err.Number = 0 Then
wscript.echo "Processor: " & vbTab & Trim(objKiX.CPU)
wscript.echo "UserName: " & vbTab & objKiX.UserId
wscript.echo "Domain: " & vbTab & objKiX.LDomain
wscript.echo "MAC id: " & vbTab & objKiX.Address
wscript.echo "Privilege: " & vbTab & objKiX.Priv
wscript.echo "Password Age: " & vbTab & objKiX.PwAge
wscript.echo "ProductType: " & vbTab & objKiX.ProductType
Set objKiX = Nothing
Else
wscript.echo "kixtart.dll has not been registered"
End If

KixTart: ScriptControl JScript to Outsource Expression

Use Jscript object to calculate Cosine of a value...

Function Cosine($numValue)
$sc = CreateObject("ScriptControl")
$sc.Language = "jscript"
$result = $sc.Eval("Math.cos("+$numValue+")")
$sc = 0
$Cosine = $result
EndFunction

Test examples...

$testvalue = 45
$test = Cosine($testvalue)
? "cosine of $testvalue is: "+$test

KiXtart: ScriptControl VBScript to Outsource Expressions


Function DaysOld($date)
Dim $sc, $result
$sc = CreateObject("ScriptControl")
$sc.Language = "vbscript"
$result = $sc.Eval("DateDiff("+Chr(34)+"d"+Chr(34)+", "+Chr(34)+$date+Chr(34)+", Now)")
$sc = 0
$DaysOld = $result
EndFunction

Function FormatDateTime($strDate, $format)
Dim $sc, $result
$sc = CreateObject("ScriptControl")
$sc.Language = "vbscript"
$result = $sc.Eval("FormatDateTime("+Chr(34)+$strDate+Chr(34)+","+$format+")")
$sc = 0
$FormatDateTime = $result
EndFunction


Test examples:

$testvalue = '2009/01/03 12:34:56'

$test1 = FormatDateTime($testvalue, 'vbShortDate')
$test2 = FormatDateTime($testvalue, 'vbLongDate')
$test3 = FormatDateTime($testvalue, 'vbLongTime')

? "shortdate: $test1"
? "longdate: $test2"
? "longtime: $test3"

$test4 = DaysOld($testvalue)
? "days old: $test4"

KiXtart: Array List Sorting


Function ArrayList()
; this code creates and populates an ArrayList
? "Example: ArrayList object"
$myArrayList = CreateObject("System.Collections.ArrayList")
$=$myArrayList.Add("Dog")
$=$myArrayList.Add("Chicken")
$=$myArrayList.Add("Rooster")
$=$myArrayList.Add("Hen")

; Now, to add an element and sort the ArrayList, all we need to do is:

; [1] add the new element to the ArrayList
$=$myArrayList.Add("Pig")
; [2] sort the ArrayList
$=$myArrayList.Sort()
For each $item in $myArrayList
? $item
Next
EndFunction

$x = ArrayList()