LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

[.ini files] Get value of several tags with the same name

Solved!
Go to solution

Hi !

 

In an ini.files, i have to get the value of each tag named a certain way in a section, but unfortunately, i have 3 or 4 tags having the same name in several sections. I don't know how to do to recover these values, the program always only consider the first tag and not the others, I tried to delete each tag after getting its values it didn't work.

 

Does someone have an idea to resolve the problem ?

 

Thanks !

0 Kudos
Message 1 of 10
(4,765 Views)

As far as I know there is no way to have more than one element in a section with the same name: the instrument simply reads the first one and skips the others.

 

If you can modify your ini file structure you could for example pack all these values into a single line, something like

Element = "value1; value2; value3"

 

Or you could differentiate the names of the elements:

Element 1 = value

Element 2 = value

 

I see no other solution unless you want to abandon the inifile instrument and read the file as an ASCII one scanning lines one by one.

 

Your attempt to delete the element after reading cannot work since the problem lies in Ini_ReadFromFile function which actually reads file content into the IniText structure in memory: you should save the data to disk with Ini_WriteToFile after that, but doing so you are likely to loose all duplicated elements as they simple aren't in memory!

 

 

Well, actually you could try to modify the IniFile instrument, whose code is public, but I personally discourage you from running this way as as the inifile instrument is not a simple code to maintain; additionally you may have to do this work again and again on every CVI update that modifies the instrument.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 10
(4,762 Views)

Thanks for your answer !

 

I can't modify the file structure, because it is read by other programs that are not mine.

I think i will read the file like an ASCII file, if I put a pointer on the tag I want the value, is there a function to recover the entire line using that pointer?

0 Kudos
Message 3 of 10
(4,757 Views)

You could, for example, use the functions in the Formatting and I/O library, SetFilePtr and ReadLine.

0 Kudos
Message 4 of 10
(4,751 Views)

... or fsetpos and fgets if you prefere to use functions from ANSI C library



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 10
(4,749 Views)

Finally, this solution is quite complicated. I have already written all the code to select the section i wanted from the file, doing the same thing for the ASCII file would take me more time.

 

I tried to create a temporary file in which i will copy my Initext and delete the tag once I got its value, but the program bugs and it seems that it always get only the first value, which is supposed to be deleted ?

 

 

  if (stricmp (modeaffiche, "ENUM") ==0)
       { 
       
           Ini_WriteToFile (IniTrames, "c:\\Documents and Settings\\PY\\Desktop\\projet\\scenario\\temp_messageries");
       
       for ( ienumindex=2;ienumindex<=(nbitemsignal-2)  ;ienumindex++)
        
         { Ini_NthItemName (IniTrames, titre_signal, ienumindex, &plistenum);
           if ( strcmp(plistenum, "LISTENUM") == 0 )
            
               {                   IniTemp = Ini_New (0);
            
          Ini_ReadFromFile (IniTemp, "c:\\Documents and Settings\\Y\\Desktop\\projet\\scenario\\temp_messageries");
            
            
              Ini_GetStringIntoBuffer (IniTrames, titre_signal, plistenum, nomenum, 100) ;
            GetIndexFromValue (panelHandle, PANEL_TREE_SIGNALS, &listenumindex, isignalindex2);
            ienumvalue= 20000+ienumindex-2;
           InsertTreeItem (panelHandle, PANEL_TREE_SIGNALS, VAL_CHILD, listenumindex, VAL_LAST, nomenum, "", NULL, ienumvalue);
            SetTreeItemAttribute (panelHandle, PANEL_TREE_SIGNALS, listenumindex, ATTR_COLLAPSED, 1);
            Ini_RemoveItem (IniTemp, titre_signal, plistenum);
            
            
            
            //-----------ecriture dans un fichier temporaire
          Ini_WriteToFile (IniTemp, "c:\\Documents and Settings\\PY\\Desktop\\projet\\scenario\\temp_messageries");
          Ini_Dispose (IniTemp);              }  }}

 

0 Kudos
Message 6 of 10
(4,742 Views)

As I already told you, Ini_ReadFromFile skips duplicated items in the file, so once read you have only one element in memory for any given name; calling Ini_WriteToFile will generate a file with that only element written to.

 

An alternative solution is to use x = Ini_LineOfLastAccess (iniTextHandle); immediately after the Ini_Getxxx function of your interest, saving the line returned from the command; after this you can open the file, read and discard 'x' lines and start reading after that to collect your values. You must be sure that the lines are organized in the proper way for this method to succeed. It is to be noted, additionally, that the connection between each element and the line in the file is calculated during Ini_ReadFromFile process and is not dynamically maintained afterwards: that is, adding or deleting lines from the file has no effect on the value returned by that function.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 10
(4,733 Views)

Ok, thank you !  But how can I use the value returned by "Ini_LineOfLastAccess", there is no function to start reading a file from a certain line, right ?

0 Kudos
Message 8 of 10
(4,726 Views)
Solution
Accepted by topic author Verveine

As you can read in my last post, you must read and discard 'x' lines:

 

OpenFile ()

 

// Skip lines

for (i = 0; i < x; i++) ReadLine ()

 

// Start reading useful lines

ReadLine ()   // read a line

...    // Interpret the line

 

 

Don't forget to add a robust error checking during I/O operations and to check for end-of-file.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 10
(4,720 Views)

It works ! 🙂  Thank you so much for your help !

0 Kudos
Message 10 of 10
(4,703 Views)