VBScript Libraries

The VBScript libraries listed here are provided freely. We do ask that if you use these libraries, or these ideas, that you refer to us in your documentation and notes.

AccessDatabase

Set [AccessDatabase Object Instance] = New AccessDatabase

Methods:

  • void AddRecord
    Adds a new record to the current recordset
  • void Connect
    Opens the connection to the database.
  • void ExecuteSQL(string SQL)
    Executes the provided SqlString using the current database connection.
  • variant GetColumn(string ColumnName)
    Returns the value of the specified column.
  • adoRecordset Retrieve(string SQL)
    Selects the records specified by the SqlString using the current database connection and returns them as an ADO Recordset object.
  • void SetColumn(string ColumnName, string ColumnValue)
    Sets the column specified by ColumnName to the value specified by ColumnValue in the current record.
  • void Update
    Updates the recordset and requeries the database to refresh data.

Properties:

  • COMMAND_TYPES
    A Dictionary object containing available the CommandType enumeration.
  • Connection
    The ADO Connection object used to access the database.
  • CURSOR_TYPES
    A Dictionary object containing available the CursorType enumeration.
  • Filename
    A string specifying the filename of the MS Access database.
  • IsActive
    A boolean indicating whether or not the Recordset object is active.
  • IsConnected
    A boolean indicating whether or not the database is open.
  • LOCK_TYPES
    A Dictionary object containing available the LockType enumeration.
  • Password
    A string containing the password to be used to open the database file.
  • Recordset
    The ADO Recordset object currently open on the database connection.
  • Username
    A string containing the username to be used to open the database file.

Example:

Set oAccessDatabase = New AccessDatabase
oAccessDatabase.Filename = Server.MapPath("..") & "\db\mydb.mdb"
Set oRecordset = oAccessDatabase.Retrieve("SELECT * FROM [MyTable]")

Calendar

Set [Calendar Object Instance] = New Calendar

Methods:

Properties:

  • Days
    A collection of CalendarDate objects
  • Database
    The name of the events database (MS Access) with a relative path from the root level (e.g. "\access_db\calendar.mdb"
  • Ends
    A date or string that evaluates to a date representing the ending date of the calendar or schedule.
  • Html
    The calendar as an HTML table. The class attribute of the table will be "calendar". Although the table will not contain events from the event database, the class attribute of the table cell will be set to "holiday" or "holiday religious" if the date is a holiday.
  • Schedule
    The calendar as an HTML table. The class attribute of the table will be "calendar". The table will contain events from the event database, and the class attribute of the table cell will be set to "holiday" or "holiday religious" if the date is a holiday.
  • Starts
    A date or string that evaluates to a date representing the starting date of the calendar or schedule.

Crypto

Set [Crypto Object Instance] = New Crypto

Methods:

  • string DecryptMessage(string Message, string MethodName)
    Decrypts the provided Message using the selected MethodName. MethodName must match one of EncryptionMethodEnum.
  • string EncryptMessage(string Message, string MethodName)
    Encrypts the provided Message using the selected MethodName. MethodName must match one of EncryptionMethodEnum.

Properties:

  • EncryptionKey
    A string specifying the current encryption key.
  • EncryptionMethods
    A string array containing the common names in EncryptionMethodEnum.
    • Base64
    • Binary
    • MD5
    • Rijndael
    • SHA
  • State
    An integer representation of the current decryption or encryption state.
  • Status
    One of the following strings corresponding to the State:
    • Initialized
    • Decryption/Encryption complete
    • Unable to decrypt
    • Unable to encrypt
    • Unrecognized method. Recognized methods are: [EncryptionMethods]
    • Bad Base64 string
    • Failure during message conversion
    • Key is not set
    • Bad Rijndael message
    • Bad Rijndael key
    • Bad Rijndael message length

Example:

Set oCrypto = New Crypto

MyEncryptedString = oCrypto.Encrypt(MyPlainTextString, "Base64")

Email

Set [Email Object Instance] = New Email

Methods:

  • void AddAttachment(string FileToAttach)
    Attaches the file specified to the email message.
  • void SaveAttachment(string SaveToFolder, string IndexOrFilename)
    Saves the attachment specified by the index or filename to the folder specified.
  • void SaveAttachments(string SaveToFolder)
    Saves all attachments to the folder specified
  • void Send
    Sends the email.
  • void WriteToResponse
    Writes the email to the ASP Response TextStream

Properties:

  • CdoMessage
    CDOMessage object representing the email.
  • Connection
    The Configuration attribute of the CdoMessage object.
  • From
    EmailAddress object representing the sender.
  • Recipient
    EmailAddress object representing the recipient.
  • Message
    A string representing the body of the email.
  • SmtpServer
    The EmailServer used to send the email.
  • Subject
    A string representing the subject of the email.

Example:

Dim oSender
Set oSender = New EmailAddress
oSender.Name = "My Mailbot"
oSender.Address = "mailbot@my-domain.com"

Dim oEmail
Set oEmail = New Email
oEmail.From = oSender

oEmail.Recipient = oRecipient

oEmail.SmtpServer.Authentication = "basic"
oEmail.SmtpServer.Name = "smtp.my-domain.com"
oEmail.SmtpServer.Password = "n0-rep1y"
oEmail.SmtpServer.Username = "no-reply@my-domain.com"
oEmail.SmtpServer.IsLocal = False
oEmail.SmtpServer.ReplyTo = oSender
oEmail.SmtpServer.Sender = oSender
oEmail.SmtpServer.Port = 25

oEmail.Subject = "Test subject"
oEmail.Message = "The AutomatedEmail has initialized. The triggering event was: " & vbCrLf & vbCrLf & "Request from webmaster."

oEmail.Send

EmailAddress

Set [EmailAddress Object Instance] = New EmailAddress

Methods:

  • void Create(string NormalizedEmailAddress)
    Creates an EmailAddress from a normalized email address. A normalized address contains a person's name or a description of the email in quotes and an email address in braces (i.e. < and >).

Properties:

  • Address
    A string representing the email address.
  • Name
    A string representing the person's name or a description of the email.
  • Normalized
    A string representing the normalized version of the email address.

Example:

Set oRecipient = New EmailAddress
oRecipient.Name = LastName & ", " & FirstName
oRecipient.Address = "my-email@my-domain.com"

EmailServer

Set [EmailServer Object Instance] = New EmailServer

Methods:

  • void DeliverMail
    Delivers mail to the users with accounts on the server.
  • CDOMessages Messages
    Gets the messages from the CDO DropDirectory and returns them as a CDO Messages collection.

Properties:

  • Account
    The CDO SMTP account.
  • Authentication
    The authentication method to be used. The string is one of AuthenticationProtocolEnum:
    • Anonymous
    • Basic
    • NTLM
  • AuthenticationProtocols
    A string array containing the values in AuthenticationProtocolEnum.
  • Configuration
    The CDO.Configuration object
  • Fields
    The Fields collection of the CDO.Configuration object
  • IsLocal
    A boolean indicating whether or not the email accounts are local. If true then mail will be sent using the pickup method, if false then the mail will be sent using the port.
  • Name
    A string representing the name of the SMTP server.
  • Password
    A string representing the password to be used to authenticate with the server.
  • Port
    A integer representing the port the SMTP server uses to send mail.
  • ReplyTo
    An EmailAddress object used as the Reply-To address.
  • Sender
    An EmailAddress object representing the sender.
  • Username
    A string representing the username to be used to authenticate with the server.
  • UseSSL
    A boolean used to indicate whether or not the SMTP server uses SSL for authentication.

Example:

Set oSmtpServer = New EmailServer

oSmtpServer.Authentication = "basic"
oSmtpServer.Name = "smtp.my-domain.com"
oSmtpServer.Password = "n0-rep1y"
oSmtpServer.Username = "no-reply@my-domain.com"
oSmtpServer.IsLocal = False
oSmtpServer.ReplyTo = oSender
oSmtpServer.Sender = oSender
oSmtpServer.Port = 25

Financial

Set [Financial Engine Object Instance] = New Financial

Methods:

  • AmortizationSchedule Amortize(float Principal, float AnnualPercentageRate, integer Years, boolean BalloonPayment)
    Returns an AmortizationSchedule object for a given amount with a given annual percentage rate over a period of years. The AmortizationSchedule contains a Schedule collection of AmortizationPayment objects.
  • float BreakEvenPoint(float FixedCost, float SellingPrice, float VariableCost)
    Returns the number of units that must be sold at the specified selling price given the fixed cost and variable cost associated with production and sale of the units.
  • float CompoundInterest(float Principal, float AnnualPercentageRate, integer Periods)
    Returns the amount of interest compounded on the princicpal given the interest rate (e.g. 6.75% as 6.75) and the number of periods.
  • float FutureValue(float PaymentAmount, float AnnualPercentageRate, integer NumberOfPayments)
    Returns the future value of periodic payments given the amount of the payment, the rate of interest, and the number of payments.
  • float Mean(float[] DataArray)
    Returns the mean of the values presented in the data collection. Since VBScript is generally type agnostic, any numeric type (e.g. float or integer) can be used in the array.
  • float Median(float[] DataArray)
    Returns the median of the values presented in the data collection, or the value that falls directly between the highest and lowest values. Since VBScript is generally type agnostic, any numeric type (e.g. float or integer) can be used in the array.
  • string RuleOfSeventyTwo(boolean ReturnAsAPercentage, float Amount)
    Returns a string that will contain either the percentage or the number of years required to double your investment (e.g. "7%" or "7 years"). If bReturnPercentage is true, the result will be expressed as a percentage, otherwise, the result will be the number of years required.
  • float StandardDeviation(float[] DataArray)
    Returns the standard deviation of the values presented in the data collection. Since VBScript is generally type agnostic, any numeric type (e.g. float or integer) can be used in the array.
  • float ZScore(float Earnings, float NetSales, float MarketValueOfEquity, float WorkingCapital, float RetainedEarnings, float TotalAssets, float TotalLiabilities)
    Returns the Altman Z-Score that is used as a predictor of bankruptcy. A score of 2.99+ indicates business is sound, while a score between 1.81 and 2.98 indicates caution and 1.80 and below indicates that a business is in trouble.

Properties:

  • Schedule

    AmortizationSchedule

    Methods:

    • hash Amortize(float Principal, float AnnualPercentageRate, float Years, float BalloonPayment)
      Creates a collection of AmortizationPayment objects.
    • void MoveFirst
      Moves the index to the first AmortizationPayment object in the Schedule.
    • void MoveLast
      Moves the index to the last AmortizationPayment object in the Schedule.
    • void MoveNext
      Moves the index to the next AmortizationPayment object in the Schedule.
    • void MovePrevious
      Moves the index to the previous AmortizationPayment object in the Schedule.
    • AmortizationPayment Payment(PaymentIndex)
      Returns an the AmortizationPayment from the Schedule hash indicated by the PaymentIndex. The AmortizationPayment object contains four properties and no methods.
      • Balance
      • Interest
      • Payment
      • Principal

    Properties:

    • APR
      A floating-point number between 0 and 100 that represents the annual percentage rate used in the amortization schedule.
    • Balloon
      A boolean indicating whether or not a balloon payment is expected on the loan.
    • BOF
      A boolean indicating whether or not the payment index is at the beginning of the schedule.
    • EOF
      A boolean indicating whether or not the payment index is at the end of the schedule.
    • Principal
      A floating-point number that represents the amount of the loan.
    • Schedule
      A Dictionary object that contains the schedule of payments. The key is a number between 1 and the number of payments in the collection.
    • Years
      An integer that represents the length of the loan.

Example

Gps

Set [Gps Object Instance] = New Gps

Methods:

  • double distance(Location start, Location stop)
    Returns the distance between the two locations in kilometers.
  • double kilometers(double miles)
    Returns the number of kilometers in the specified number of miles.
  • double miles(double kilometers)
    Returns the number of miles in the specified number of kilometers.

Properties:

Example:

Set oHome = new Location
oHome.Latitude.degrees = 33
oHome.Latitude.minutes = 29
oHome.Latitude.seconds = 20
oHome.Longitude.degrees = -111
oHome.Longitude.minutes = 56
oHome.Longitude.seconds = 42
Set oWork = new Location
oWork.Latitude.degrees = 33
oWork.Latitude.minutes = 31
oWork.Latitude.seconds = 52
oWork.Longitude.degrees = 112
oWork.Longitude.minutes = 0
oWork.Longitude.seconds 16
oWork.Longitude.direction = "W"
Set oGps = new Gps
double_miles = oGps.miles(oGps.distance(oHome, oWork))