Results 1 to 9 of 9

Thread: Looping through text file

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    Looping through text file

    I have a text file that I would like to loop through and obtain a listing of vendors. It is a file that is seperated by the "^" simble. I would like to loop through it and place the results in a combo box. Here is the code I have so far:

    Function getVendors(offnum)
    Const ForReading = 1
    Const Create = False

    ' Declare local variables
    strFileName = Server.MapPath("vendors.txt")

    ' Instantiate the FileSystemObject
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

    ' use Opentextfile Method to Open the text File
    Set TS = objFSO.OpenTextFile(strFileName, ForReading, Create)

    strValue = Ts.Readline
    strArray = Split(strValue, "^")
    ' - strArray is now an array
    Dim i
    If Not TS.AtEndOfStream Then
    For i = 0 to Ubound(strArray)
    'Response.Write i & " = " & strArray(i) & "<BR>"

    VendorName = strArray(0)
    VendorAddr = strArray(1)
    VendorCity = strArray(2)
    VendorState = strArray(3)
    VendorZip = strArray(4)
    VendorID = strArray(5)
    VendorOff = strArray(6)
    Next
    End IF
    ' close TextStreamObject
    ' and destroy local variables to relase memory
    'TS.Close
    'Set TS = Nothing
    'Set objFSO = Nothing
    End Function

    This is how I am calling it:

    <option value="002"><%If Not TS.AtEndOfStream Then %><%=VendorName%>,<%=VendorAddr%>&nbsp<%=VendorCity%>,<%=vendorzip%><%END IF%></option>

    The problem is that is only goes through the first line, then it stops. It places the first line in the combo box but that is it. How can I get all of them in there, also can you sort with a text file?

    Attached is the text file...Thanks
    Attached Files Attached Files

Posting Permissions

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



Click Here to Expand Forum to Full Width