cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I read a value from an ini file into a variable?

SOLVED
Participant

How can I read a value from an ini file into a variable?

I have configuration files in INI format. I would like to read these in Mahcad. Can someone give me a tip as I can read the values ​​individually one by one in MathCad variables?

Something like a := READ(File,Section,valuename)

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How can I read a value from an ini file into a variable?

Here is a first approach. Not much error handling included and will work for "well behaved" ini-files and numerical values only.

 
 
 

B.PNG

MC15 worksheet attached

View solution in original post

13 REPLIES 13

Re: How can I read a value from an ini file into a variable?

Even a solution for Prime is very welcome
 
Thank you very much

Re: How can I read a value from an ini file into a variable?

You'll have to be more specific about the structure of an "INI-file".

Re: How can I read a value from an ini file into a variable?

Example of INI-File:

Filename: 'Geometry.ini'
Content (ASCII-File):
[Cylinder1]
Hight=100.12
Diameter=25.123456
[PointA]
X=123.12345
Y=123458.3
Z=7.0

I would like to read the Value of MathCad Variable CylHight out of the INI-File.
I'm looking for something like:

CylHight:=READINI('Geometry.ini','Cylinder1','Hight')

Best regards

Re: How can I read a value from an ini file into a variable?

Here is a first approach. Not much error handling included and will work for "well behaved" ini-files and numerical values only.

 
 
 

B.PNG

MC15 worksheet attached

View solution in original post

Re: How can I read a value from an ini file into a variable?

Here's another approach.

LM_20191019_ReadIni.png

In your 'windows' directory you'll find more .INI files. Example:

LM_20191019_ReadIni.png

 

Success!
Luc

 

 

Re: How can I read a value from an ini file into a variable?

Here's the first incarnation in Prime 4:

LM_20191019_ReadIni.png

Which also works in Prime express.

 

Success!

Luc

Re: How can I read a value from an ini file into a variable?

Hi
Many thanks for your (Werner_E and  help. You helped me a lot. My INI files are a bit more complicated (string values, comments, empty lines, comment lines, different comment characters (*, //), tabulators, indents, etc). But you have shown me a way to solve my problems. In the next weeks I will work on a solution and then show it here.
Thanks again and best regards

Re: How can I read a value from an ini file into a variable?

Corrected an error where it would miss the last character of a parameter value.

 

Since the ReadIni(file, section, parameter) approach doesn't care about comment statements, it's sort of immune to them. This function will even handle this .INI file  https://downloads.avaya.com/elmodocs2/ip_phones/r2_7/output/16_601433_2/IPTel_Server044.html

 

Luc

Re: How can I read a value from an ini file into a variable?

-- delete --

Example INI-File:

Announcements