Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing Option Selected From textfile

Status
Not open for further replies.

techskool

Technical User
Jun 20, 2002
151
GB
Hi Guys

This works to populate a drop down box from a text box. Very useful.
---------------------------------
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' use Opentextfile Method to Open the text File
Set TS = objFSO.OpenTextFile(strFileName, ForReading, Create)
If Not TS.AtEndOfStream Then
Do While Not TS.AtendOfStream
strLine = TS.ReadLine ' Read one line at a time
Response.Write (&quot;<option>&quot; & strLine & &quot;</option>&quot;)
Loop
End If
---------------------------------

Ive added this to it to give option selected when comparing a recordset value to the textfile values. This however doesnt work, but i cant see what ive done wrong?

---------------------------------
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
' use Opentextfile Method to Open the text File
Set TS = objFSO.OpenTextFile(strFileName, ForReading, Create)
If Not TS.AtEndOfStream Then
Do While Not TS.AtendOfStream
strLine = TS.ReadLine ' Read one line at a time
If srtLine = rs(&quot;Format&quot;) Then
Response.Write (&quot;<option selected>&quot; & rs(&quot;Format&quot;) & &quot;</option>&quot;)
Else
Response.Write (&quot;<option>&quot; & strLine & &quot;</option>&quot;)
End If
Loop
End If
-------------------------------------



Cheers in advance

Dave

 
Not sure I would open the two objects together and run through them as you are.

why not open the DB write the values to a array and then compare the array to the text file values. That way you have something to point to for debugging much easier then the way your working it now also.

have you ensured a value in the recordset

_________________________________________________________
[sub]$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;[/sub]
onpnt2.gif
[sup] [/sub]
 
This is often a bad compare syntax...try adding in CStr and Trim...
 
When i say i have added this , ive just sdded a bit of code, theres onlyone drop down box.

Theres a value in the recordset, ive tries the usual response.write, and its there.

What do you mean open 2 obects together, the recordset and the filesystem???

Anyway

This works

Do While Not TS.AtendOfStream
strLine = TS.ReadLine ' Read one line at a time
Response.Write (&quot;<option>&quot; & strLine & &quot;</option>&quot;)
Loop


My understanding, was that if this loops through and writes out all the lines in the text field, then adding a simple if statement, such as:

If srtLine = rs(&quot;Format&quot;) Then
Response.Write (&quot;<option selected>&quot; & rs(&quot;Format&quot;) & &quot;</option>&quot;)
Else


I thought the logic way that while a loop is initialised, if somethin matches, then write THIS, and if it doesnt write THAT.

Thanks so far fellas

Dave ;-)
 
okay guys its still not working, so :

onpnt:
how do i write the values to a array and then compare the array to the text file values.
and

jackfl
how can i use , CStr and Trim...

Cheers guys

Dave


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top