Counting Entries of INI-section ?

Counting Entries of INI-section ?

Postby ukoenig » Sun Aug 26, 2012 3:59 pm

Hello,

I wanted to count the Entries < System > from File < Settings.ini >
I could count the Textlines, but why it doesn't work ?

I tested from INI-file < SETTINGS.INI >
Section < System > :

[System]
cField_1=Object1,Value 1
cField_2=Object2,Value 2
cField_3=Object3,Value 3

Code: Select all  Expand view

FUNCTION READ_INI()
Local oInifile, nEntries := 1, cEntries := ""

INI oInifile FILE c_path + "\SETTINGS.INI"
    cEntries := StrTran( GetProfString( "System" ), Chr( 0 ), CRLF )
    FOR nEntries = 1 to MlCount( cEntries ) // doesn't count = ZERO
        MsgInfo( GetProfString( "System", MemoLine( cEntries,, nEntries ) ),;
                MemoLine( cEntries,, nEntries ) )   
    NEXT
ENDINI

RETURN NIL
 


The working Sample ( counts Devices from Windows ) :

Code: Select all  Expand view

function Main()

   local cEntries := StrTran( GetProfString( "Devices" ), Chr( 0 ), CRLF )
   local n

   for n = 1 to MlCount( cEntries )
      MsgInfo( GetProfString( "Devices", MemoLine( cEntries,, n ) ),;
               MemoLine( cEntries,, n ) )
   next

return nil
 


Best Regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Counting Entries of INI-section ?

Postby Antonio Linares » Sun Aug 26, 2012 5:03 pm

Uwe,

Its simpler if you just check for an empty entry:

Code: Select all  Expand view

   local aEntries := {}, cValue, n := 1

   while ! Empty( cValue := GetProfString( cSection, "cField_" + AllTrim( Str( n++ ) ) ) )
      AAdd( aEntries, cValue )  
   end
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42089
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Counting Entries of INI-section ?

Postby Eoeo » Sun Aug 26, 2012 6:33 pm

Antonio,
And If I not Know the name of each row ?

please see it

sample :
cSection:="Cars"

[Cars]
Opel=4569390202
Daihatsu=48838929292
Ford=38329494949
Ferrari=2828394949
Lamborghini=334595940202



I need an array with name of Entry and values of each entries








Function Test
Local cInifile := cFilePath(GetModuleFileName( GetInstance() ) ) + "test.ini"
local aEntries := {}, cValue, n := 1
local aString := {}
Local nBottom := 18
Local nRight := 52
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H

cSection:= "Cars"



aEntry := StrTran(GetPVProfString(cSection, , ,cInifile), Chr(0), CRLF)

? MlCount(aEntry)

IF EMPTY(aEntry)
return {}
ENDIF

for nI:=1 to LEN(aEntry)
AADD(aString,GetIni( cInifile, cSection, aEntry[nI]) )
next


* while ! Empty( cValue := GetProfString( cSection, "cField_" + AllTrim( Str( n++ ) ) ) )
* while ! Empty( cValue := GetProfString( cSection, ) ) )
* AAdd( aEntries, cValue )
* end




// I wish see then into a xbrowse

DEFINE DIALOG oDlg ;
SIZE nWidth, nHeight;
TITLE 'Filtri' PIXEL;
GRADIENT { { 1,CLR_WHITE, LIGHTCYAN } } ;
STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_CAPTION, 4 )


@ 30, 10 XBROWSE oLbx OF oDlg ;
SIZE 100,80 PIXEL ;
ARRAY aString AUTOCOLS


WITH OBJECT oLbx
:lRecordSelector := .f.
:aCols[1]:cHeader := i18n("Tipo")
:aCols[2]:cHeader := i18n("Value")
:CreateFromCode()
END


ACTIVATE DIALOG oDlg centered




RETURN NIL




any solution
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: Counting Entries of INI-section ?

Postby Eoeo » Sun Aug 26, 2012 6:59 pm

Antonio,
resolved !!
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: Counting Entries of INI-section ?

Postby ukoenig » Tue Aug 28, 2012 6:44 pm

Antonio,

Thank You very much,
it is working fine now.

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 98 guests