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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can i grab text from a .txt file and use it as a string

Status
Not open for further replies.

jacq

Technical User
Jan 3, 2001
38
GB
i have grabbed a username from a text file using filesystemobject and i can display it in my asp by using:
Response.Write " " & "Welcome " & objtextStream.Readline)
[COLOR="666666FF"]how can i get the username into a string?[/color]
i have tried declaring cUser = objtextStream.Readline but this returns an error
 
If the password is on the next line of the text file, then call the .skipline method, and then do your .readline again....

If that's not where the password is, then tell us where it is.

:)
Paul Prewett
 
i already have all the text i want from the textfile in the form of a username

i want to be able to get that username to see if it is entered in a table in my database instead of using login/password input boxes
i can't seem to do anything with the username other than display it

eg at the moment it displays 'Welcome ASMITH', but i want to be able to say
sUser = ASMITH 'or whatever is in the textfield
if rs("sUser") = ASMITH 'goto next page
 
Ahhh -- sorry. :) It's early.

Ok then -- now you have your username -- you need to read it into a variable like:

userName = objtextStream.Readline

That would be first -- and then write it and use it for comparison from this point forward from your variable --

Then, just make your recordset.... For checking for passwords, I usually stick that in the where clause of the SQL statement, and then check for an empty recordset to see if they are in there.

Let's say I have a table with userName as a field, and the table is called users, and I have the above variable declared.

dim sqlStatement
sqlStatement = "SELECT userName FROM users WHERE userName='" & userName & "'

rs.open sqlStatement, con

if not rs.eof then
response.redirect("loginSuccess.htm")
else
response.redirect("loginError.htm")
end if

Obviously, you could do anything you want in the if block there, instead of redirecting.

Does that help?
:)
Paul Prewett
 
thank you, that is what i'm trying to do but i keep getting this message when i try to put:
username = objtextstream.readline

Microsoft VBScript runtime error '800a003e'
Input past end of file
/ASP_Apps/ICTProjects/ictresponse.asp, line 156
 
I suspect that it's because you are still response.write'ing the content to the screen in this fashion:

Response.Write " " & "Welcome " & objtextStream.Readline)

and then trying to do this:

username = objtextstream.readline

Where the cursor in your text file is already at the end of the file, and so you are receiving that error. Try this:

username = objtextstream.readline
Response.Write " " & "Welcome " & username

and then go about your business.

let me know if this works. :)
paul
 
Paul...you are a star
thank you very much for your help,
Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top