WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Variables and Parameters

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Variables in INI Files

Keywords:   variable substitution INI files

Question:

Is it possible to read a string from an ini file that does variable substitution?

I want to have:

	[section1]
	variable1=test1
	[section2]
	variable2=%variable1%
Then I read in variable1 and variable2 and have the value of variable2 = test1.

Answer:

Well, not exactly, but the following should work...
	[section1]
	variable1=test1
	[section2]
	variable2=variable1

	xxx=IniReadPvt("section2","variable2",0,inifile)
	yyy=IniReadPvt("section1",xxx,0,inifile)
	Message("Value of yyy is",yyy)
Or, if you have:
	[section1]
	variable1=something
	[section2]
	variable2=%variable1%\otherthing\
and after reading in variable1 and variable2, you want variable2=something\otherthing\

You would do something like:

	var1=IniReadPvt("section1","variable1",0,inifile)
	var2=IniReadPvt("section2","variable2",0,inifile)
	var2=StrReplace(var2,"%%variable1%%",var1)
But there's no easy way to generalize it... Another possibility might be:
	[section1]
	variable1=c:\something
	[section2]
	variable2=otherthing

	dir1 = IniReadPvt("section1","variable1","", inifile)
	dir2 = IniReadPvt("section2","variable2","", inifile)
	resultDir = ItemInsert (dir2, -1, dir1, "\")
Assuming that variable1 is a legit UNC or path, and variable2 doesn't have a beginning or trailing \, the result of the example will be:
	c:\something\otherthing\
This will also work:
	[section1]
	variable1=c:\level1\level2
	[section2]
	variable2=level3\level4
with the result being:
	c:\level1\level2\level3\level4\

Article ID:   W13925
Filename:   Variables and INI files.txt
File Created: 1999:04:15:16:57:18
Last Updated: 1999:04:15:16:57:18