Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting variables using .ini (?) file

Status
Not open for further replies.

ErroR

Technical User
Apr 9, 2001
79
US
I'm somewhat new to the VB Scripting and here is what I'm trying to do and any help or suggestions on how best to accomplish this would be great.

I'm trying to setup a script that will manipulate some system files and drive mappings according to some choices made in a batch menu file.

What I need is the ability for a few variables to be set according to some plain text contained in an external file so that individuals who don't understand VB don't have to go into the script to make minor changes such as server name or driver letter changes.

So, I would like to be able to use something like an .ini file to specify the options like this:

[ABCServer]
drive=X
share=ABCShare
client=ABCompany

[123Server]
drive=Y
share=123Share
client=123Company

This way I can make the code very static in what it does, yet allow the non-programatic associates edit the .ini file to change simple specifics per client.

However, I'm unsure how to get the script to jump to the specific section of the file to read the variables I'm setting.. SkipLine is kinda restrictive..

Any help is appreciated.
 
DIM objfile, inifile
set objfile = createobject("Scripting.FileSystemObject")
if isobject(objfile) then
set inifile = objfile.opentextfile("MYINIFILE.INI")
end if

dim ini
while not inifile.atendofline
ini = inifile.readline
response.write ini & &quot;<br>&quot; & cvbCrLf
wend
inifile.close
set objfile=nothing
br
Gerard
(-:
 
Gerard,

Thanks for the reply.. however I'm a bit puzzled.. I'm am a noob afterall.

With what you wrote, I get an error about the Response.Write, error says Object Required..

Anyway, trying to decode what your piece there does, I still don't see how it gives me the ability to jump to the certain sections of the .ini file?

Maybe you could explain a bit?

Thanks! =)
 
a) cvbCrLf is wrong; vbCrLf is correct.
b) In my source there is no &quot;MYINIFILE.INI&quot;, but a real path and filename. Of cource the file exists.....
c) The response.write is just to list the contents. When you
search a specific value, you must include a IF-statement, to skip al the rows you do not need...

br
Gerard
(-:
 
I caught the cvbCrLf, I figured as fast as you got back to me, just one mistype was pretty good...

I got the path for the .ini file setup just fine and now I get your IF statement comment. I appreciate the help.. but I had one last question.

Your line:

if isobject(objfile) then

I'm not familiar with that, what is that piece doing?
 
it's a check to see if the obeject was created correctly. i cut/paste this from a piece of code, and removed obsolete lines. obviously an 'ELSE' block is missing now... but that is something for you to decide ;-)

br
Gerard
(-:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top