Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

October 17, 2009

VBScript Ceil and Floor Functions

VBScript does not have native Ceiling and Floor functions. In order to use these function in your financial or mathematical applications, you will have to write your own VBScript implementation. By definition:

The ceiling and floor functions map a real number to the next largest or next smallest integer. More precisely, ceiling(x) is the smallest integer not less than x and floor(x) is the largest integer not greater than x.

So here is the VBScript implementation of these two functions:

July 9, 2009

Export Recordset Data to CSV Using ASP/VBScript

The CSV (Comma-Separated Values) file format is a text file format in which you can store tabular data, such as data from a database table. This format is can be read by various spread sheet programs such as Microsoft Excel and OpenOffice.org Calc. This format is not suitable for storing binary data.

The following ASP/VBScript code sample allows you to export data from a database table to a CSV file. The code accesses the table through an ADODB Recordset object, formats the data into the CSV format and sends the data to the browser along with appropriate response headers. This code should be saved as an ASP script on a webserver. You should see an "Open/Save As..." dialog when you access the script through a web browser.

July 4, 2009

VBScript Select Case Statement - Complete Syntax

The VBScript Select Case statement is a useful and more readable substitute for the VBScript If...Elseif statement. It allows you to execute one out of many blocks of code depending on the value of a variable.

While searching for example uses of this statement, I noticed that most of the examples available on the internet do not describe the complete syntax and usage of the statement. According to the MSDN VBScript reference, the syntax of the Select Case statement is:

June 23, 2009

Generate Random Strings Using ASP/VBScript

This is a simple yet highly customizable function that allows you to generate random strings using VBScript that you can use in your ASP/VBScript applications. The random strings can be used for various purposes, including:

  • Login Systems
    • Random password for new registrations
    • Random password for users requesting password reset
  • Referral Codes
  • Promotional Codes
  • Primary Keys for tables where using integers as primary keys is not desirable

The following code is a VBScript translation of the php random string function I wrote earlier. It generates an 8 character long random string that contains 1 digit:

May 19, 2009

List Images and Other Files Types in a Directory Using ASP

This is a nice and simple ASP+VBScript code snippet that lists the files present in the specified directory (folder). The ready-to-go example below displays the list of images. However, the code can display files depending on filename extension. The script also returns additional information about the files such as type, size and date modified.

April 13, 2009

Crop-To-Fit an Image Using ASP/PHP

Image Cropping refers to the removal of the outer parts of an image to improve framing, accentuate subject matter or change aspect ratio. In this article I will demonstrate a technique that combines resizing and cropping to fit an image in given dimensions. You can, for example, use this technique to generate square thumbnails for images with arbitrary dimensions and aspect-ratio.