Jump to content
Macro Express Forums

Detect missing section/key in ini file


Recommended Posts

I am setting a variable from a Section/Key in an ini file and am trying to detect if either the Section or the Key is missing from the file (as opposed to being present but containing a blank value).

 

There are five "On Error" conditions in "Set Value from INI file", but none of them seem to be related to detecting missing Section/Key.

 

Thoughts?

Link to comment
Share on other sites

Pretty simple. Create a test variable and set to the contents of the file. Then check if it contains the strings representing the sections an parameters.

[b]Quasi code:[/b]
Variable Set to ASCII Char 10 to %LF%
Variable Set to ASCII Char 13 to %CR%
Variable Set String %Section% to "[some Section]"
Variable Set String %Parameter% to "%CR%%LF%Some Parameter="
Variable Set String %Test% to contents of c:\test.ini
If Variable %Test% contains %Section%
And
If Variable %Test% contains %Parameter%
Jump in the creek
Else
Give the user an error
Endif

CRLF (Carriage Return/Line Feed) is just there to make sure your parameter stars with end of line from the previous line. So in case you search for "Floyd=" and there is a parameter named "Pink Floyd="

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...