Array Function for ASP - 19 Feb 2002

I was in search of an array function like the one below for ASP (being so lazy!), but I couldn't find one... so I decided to create my own! This function reads a file line by line and stores each line a dynamic array. First two object varibles - fso (file system object) and ts (textfileobject) - are created.

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(filename, ForReading)

Then I declared an array using ReDim statement with the size set one.

reDim myarray(0)

Now as long as I read from the file, I change the size of the array dynamically without destroying the previous elements and copy the current line read to the current array element.

While not ts.AtEndOfStream

Redim Preserve myarray(i)

The final statement returns the myarray object from function File(filename). Here's the entire source code listing:

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.