VBScript Array Question

Results 1 to 2 of 2

Thread: VBScript Array Question

  1. #1
    Join Date
    Dec 1969

    Default VBScript Array Question

    No realy sure how to ask this question the right way, but here goes.<BR><BR>Q1: Is there a way to filter or display data on a web page based on an array instead of the traditional recordset method.<BR><BR>Example .csv table:<BR>id,menuitem,menu_link<BR>1, storage devices, 0<BR>2, computers, 0<BR>3, floppy drives, 1<BR>4, hard drives, 1<BR>5, tape drives, 1<BR>6, desktop computers, 2<BR>7, servers, 2<BR>8, notebooks, 2<BR><BR>When someone click a link such as the one below:<BR>&#060;a href="menupage.asp?mlink=2&#062;computers&#060;/a&#062;<BR><BR>The SELECT method finds the following records based on the mlink value of 2:<BR>results:<BR>6, desktop computers, 2<BR>7, servers, 2<BR>8, notebooks, 2<BR><BR>Q2:Is there a way to do this in an session array.<BR>

  2. #2
    Join Date
    Dec 1969

    Default Well, yeah, but...

    ...you *do* know you could simply treat the CSV file as a database???<BR><BR>The MS "text driver" will quite happily handle that file for you and allow you do 98% of the same queries you could do with an Access DB.<BR><BR>**********<BR><BR>But anyway:<BR><BR>I would convert the CSV file to an ARRAY-OF-ARRAYS.<BR><BR>That is each line of the file becomes one element in the outer array and then you SPLIT on comma to put each of the fields into an element of the inner array.<BR><BR>So then it&#039;s dirt simple:<BR><BR>&#060;%<BR>For rownum = 0 To UBound(allRows)<BR> row = allRows(rownum)<BR> If Trim(row(2)) = searchFor Then<BR> ...<BR> End If<BR>Next<BR>%&#062;<BR><BR>You could convert the CSV file thus:<BR><BR>&#060;%<BR>Set FSO = Server.CreateObject("Scripting.FileSystemObject")< BR>Set infile = FSO.OpenTextFile( Server.MapPath("whatever.csv") )<BR>allRows = Split( infile, vbCrLf )<BR>For rownum = 0 To UBound(allRows)<BR> allRows(rownum) = Split( allRows(rownum), "," )<BR>Next<BR>%&#062;<BR><BR>If you really do have the field names in the .csv file, then your later search loop should start at 1 instead of zero.<BR><BR>And as for storing this in a session variable...sure. Why not.<BR><BR>But unless the data is different for each user, why not store it in an application variable? MUCH more efficient.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts