ReadIniFile Challenge

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
MacschedStudent
Junior Coder
Posts: 36
Joined: Fri Oct 12, 2007 5:55 pm
Location: federal way wa
Contact:

ReadIniFile Challenge

Post by MacschedStudent » Sun Aug 29, 2010 12:07 am

Hey guys

I have read the History but don't see any problems with MSched 7.4 concerning ReadIniFile. But I can't seem to get it to work. I am running w2k. Here is the entire script - its almost exactly like the example

Code: Select all


ReadIniFile>setup.ini,STARTUP,AppName,indata
Let>msg=The Username is:
ConCat>msg,indata
MessageModal>msg


and believe it or not here is the entire contents of the setup.ini file

[Startup]
AppName=Browser Configuration Utility
ProductGUID=125BA25B-8D21-4029-AA06-47C3AA327AA7
CompanyName=DeviceVM




but when I click on the executable all I get is this

Code: Select all

The Username is:new,test


I have no idea where this is coming from any ideas???

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Sun Aug 29, 2010 12:45 am

I would like to see you path the INI file. Either hard-code it, or use
variables like %SCRIPT_DIR%

Other variables you can use:

WIN_DIR Windows Directory Path
SYS_DIR Windows System Directory Path
TEMP_DIR Windows Temp Directory Path
SCRIPT_DIR Directory of running script


Like this:

Code: Select all

ReadIniFile>%SCRIPT_DIR%\setup.ini,STARTUP,AppName,indata

MacschedStudent
Junior Coder
Posts: 36
Joined: Fri Oct 12, 2007 5:55 pm
Location: federal way wa
Contact:

Post by MacschedStudent » Sun Aug 29, 2010 1:14 am

You were correct, it worked - thanks

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

comments in INI files

Post by Dick99999 » Sun Aug 29, 2010 8:52 am

Since we are on INI files. I found an other issue. Remarks are commonly introduced by a semicolon in ini files. When reading the value of an ini var, the comments comes with it for free. I strip those off by demanding that comments are preceded by at least one tab.
Or is there any other formal comment character?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Aug 30, 2010 2:11 pm

Wikipedia INI information suggests that the INI format is not formal and fixed. If you are creating and reading your own INI files, I'd suggest making sure comments are on a line of their own. If you are reading INI files created by other applications, since there are conflicting "rules", you will have to write your code to deal with INI file idiosyncrasies you encounter.

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Wed Sep 01, 2010 4:39 pm

JRL wrote:Wikipedia INI information ..... If you are reading INI files created by other applications, since there are conflicting "rules", you will have to write your code to deal with INI file idiosyncrasies you encounter.
In that case wouldn't it be very helpful if ReadIniFile would have a filth parameter: a string that initiates comments and strips that part off the result?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Sep 01, 2010 5:00 pm

ReadINIFile> already does not read keys that are preceded by
a semicolon. This has been a standard in every program that I have ever seen (except for some "home grown" applications)

Example:

ReadIniFile>c:\test.ini,SETTINGS,TESTVAR,inresult


------- c:\test.ini ------------

[SETTINGS]
;TESTVAR=TRUE


This results in inresult=*EMPTY*

Even putting a tab character in front of the semicolon
results in nothing being read (as I would expect!)

[SETTINGS]
         ;TESTVAR=TRUE

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Sep 01, 2010 6:34 pm

Alan,

I'm not positive, but I think what Dick is referring to is having a comment on the same line as the data.

[SETTINGS]
TESTVAR=TRUE ;Set to TRUE or FALSE


What you'll get back from:

ReadIniFile>c:\test.ini,SETTINGS,TESTVAR,inresult


Is

iniresult = TRUE ;Set to TRUE or FALSE

My only response at this time remains:
If you are creating and reading your own INI files, I'd suggest making sure comments are on a line of their own. If you are reading INI files created by other applications, since there are conflicting "rules", you will have to write your code to deal with INI file idiosyncrasies you encounter.

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Thu Sep 02, 2010 7:08 am

Indeed I meant comment on the same line. And agree that lines starting with a comment ; are already being skipped by MS. To make the discussion less abstract, this is the code I currently use. Since I recently 'discovered' how regular expressions are implemented and work in MS, I might replace this by an RE that looks for the last appearance of TAB;

Anyway it works for me, and I'd still add a string or an RE as fifth parameter in ReadIniFile as a wish list item.

Code: Select all


ReadIniFile>%CWD%\%Fn%,section,nameVar,valueStr
Position>%TAB%;,valueStr,1,a_nPos,FALSE
if>a_nPos>0
   let>a_nPos=a_nPos-1
   MidStr>valueStr,1,a_nPos,valueStr
endif>
Trim>valueStr,valueStr

ini file
[section]
; on-line coments to be seperated by TAB; form the values
var1=abs                             ; this is a comment
var2=                                  ; this is an empty string
var3=file1;file2;                    ; is OK since the value contains no TAB


Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts