Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

INI DB

Posted on July 18, 2013October 26, 2015 By David Kittell
<%
'****************************************************************************
'*                            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")

%>
Originally Posted on July 18, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

ASP Code VB

Post navigation

Previous post
Next post

Related Posts

MessageBox Class

Posted on November 19, 2013October 26, 2015

Dim result = MessageBox.Show("Message To Display", "MessageBox Title", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) If result = DialogResult.Cancel Then MessageBox.Show("Cancel Button Pressed", "MessageBox Title",MessageBoxButtons.OK , MessageBoxIcon.Exclamation) ElseIf result = DialogResult.No Then MessageBox.Show("No Button Pressed", "MessageBox Title", MessageBoxButtons.OK, MessageBoxIcon.Error) ElseIf result = DialogResult.Yes Then MessageBox.Show("Yes Button Pressed", "MessageBox Title", MessageBoxButtons.OK, MessageBoxIcon.Information) End If var result…

Read More

Excel – Find Comma Replace With LineBreak

Posted on August 11, 2015October 26, 2015

Selected the range of cells you need to replace. Go to Home > Find & Select > Replace or Ctrl + H Find what: , Replace with: CTRL + SHIFT + J Click Replace All Somehow CTRL + SHIFT + J is registered as a linebreak. Reference: http://stackoverflow.com/questions/14856501/substitute-a-comma-with-a-break-link-in-a-cell Originally Posted…

Read More

Enable/Disable Desktop Saves

Posted on November 9, 2013October 26, 2015

WARNING: Backup the computer you try these scripts on before you run these. These scripts will enable/disable the ability to save anything to the desktop. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer] "NoSaveSettings"=dword:00000001 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer] "NoSaveSettings"=dword:00000000 Originally Posted on November 9, 2013Last Updated on October 26, 2015…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes