Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Can i read the value from a .properties file

Reply
 
Old 08-20-2008   #1 (permalink)
deepal.82


 
 

Can i read the value from a .properties file

Hi,

I have a abc.properties files.
This file has contents as below

#local
local.db.server = SQL024301
local.db.database = Taurus_Dev_R4
local.db.username = NT
#dev
dev.db.server = SQL024302
dev.db.database = Taurus_Dev_R4
dev.db.username = NT

The above parameters are passed to a stored procedure through the VB
script. Can i read the values from the properties file? If so how?

Thanks
Deepal

My System SpecsSystem Spec
Old 08-20-2008   #2 (permalink)
ekkehard.horner


 
 

Re: Can i read the value from a .properties file

deepal.82@xxxxxx schrieb:
Quote:

> Hi,
>
> I have a abc.properties files.
> This file has contents as below
>
> #local
> local.db.server = SQL024301
> local.db.database = Taurus_Dev_R4
> local.db.username = NT
> #dev
> dev.db.server = SQL024302
> dev.db.database = Taurus_Dev_R4
> dev.db.username = NT
>
> The above parameters are passed to a stored procedure through the VB
> script. Can i read the values from the properties file? If so how?
>
> Thanks
> Deepal
To get you started:

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sPFSpec : sPFSpec = ".\abc.properties"
Dim dicProps : Set dicProps = CreateObject( "Scripting.Dictionary" )
Dim oTS : Set oTS = oFS.OpenTextFile( sPFSpec )
Dim sSect : sSect = ""
Do Until oTS.AtEndOfStream
Dim sLine : sLine = Trim( oTS.ReadLine )
If "" <> sLine Then
If "#" = Left( sLine, 1 ) Then
sSect = sLine
WScript.Echo oTS.Line, "starting section", sSect
Else
If "" = sSect Then
WScript.Echo oTS.Line, "no section", sLine
Else
Dim aParts : aParts = Split( sLine, "=" )
If 1 <> UBound( aParts ) Then
WScript.Echo oTS.Line, "bad property line", sLine
Else
dicProps( sSect & "." & Trim( aParts( 0 ) ) ) = Trim( aParts( 1 ) )
WScript.Echo oTS.Line, "good property line", sSect, sLine
End If
End If
End If
End If
Loop
oTS.Close

Dim sKey
For Each sKey In dicProps
WScript.Echo sKey, "=>", dicProps( sKey )
Next

sKey = "#local.local.db.database"
WScript.Echo dicProps( sKey )

output:

2 starting section #local
3 good property line #local local.db.server = SQL024301
4 good property line #local local.db.database = Taurus_Dev_R4
5 good property line #local local.db.username = NT
6 starting section #dev
7 good property line #dev dev.db.server = SQL024302
8 good property line #dev dev.db.database = Taurus_Dev_R4
8 good property line #dev dev.db.username = NT
#local.local.db.server => SQL024301
#local.local.db.database => Taurus_Dev_R4
#local.local.db.username => NT
#dev.dev.db.server => SQL024302
#dev.dev.db.database => Taurus_Dev_R4
#dev.dev.db.username => NT
Taurus_Dev_R4

My System SpecsSystem Spec
Old 08-20-2008   #3 (permalink)
deepal.82


 
 

Re: Can i read the value from a .properties file

Thanks a lot for the reply. I shall try to work on this.
My System SpecsSystem Spec
Old 08-21-2008   #4 (permalink)
deepal.82


 
 

Re: Can i read the value from a .properties file

On Aug 20, 5:25*pm, deepal...@xxxxxx wrote:
Quote:

> Thanks a lot for the reply. I shall try to work on this.
This works fine. thnx a lot
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
read-only option in properties cannot be cleared General Discussion
File info and properties when you right ckick on a file Vista file management
How to read sql server database properties PowerShell
Read properties in windows Mail Vista mail
Read properties of Windows Service from Windows Forms App .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46