VB icon


Submitted on: 1/6/2015 4:47:00 AM
By: Grummite (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: VbScript (browser/client side)
Views: 1253
     This is a VBS script that will look for a item in a INI file. Comes in handy when you need to read INI files created by other applications. It's Read-only, no writing to INI files done here.
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: INIreader
' Description:This is a VBS script that will look for a item in a INI file. Comes in handy when you need to read INI files created by other applications. It's Read-only, no writing to INI files done here.
' By: Grummite (from psc cd)
' Inputs:Changes need made in the
'code for the INI filename
'and INI item parameters.
'Look for the Code between
'the lines of ''''''s.
' Returns:It returns a message box
'with the string being
'search for.

' Email me at VBS@grummite.com
Option Explicit
Const ForReading = 1
Dim TheString	'The String we are looking for
Dim g_ShellObj	'Object used for sending text to a message box
'change INI File here
Const Filespec="\\SERVER\C$\FILENAME.INI"
Set g_ShellObj = CreateObject("Wscript.Shell")
'Starting Main function
	'Proper use is: ReadFromINI(INI file, Item in brackets, Item we are looking for)
	'This shows what has been found
	WScript.Echo Now() & " --> Ended **" & TheString & "**" 
Function ReadFromINI(INIfile,BracketItem,TheItem)
Dim fsoIN, Fin					'Objects for Reading.
Dim FoundBracket, FoundTheItem		'Keeps tracks of what we have found so far.
Dim CurrStr						'Last string that was read from the INI file.
Dim I 						'Integer used for stepping through CurrStr.
Dim StringFound					'String we are looking for.
Dim C							'Current character while stepping through CurrStr
'Initialize variables
	'Create an object and open file for reading.	
	Set fsoIN = CreateObject("Scripting.FileSystemObject")
	Set Fin = FsoIN.OpenTextFile(INIfile, ForReading)
	'Stepping through file line by line to find what we are looking for.
	Do While Fin.AtEndOfStream <> True
		If left(CurrStr,1)="[" Then	'Looking for an item in brackets
			If ucase(mid(CurrSTr,2,len(BracketItem)))=ucase(BracketItem) Then
			End If
			'Once we are within the right section we start searching for 
			'the correct item we are looking for.
			If FoundBracket Then
				'Compare each item to the item we are looking for.
				If ucase(left(CurrSTr,len(TheItem)))=ucase(TheItem) Then
					'We found the item! We must find where the equal sign
					'is so we don't include it in our result.
					I = len(TheItem)+1
					Do While I<len(CurrStr)
						C = MID(CurrStr,I,1)
						If C<>" " And C<>"=" Then
							'This is not the right item but similar name.
							'example: We're looking for "TheGreatThing" while
							'we found "TheGreatThingy". (Notice the "y")
							If C="=" Then
								'We found the equal sign, we can now create our
								'Just a space, we got to keep stepping through
								'the string until we find that equal sign.
							End If
						End If
				End If
			End If		
		End If
	'Close the file and clear the object.
	Set fsoIN=Nothing
	'Can't forget to Set the function's variable
End Function
'Have a nice day!

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.