adding new line into .ini

Microsoft Visual basic v6.0 deluxe learn...
July 28, 2009 at 11:14:58
Specs: Windows XP
appreciate your support to guide me how to add a new line under [ORAGTWY] using vbs the file as follows;

; Settings for 25-User-SqlBase Server
[dbnt25sv]
country=germany
cache=2000
sortcache=2000
readonly=0
oracleouterjoin=0
logfileprealloc=0
partitions=0
optimizerlevel=2
locktimeout=275

[dbnt25sv.dll]
comdll=sqlws32
comdll=sqlapipe

[win32client]
country=germany
clientname=Win32User
SetZeroLengthStringsToNull=ON

[win32client.dll]
comdll=sqlws32
comdll=sqlora32
comdll=sqlodb32

[win32client.ws32]
serverpath=SRVxxx,<localhost>/WCxxx

[ORAGTWY]
REMOTEDBNAME=pos401a1,@pos401a1
REMOTEDBNAME=posprd2,@posprd2
REMOTEDBNAME=bscsprd2,@bscsprd2
REMOTEDBNAME=BSCSPRE7,@BSCSPRE7
REMOTEDBNAME=BSCSPRE7,@BSCSPRE7
REMOTEDBNAME=SIEBPRD2,@SIEBPRD2


servername=server1
REMOTEDBNAME=WCDB,@WCDB

[ODBCRTR]

[SQLTALK]
country=germany

[SQLAPIW]
country=germany


See More: adding new line into .ini

Report •


#1
July 31, 2009 at 13:28:53
This should do what you are looking for.

set objWS = CreateObject("Wscript.Shell")
Set fsob=CreateObject("Scripting.FileSystemObject")

strNewLine = "New Line to Write"
strFileName = "c:\test.ini"

Const FOR_READING = 1
Const FOR_WRITING = 2
strCheckForString = UCase("[ORAGTWY]")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strFileName, FOR_READING)
strContents = objTS.ReadAll
objTS.Close
arrLines = Split(strContents, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, FOR_WRITING)
For Each strLine In arrLines
If (Left(UCase(LTrim(strLine)),Len(strCheckForString)) = strCheckForString) Then
objTS.WriteLine strLine
objTS.WriteLine strNewLine
else
objTS.WriteLine strLine
End If
Next


Report •

#2
July 31, 2009 at 15:56:00
Here is the same thing condensed down a little bit, it's not perfect but it's a work in progress, I have to take off.

strNewLine = "New Line to Write"
strFileName = "c:\test.ini"
strCheckForString = UCase("[ORAGTWY]")

Set objFS = CreateObject("Scripting.FileSystemObject")
StrContents = Split(objFS.OpenTextFile(strFileName).ReadAll, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, 2)
For Each strLine In StrContents
If (Left(UCase(LTrim(strLine)),Len(strCheckForString)) = strCheckForString) Then
objTS.WriteLine strLine: objTS.WriteLine strNewLine
else
objTS.WriteLine strLine
End If
Next
Wscript.quit


Report •

Related Solutions


Ask Question