Skip to main content
1-Visitor
October 18, 2019
Solved

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

  • October 18, 2019
  • 2 replies
  • 5126 views

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)

Best answer by Werner_E

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

2 replies

diedrich1-VisitorAuthor
1-Visitor
October 18, 2019
Even a solution for Prime is very welcome
 
Thank you very much
23-Emerald IV
October 19, 2019

Here's the first incarnation in Prime 4:

LM_20191019_ReadIni.png

Which also works in Prime express.

 

Success!

Luc

23-Emerald IV
October 21, 2019

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

25-Diamond I
October 18, 2019

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

diedrich1-VisitorAuthor
1-Visitor
October 18, 2019
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
Werner_E25-Diamond IAnswer
25-Diamond I
October 18, 2019

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