<% '**************************************************************************** '* Terms Of Use * '**************************************************************************** '**************************************************************************** '* This script is provided free of charge by WebEarth Network. * '* http://www.web-earth.net * '* by all mean feel free to modify any or all content of this script, * '* feel free to do anything with it you wish, print it out, give it to your * '* other half for valentines day, you will most likely be met with a puzzled* '* look, but you get the point. You can do ANYTHING you want with this as * '* long as the following Box is left at the top of the script. * '**************************************************************************** '**************************************************************************** '* THIS MUST REMAIN WITH THIS SCRIPT * '**************************************************************************** '* Origional Author: Lucas Nodine * '* Origional Company: WebEarth Network * '* Origional Co. Website: http://www.web-earth.net * '* * '* Use policy: * '* Distribute this to anyone, and everyone you wish. You may modify any or * '* all parts of this document, as long as this comment box stays with the * '* code. * '**************************************************************************** '*********************** DEPENDANT ON FILES AS FOLLOWS ********************** ' This script requires the following files for operation ' iniABusy.txt ' iniBBusy.txt ' iniCBusy.txt ' All of these are included in the .zip ' if one is lost, simply create a .txt document and put only a zero (0) in the file. ' no spaces no returns no other characters. ' ** ?? // IMPORTANT have a / on the end of ALL directories!!! // ?? ** '******************** Var's ******************* '///////////// READ DATA ////////////////////// ' Base Directory to look in for the data file ReadBaseDir = "d:/sites/webearth/" '///////////// WRITE DATA ///////////////////// 'Base Dir to write data file to ' IMPORTANT have a / on the end of ALL directories!!! WriteBusyBaseDir = "d:/sites/webearth/asp101Data/" WriteBaseDir = "d:/sites/webearth/" '*************************************************************************** '* Begin INI Read/writing code * '*************************************************************************** Function ReadINI(Section, Key, DefaultKeyValue, Path) Set oFS = Server.CreateObject("Scripting.FileSystemObject") Set ReadINIfile = oFS.OpenTextFile(ReadBaseDir & Path, 1, True) ' Set keyValue to empty so that if it is still empty at the end, it will return ' the DefaultKeyValue keyValue = "" While Not ReadINIfile.AtEndOfStream dataStr = ReadINIfile.ReadLine sectionLoc = InStr(1, dataStr, "[" & Section & "]") keyLoc = InStr(1, dataStr, "]" & Key & "=") If sectionLoc <> "0" Then If keyLoc <> "0" Then keyValue = Mid(dataStr, InStr(1, dataStr, "=") + 1) End If End If Wend ' If keyValue is still empty from the inital set, it will not be assigned the ' DefaultKeyValue value If keyValue = "" Then keyValue = DefaultKeyValue End If 'Cleanup our mess ReadINIfile.Close ReadINI = keyValue End Function Sub WriteINI(Section, Key, Value, Path) 'Set Error = "False" so that we can do error checking Error = "False" Set oFS = Server.CreateObject("Scripting.FileSystemObject") 'Open and read all Busy.txt's Set ReadINIfileABusy = oFS.OpenTextFile(WriteBusyBaseDir & "iniABusy.txt", 1, True) Set ReadINIfileBBusy = oFS.OpenTextFile(WriteBusyBaseDir & "iniBBusy.txt", 1, True) Set ReadINIfileCBusy = oFS.OpenTextFile(WriteBusyBaseDir & "iniCBusy.txt", 1, True) ReadINIABusy = ReadINIfileABusy.ReadAll ReadINIBBusy = ReadINIfileBBusy.ReadAll ReadINICBusy = ReadINIfileCBusy.ReadAll 'Below just check to find the first ini storage file that is not busy, running all ' of them before saying that they are all busy File = "" If ReadINIABusy = "0" Then Set WriteINIfileABusy = oFS.CreateTextFile(WriteBusyBaseDir & "iniABusy.txt", True) WriteINIfileABusy.Write "1" WriteINIfileABusy.Close Set WriteINIfileABusy = Nothing File = "A" Else If ReadINIBBusy = "0" Then Set WriteINIfileBBusy = oFS.CreateTextFile(WriteBusyBaseDir & "iniBBusy.txt", True) WriteINIfileBBusy.Write "1" WriteINIfileBBusy.Close Set WriteINIfileBBusy = Nothing File = "B" Else If ReadINICBusy = "0" Then Set WriteINIfileCBusy = oFS.CreateTextFile(WriteBusyBaseDir & "iniCBusy.txt", True) WriteINIfileCBusy.Write "1" WriteINIfileCBusy.Close Set WriteINIfileCBusy = Nothing File = "C" Else Error = "True" ErrorData = "All INI Files are busy, please try again later" End If End If End If 'Cleanup this mess ReadINIfileABusy.Close ReadINIfileBBusy.Close ReadINIfileCBusy.Close Set ReadINIfileABusy = Nothing Set ReadINIfileBBusy = Nothing Set ReadINIfileCBusy = Nothing If File = "A" Then Set WriteINIfile = oFS.CreateTextFile(WriteBusyBaseDir & "iniA.txt", True) ElseIf File = "B" Then Set WriteINIfile = oFS.CreateTextFile(WriteBusyBaseDir & "iniB.txt", True) ElseIf File = "C" Then Set WriteINIfile = oFS.CreateTextFile(WriteBusyBaseDir & "iniC.txt", True) Else Error = "True" ErrorData = "Unknown File Line 116" End If Set ReadINIfile = oFS.OpenTextFile(WriteBaseDir & Path, 1, True) 'This is what it will look for in the database searchString = "[" & Section & "]" & Key & "=" While Not ReadINIfile.AtEndOfStream dataStr = ReadINIfile.ReadLine sectionLoc = InStr(1, dataStr, "[" & Section & "]") keyLoc = InStr(1, dataStr, "]" & Key & "=") If sectionLoc <> "0" Then If keyLoc <> "0" Then WriteINIfile.Write searchString & Value & vbcrlf completeWritten = True Else WriteINIfile.Write dataStr & vbcrlf End If Else WriteINIfile.Write dataStr & vbcrlf End If Wend ' If completeWritten is true the entry was found and replaced, if not write a NEW entry. If completeWritten <> True Then WriteINIfile.Write searchString & Value & vbcrlf End If ReadINIfile.Close WriteINIfile.Close If File = "A" Then Set ReadINIfile = oFS.OpenTextFile(WriteBusyBaseDir & "iniA.txt", 1, True) ElseIf File = "B" Then Set ReadINIfile = oFS.OpenTextFile(WriteBusyBaseDir & "iniB.txt", 1, True) ElseIf File = "C" Then Set ReadINIfile = oFS.OpenTextFile(WriteBusyBaseDir & "iniC.txt", 1, True) Else Error = "True" ErrorData = "Unknown File Line 152" End If Set WriteINIfile = oFS.CreateTextFile(WriteBaseDir & Path, True) While Not ReadINIfile.AtEndOfStream WriteINIfile.Write ReadINIfile.ReadLine & vbcrlf Wend ReadINIfile.Close WriteINIfile.Close Set ReadINIfile = Nothing Set WriteINIfile = Nothing If File = "A" Then Set WriteINIBusy = oFS.CreateTextFile(WriteBusyBaseDir & "iniABusy.txt", True) ElseIf File = "B" Then Set WriteINIBusy = oFS.CreateTextFile(WriteBusyBaseDir & "iniBBusy.txt", True) ElseIf File = "C" Then Set WriteINIBusy = oFS.CreateTextFile(WriteBusyBaseDir & "iniCBusy.txt", True) Else Error = "True" ErrorData = "Unknown File Line 173" End If WriteINIBusy.Write "0" WriteINIBusy.Close Set WriteINIBusy = Nothing 'If there was an error, write out the returned error If Error = "True" Then Response.Write ErrorData End If Set oFS = Nothing End Sub '*************************************************************************** '* End INI Read/writing code * '*************************************************************************** 'If you are worried about people viewing your data file simply uncomment the next line and replace .ini with .asp 'WriteINI "<%", "This", "Is Hidden Now", "data.asp" 'Syntax WriteINI [Section] As String, [Key] As String, [KeyValue] As String, [Path] As String 'Syntax ReadINI([Section] As String, [Key] As String, [DefaultKeyValue] As String, [Path] As String) As String WriteINI "Author", "Name", "Lucas", "data.ini" WriteINI "Author", "Website", "http://www.web-earth.net", "data.ini" Response.Write "Author: " & ReadINI("Author", "Name", "Tom", "data.ini") Response.Write "<br>Website: <a href=" & ReadINI("Author", "Website", "None", "data.ini") & " target=""_blank"">" & ReadINI("Author", "Website", "None", "data.ini") & "</a>" Response.Write "<br>Empty Field: " & ReadINI("Author", "Nothin", "Empty", "data.ini") %>
Last Updated on October 26, 2015