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

Multithreded file writing in VBS/ASP

Status
Not open for further replies.

alonex

Programmer
Jan 10, 2006
14
US
Hi,

I have an ASP file that updates a file, I need to keep the updating capabilty in a multi-access environment.

how can I modify my code (below) to allow multi-access (somthing similar to non blocking I/O in Java)?

Thanks,
Alonex

My code:
=========

<%
if (Request.Form("user_id"))<>"" then
'declare our variables
Dim passwd,objFSO , myFile, findStr,ReadLineTextFile,MyFileRead,pos

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set myFileRead = objFSO.OpenTextFile("c:\file.txt", 1)

findStr=Request.Form("user_id")
foundID = false
Do While MyFileRead.AtEndOfStream <> True
ReadLineTextFile = MyFileRead.ReadLine
pos=InStr(1,ReadLineTextFile,findSTR,1)
if (pos <> 0) Then foundID = True
' if (StrComp(finsSTR,ReadLineTextFile))=0 Then foundID = True
Loop
MyFileRead.close

if foundID = True Then

msg = (Request.Form("user_id"))&" is already regisered"
Response.Write("<" & "script language=VBScript>")
Response.Write("MsgBox """ & msg & """<" & "/script>")

else

'create a text file called c:\file.txt , this was created on the C drive
Set myFile = objFSO.OpenTextFile("c:\file.txt", 8)
myFile.WriteLine(Request.Form("user_id"))
myFile.Close

Set myFile = Nothing
Set objFSO = Nothing

'response.write(Request.Form("user_id"))
msg = (Request.Form("user_id"))&" had been registered successfully"
Response.Write("<" & "script language=VBScript>")
Response.Write("MsgBox """ & msg & """<" & "/script>")

'&(Request.Form("user_id"))&" had been registered"
Response.End

End if
End if
%>
 
Whew! That code's a bit untidy, hmm?

The FSO doesn't offer any mechanism for concurrent file I/O. At the least you'll want some form of locking. Since simple file I/O isn't going to help you, you'll need to consider something like a small Jet database instead.
 
SQL Express is free so why not go with a SQL database. Writing to SQL via code works easy enough and plenty of examples are available if you search.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top