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%> <%=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?
Originally posted by brianh Great, do you know how to sort using the file system object?
If you search on this forum you will get plenty of example of sorting algorithm, look for bubble sort. Here is an example using fso, u can adapt it to your need.
Originally posted by plenderj Sorry, only now just noticed where this thread was.
Um I don't know if there's any other ways of doing it in ASP etc, so just ignore me
Yes Jamie, I dont like to use FSO either, but in asp its the easiest and quickest way. There is other way of doing it, but more time consuming.
I have never really used FSO in VB but in asp i use it frequently.
In ASP, load the file contents line by line into a Scripting.Dictionary object. This doesn't need to be sorted (provided you index it correctly), as it's searchable!
Jerry Grant................tnarG yrreJ Website: <JG-Design></.net> Email: [email protected] Working towards a bug free world......
(Not a Microsoft employee)
Originally posted by Jerry Grant In ASP, load the file contents line by line into a Scripting.Dictionary object. This doesn't need to be sorted (provided you index it correctly), as it's searchable!
Well Dictionary object is pretty similar or if not the same to VB Collection Object. You can use it to store information temporerily but not permanently. I have to admint it is pretty useful sometime.