File_SettingRead

Reads setting from config file

Config file can be passed as argument

Contents of the file is as follows:
#Hash lines are comment lines
' Also lines start with '
#You may add as many comments as you want
appname = File_SettingRead
appversion = 4.8
icsDrive=C
icsProjectDir=ICS
icsMinDiskSpace=5000
icsMaxDiskSpace=100000
icsMailApplication=Outlook.Application
icsEMailTo=mymail@yourhost.com
#End of the configuration file

Part of this was found online a while back and enhanced to be flexible enough
Can be used in VB6, VB.net and even ASP Classic after some modifications

CodeFunctionName
What is this?

Public

Tested

Original Work
Function File_SettingRead(SettingID, Optional fileName = "D:\App.Config")
Dim FSO
Dim strConfigLine
Dim fConFile
Dim EqPos, strLen, varName, varVal
Rett = "{{$N/A$}}"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fConFile = FSO.OpenTextFile(fileName)
Do While Not fConFile.AtEndOfStream
strConfigLine = fConFile.ReadLine
strConfigLine = Trim(strConfigLine)
If Left(strConfigLine, 1) = "#" Then GoTo NextLine
If Left(strConfigLine, 1) = "'" Then GoTo NextLine
If strConfigLine = "" Then GoTo NextLine
' If (INSTR(1,strConfigLine,"#",1) < > 1 AND LEN(strConfigLine) < > 0) THEN
EqPos = InStr(1, strConfigLine, "=", 1)
strLen = Len(strConfigLine)
varName = UCase(Trim(Mid(strConfigLine, 1, EqPos - 1)))
varVal = Trim(Mid(strConfigLine, EqPos + 1, strLen - EqPos))
If varName = UCase(SettingID) Then
Rett = varVal
Exit Do
End If
NextLine:
Loop
fConFile.Close
File_SettingRead = Rett
End Function

SettingID, Optional fileName = "D:\App.Config"

Views 790

Downloads 311

CodeID
DB ID

ANmarAmdeen
602
Attachments
Revisions

v1.0

Wednesday
September
23
2020