FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Counting Entries of INI-section ?
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Counting Entries of INI-section ?
Posted: Sun Aug 26, 2012 03: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 (fw): Select all Collapse
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 (fw): Select all Collapse
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.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Counting Entries of INI-section ?
Posted: Sun Aug 26, 2012 05:03 PM
Uwe,

Its simpler if you just check for an empty entry:

Code (fw): Select all Collapse
   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
Posts: 222
Joined: Mon Jun 04, 2012 12:00 PM
Re: Counting Entries of INI-section ?
Posted: Sun Aug 26, 2012 06: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
Posts: 222
Joined: Mon Jun 04, 2012 12:00 PM
Re: Counting Entries of INI-section ?
Posted: Sun Aug 26, 2012 06:59 PM

Antonio,
resolved !!

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Counting Entries of INI-section ?
Posted: Tue Aug 28, 2012 06: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.

Continue the discussion