[ Home | Syllabus | Course Notes | Assignments | Search]
<?xml version="1.0"?> <component> <registration description="FileFinder" progid="FileFinder.WSC" version="1.00" classid="{82e84cc0-23f8-11d3-88e4-00105a68bf5d}"> </registration> <public> <property name="FileSpec"> <get/> <put/> </property> <property name="Date"> <get/> <put/> </property> <method name="Search"> </method> <event name="FileFound"> <parameter name="fileName" /> </event> </public> <script language="VBScript"> <![CDATA[ dim FileSpec FileSpec = "c:\" dim Date Date = Now function get_FileSpec() get_FileSpec = FileSpec end function function put_FileSpec(newValue) set fso = CreateObject("Scripting.FileSystemObject") if fso.FolderExists(newValue) then FileSpec = newValue end if end function function get_Date() get_Date = Date end function function put_Date(newValue) if IsDate(newValue) then Date = newValue end if end function function Search() set fso = CreateObject("Scripting.FileSystemObject") set fld = fso.GetFolder(FileSpec) set files = fld.Files set dic = CreateObject("Scripting.Dictionary") for each f in files d = DateDiff("d", f.DateLastModified, Date) if d = 0 then FireEvent "FileFound", f.Name dic.add f.Name, f.Name end if next set Search = dic end function ]]> </script> </component>
' FFX.vbs ' Demonstrates the use of the FileFinder WSC component ' Usage: FFX [path] [date] ' --------------------------------------------------------- Dim oFF, str Set oFF = WScript.CreateObject("FileFinder.WSC", "FileFinder_") if WScript.Arguments.Count > 0 then if WScript.Arguments.Item(0) = "/?" then WScript.Echo "Usage: FF [path] [date]" WScript.Quit end if end if if WScript.Arguments.Count = 2 then oFF.FileSpec = WScript.Arguments.Item(0) oFF.Date = WScript.Arguments.Item(1) else if WScript.Arguments.Count = 1 then oFF.FileSpec = WScript.Arguments.Item(0) oFF.Date = Now else oFF.FileSpec = InputBox("Enter the folder name:",, "c:\") if oFF.FileSpec <> "" then oFF.Date = InputBox("Enter the date as a string:",, Date) else WScript.Echo("You must provide the name of an existing folder.") WScript.Quit end if end if end if oFF.Search() if str = "" then str = "No file found." end if WScript.Echo str ' ----------------------------------------------------- ' Event handler ' ----------------------------------------------------- sub FileFinder_FileFound(fileName) str = str & fileName & vbCrLf end sub
You could put a COM wrapper around any C++ dialog (like ex25b.auto)
But learning C++ just to create a way to get input is a complex way
Property | Description |
Document | reference to the DHTML object |
Methods | |
Create | Creates dialog from HTML page (does not display) |
Show | Displays the dialog |
Move | Moves position of dialog |
GetItemText/SetItemText | read/wirte innerHTML property of tag |
GetItemValue/SetItemValue | Read/Write value property of tag |
GetItemSrc/SetItemSrc | Read/Write Source property of tag |
GetItemHref/SetItemHref | Read/Write href property of tag |
New Invoice # | on date: |
The Company Address and number ZIP Code City Country |
To: |
Quantity |
Description |
Price |
Total |
USD UKP |
Thank you!
Visit us at: Company Web Site
Here is the HTML for the above
<html><
td width="19%" align="right" height="20"><span tip="Total amount payable" id="payable"></span></td> //// this is the "payable" field
' Invoice.vbs ' Demonstrates HTML-based dialog boxes in VBScript ' ------------------------------------------------ Dim dlg Set dlg = CreateObject("WshKit.DialogBox") If dlg.Create("path://invoice.htm") = True Then dlg.SetItemSrc "companylogo", "expoware.gif" dlg.SetItemText "companyname", "Expoware Soft" dlg.SetItemText "companyaddress", "One Expoware Way, 1" dlg.SetItemText "companycity", "00000 Roundmond" dlg.SetItemText "companycountry", "Rome, Italy" dlg.SetItemText "companyphone", "+39 06 12345678" dlg.SetItemValue "invoiceID", "7" dlg.SetItemValue "invoicedate", Now dlg.SetItemValue "quantity", 1 dlg.SetItemValue "description", "Royalties for WSH Book" dlg.SetItemValue "price", "<lots of money>" dlg.SetItemText "total", "0" dlg.SetItemText "lire", "<i>No lire</i>" dlg.SetItemText "companysite", "our web site." dlg.SetItemHref "companysite", "http://www.expoware.com" dlg.SetItemValue "recipient", "Wrox Press" & vbCrLf & _ "Arden House" & vbCrLf & _ "1102 Warwick Road, Acock's Green" & _ vbCrLf & "Birmingham, UK. B27 6BH" dlg.Move 0, 0, 700, 450 If dlg.Show("center") = True Then MsgBox "You sent an invoice to:" & vbCrLf & vbCrLf & _ dlg.GetItemValue("recipient") & vbCrLf & vbCrLf & _ "for an amount payable of " & _ dlg.GetItemText("lire"),, "New Invoice" End If Else MsgBox "Template not found.", 64, "New Invoice" End If
Description: invoice entry program which uses a data base, word document, and e-mail with input coming form a HTML dialog box (DESCRIBED earlier).
(Because ACCESS is not installed on my machine, I'll comment out the data base parts)
' NewInvoice.vbs ' Creates, prints and sends invoices through e-mail ' -------------------------------------------------------------- Option Explicit ' Constants Const adUseClient = 3 Const adLockOptimistic = 3 Const ssfDrives = &H11 ' Reference to My Computer Const myInvoiceFolder = "C:\Invoices\" Const myInvoiceDlgTemplate = "invoice.htm" Const myInvoiceDocTemplate = "InvoiceTemplate.dot" ' -------------------------------------------------------------- ' Gets the number for the new invoice ' -------------------------------------------------------------- Dim rs, numNewInvoice Set rs = CreateObject("ADODB.Recordset") rs.CursorLocation = adUseClient numNewInvoice = 1 rs.Open "select InvoiceNo from Invoices order by InvoiceNo desc", "Invoices" If rs.RecordCount > 0 Then numNewInvoice = rs("InvoiceNo") + 1 End If rs.Close ' -------------------------------------------------------------- ' Collects all the information needed to prepare the invoice ' -------------------------------------------------------------- Dim dlg Set dlg = CreateObject("WshKit.DialogBox") If Not dlg.Create("path://" & myInvoiceDlgTemplate) Then MsgBox "Unable to locate the [" & myInvoiceDlgTemplate & "] template" WScript.Quit End If Dim sMonth, sDay, sYear, sDate sMonth = MonthName(Month(Date)) sDay = Day(Date) sYear = Year(Date) sDate = sMonth & " " & sDay & ", " & sYear ' Initialize the fields of the dialog dlg.SetItemSrc "companylogo", "expoware.gif" dlg.SetItemText "companyname", "Expoware Soft" dlg.SetItemText "companyaddress", "One Expoware Way, 1" dlg.SetItemText "companycity", "00000 Roundmond" dlg.SetItemText "companycountry", "Rome, Italy" dlg.SetItemText "companyphone", "+39 06 12345678" dlg.SetItemValue "invoiceID", numNewInvoice dlg.SetItemValue "invoicedate", sDate dlg.SetItemValue "quantity", 1 dlg.SetItemValue "description", "Description of the invoice" dlg.SetItemText "companysite", "our Web site." dlg.SetItemHref "companysite", "http://www.expoware.com" ' Display the dialog box dlg.Move 0, 0, 700, 450 If Not dlg.Show("center") Then WScript.Quit End If ' Store the data into variables Dim dlgInvoiceNo, dlgInvoiceDate, dlgQuantity Dim dlgPrice, dlgDesc, dlgTotal Dim dlgTo, dlgCurrency dlgTo = dlg.GetItemValue("recipient") dlgInvoiceNo = dlg.GetItemValue("invoiceID") dlgInvoiceDate = dlg.GetItemValue("invoiceDate") dlgQuantity = dlg.GetItemValue("quantity") dlgDesc = dlg.GetItemValue("description") dlgPrice = FormatNumber(dlg.GetItemValue("price"),,,, -2) dlgTotal = dlgQuantity * dlgPrice dlgTotal = FormatNumber(dlgTotal,,,, -2) ' Get the currency Dim wbdoc, ukp Set wbdoc = dlg.Document Set ukp = wbdoc.all("ukp") dlgCurrency = "$" If ukp.checked Then dlgCurrency = "£" ' -------------------------------------------------------------- ' Creates a new Word document ' -------------------------------------------------------------- Dim word, doc, docName Set word = CreateObject("Word.Application") Set doc = word.Documents.Add(myInvoiceDocTemplate) ' Fill the bookmarks in the document doc.Bookmarks("InvoiceNumber").Range.Text = dlgInvoiceNo doc.Bookmarks("InvoiceDate").Range.Text = dlgInvoiceDate doc.Bookmarks("Paid").Range.Text = "PAID" doc.Bookmarks("Quantity").Range.Text = dlgQuantity doc.Bookmarks("Recipient").Range.Text = dlgTo doc.Bookmarks("Description").Range.Text = dlgDesc doc.Bookmarks("Price").Range.Text = dlgCurrency & dlgPrice doc.Bookmarks("Total").Range.Text = dlgCurrency & dlgTotal doc.Bookmarks("Payable").Range.Text = dlgCurrency & dlgTotal ' Save the document as 'Invoice #.doc' Dim myDocs, fso Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FolderExists(myInvoiceFolder) Then fso.CreateFolder(myInvoiceFolder) End If docName = myInvoiceFolder & "Invoice " & dlgInvoiceNo & ".doc" doc.SaveAs docName doc.Close word.Quit ' -------------------------------------------------------------- ' Records the invoice in the database ' -------------------------------------------------------------- Set rs = CreateObject("ADODB.Recordset") rs.CursorLocation = adUseClient rs.Open "select * from Invoices", "Invoices",, adLockOptimistic rs.AddNew rs.Fields("InvoiceNo") = dlgInvoiceNo rs.Fields("InvoiceDate") = dlgInvoiceDate rs.Fields("Recipient") = dlgTo rs.Fields("InvoiceDescription") = dlgDesc rs.Fields("InvoiceAmount") = dlgTotal rs.Fields("Currency") = dlgCurrency rs.Fields("Paid") = 1 rs.Fields("WordFile") = docName rs.Update rs.Close ' -------------------------------------------------------------- ' Prints the invoice ' -------------------------------------------------------------- Dim shell, f, fi Set shell = CreateObject("Shell.Application") Set f = shell.Namespace(ssfDrives) Set fi = f.ParseName(docName) fi.InvokeVerb("&Print") ' -------------------------------------------------------------- ' Sends the document through e-mail ' -------------------------------------------------------------- ' Displays a dialog to accept the e-mail address of the recipient. It also ' validates what you type in using a regular expression. Dim address Set dlg = CreateObject("WshKit.InputBox") dlg.Title = "Send E-mail" dlg.Label = "Type the e-mail address in the edit box below:" dlg.Format = "\w+\@\w+\.\w+" ' The reg. exp. for e-mail addresses dlg.Show If dlg.Text = "" Then WScript.Quit End If ' Stores the address address = dlg.Text Dim oApp Dim mail Const olMailItem = 0 ' A mail item in Outlook ' Starts the Outlook application Set oApp = CreateObject("Outlook.Application") ' Creates a new mail item Set mail = oApp.CreateItem(olMailItem) ' Fill in the message mail.To = address mail.Subject = "Invoice" mail.Body = "Here's the invoice you were waiting for." mail.Attachments.Add docName mail.Send ' Closes Outlook oApp.Quit