FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour reading ini file
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
reading ini file
Posted: Wed Apr 15, 2009 05:34 PM

if I have a INI FILe
and I have on a group
I not Know How many record are on this group

hOW i CAN READ how many lines are on group TESTFILE ?

sample inifile:

[GENERAL]
EXETITLE="GENERAL TEST"

[TESTFILE]
1="UNO.TXT"
2="DUE.TXT"
3="TRE.TXT"
4="QUATTRO.TXT"

Best Regards, Saludos



Falconi Silvio
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: reading ini file
Posted: Wed Apr 15, 2009 06:38 PM

Silvio,

METHOD LeeIni() CLASS main
local oIni
INI oIni FILE ".\Sysctrl.Ini"
GET cFile1 SECTION "TESTFILE" ENTRY "1" OF oIni DEFAULT "UNO.TXT"
GET cFile2 SECTION "TESTFILE" ENTRY "2" OF oIni DEFAULT "DOS.TXT"
GET cFile3 SECTION "TESTFILE" ENTRY "3" OF oIni DEFAULT "TRES.TXT"
GET cFile4 SECTION "TESTFILE" ENTRY "4" OF oIni DEFAULT "CUATRO.TXT"
ENDINI

msginfo( cFile1 )

RETURN ( nil )

saludos

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: reading ini file
Posted: Wed Apr 15, 2009 09:31 PM
Silvio,

You can count section-entrys with opening the INI as a text-file

Code (fw): Select all Collapse
function Main()
local oFile  := TTxtFile():New( "Silvio.ini" ), n

nLEN := oFile:RecCount() 
oFile:GoTop()
nCOUNT := 0
FOR n = 1 to nLEN
   // Scan, until You reach the needed section
   //-------------------------------------------------
   IF ALLTRIM(oFile:ReadLine()) = "[TESTFILE]"
      // Start the counter with the next line after the entry
      // ----------------------------------------------------------- 
      oFile:Skip()
      // Loop the section until reach a empty line or next section
      //-------------------------------------------------------------------
      DO WHILE .T.
         // Exit on empty line or next section
         // -------------------------------------------
         IF SUBSTR(ALLTRIM(oFile:ReadLine()),1,1) = " " .or. ;
            SUBSTR(ALLTRIM(oFile:ReadLine()),1,1) = "["
            EXIT
         ELSE
              // Count the section line
              // --------------------------
              nCOUNT++
         ENDIF
         oFile:Skip()
     ENDDO
     EXIT
   ENDIF
   oFile:Skip()
NEXT
oFile:Close()

MsgAlert( nCount, "Section entrys in [TESTFILE]" )

RETURN( NIL )


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: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: reading ini file
Posted: Wed Apr 15, 2009 10:31 PM
Code (fw): Select all Collapse
FUNCTION GETPVPROFSECTION( cSection, cIniFile )

    LOCAL cKeys := STRTRAN( GETPVPROFSTRING( cSection, , "", cIniFile ), CHR( 0 ), CRLF )

    LOCAL aKeys := {}

    LOCAL i

    FOR i = 1 TO MLCOUNT( cKeys )
        AADD( aKeys, RTRIM( MEMOLINE( cKeys, , i ) ) )
    NEXT

    RETURN aKeys


EMG
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: reading ini file
Posted: Thu Apr 16, 2009 10:20 AM

thanks Emg and Uwe

Best Regards, Saludos



Falconi Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: reading ini file
Posted: Thu Apr 16, 2009 11:19 AM

Sorry I try this :

function Main()

local oBar
lOCAL cIniFile :="testfile.ini"

cKeys := STRTRAN( GETPVPROFSTRING( "Areas", , "", cIniFile ), CHR( 0 ), CRLF )
? cKeys

aAreas:=GETPVPROFSECTION("Areas", cIniFile )
return nil

it not run ok
it me return a value 0

Best Regards, Saludos



Falconi Silvio
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: reading ini file
Posted: Thu Apr 16, 2009 11:29 AM
Silvio wrote:lOCAL cIniFile :="testfile.ini"


Code (fw): Select all Collapse
lOCAL cIniFile :=".\testfile.ini"


EMG
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: reading ini file
Posted: Thu Apr 16, 2009 01:04 PM

ooppss...

Best Regards, Saludos



Falconi Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: reading ini file
Posted: Thu Apr 16, 2009 01:09 PM

Now run but I need also the record of each lines

function Main()
lOCAL cIniFile :=".\testfile.rrr"
Local nAreas := STRTRAN( GETPVPROFSTRING( "Areas", , "", cIniFile ), CHR( 0 ), CRLF ) // return 3
Local aAreas :=GETPVPROFSECTION( "Areas", cIniFile )

I want save on each aAreas[nArea] the caption

Best Regards, Saludos



Falconi Silvio
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: reading ini file
Posted: Fri Apr 17, 2009 11:57 AM
Silvio,

you can try this to get the entry and its value

Code (fw): Select all Collapse
FOR i = 1 TO MLCOUNT( cKeys )
     AADD( aKeys, RTRIM( MEMOLINE( cKeys, , i ) ) )
     aEntry := StrToken (aKeys[i],1,"=")
     aValue := StrToken (aKeys[i],2,"=")
NEXT
kind regards

Stefan
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: reading ini file
Posted: Fri Apr 17, 2009 02:10 PM
Silvio wrote:Now run but I need also the record of each lines

function Main()
lOCAL cIniFile :=".\testfile.rrr"
Local nAreas := STRTRAN( GETPVPROFSTRING( "Areas", , "", cIniFile ), CHR( 0 ), CRLF ) // return 3
Local aAreas :=GETPVPROFSECTION( "Areas", cIniFile )

I want save on each aAreas[nArea] the caption


Code (fw): Select all Collapse
Local aValues := {}
Local i

FOR i = 1 TO nAreas
    AADD( aValues, GETPVPROFSTRING( "Areas", aAreas[ i ], "", cIniFile ) )
NEXT


EMG
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: reading ini file
Posted: Sat Apr 18, 2009 01:21 PM
thanks enrico but perhaps I made some errors

firt I must found the total of Lines
I made this :


Code (fw): Select all Collapse
function Main()

   local oBar
   lOCAL cIniFile :=".\recibo.INI"
   Local nAreas := STRTRAN( GETPVPROFSTRING( "Areas", , "", cIniFile ), CHR( 0 ), CRLF )
   Local aAreas  := GETPVPROFSECTION( "Areas", cIniFile )
   Local aValues := {}
   Local i

    ?  nAreas

    // found each string
    FOR i = 1 TO nAreas
    AADD( aValues, GETPVPROFSTRING( "Areas", aAreas[ i ], "", cIniFile ) )
    NEXT

     ?aValues[1]
return nil

the first ? nAreas not give me the total of lines but a message with
1
2
3

while the second part run ok

// found each string of each lines

FOR i = 1 TO nAreas
AADD( aValues, GETPVPROFSTRING( "Areas", aAreas[ i ], "", cIniFile ) )
NEXT


FILE INI RECIBO.INI
[General]
Title=Recibo

[Areas]
1=.\RECIBO.V01
2=.\RECIBO.V02
3=.\RECIBO.V03
Best Regards, Saludos



Falconi Silvio
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: reading ini file
Posted: Sat Apr 18, 2009 01:35 PM
Silvio wrote:Local nAreas := STRTRAN( GETPVPROFSTRING( "Areas", , "", cIniFile ), CHR( 0 ), CRLF )
Local aAreas := GETPVPROFSECTION( "Areas", cIniFile )


Code (fw): Select all Collapse
Local aAreas := GETPVPROFSECTION( "Areas", cIniFile )
Local nAreas := LEN( aAreas )


EMG
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: reading ini file
Posted: Sat Apr 18, 2009 03:03 PM
thanks Emg
Now run ok

then I made this

DEFINE WINDOW oWnd TITLE "TEST window GENERATION" MDI HSCROLL



For i=1 to Len( aFileArea)

cTitleArea :=GetPvProfString("General", "Title","", aFileArea[i])
nWidthArea := VAL(GetPvProfString("General", "Width","", aFileArea[i]))
nHeightArea := VAL(GetPvProfString("General", "Height","", aFileArea[i]))
GenChild( cTitleArea,nWidthArea,nHeightArea)
NEXT

ACTIVATE WINDOW oWnd MAXIMIZED


function GenChild( cTitle,nWidth,nHeight)
local oWndChild

DEFINE WINDOW oWndChild OF oWnd MDICHILD FROM 0,0 TO nHeight/2.5,180 COLOR "N/W" TITLE cTitle

ACTIVATE WINDOW oWndChild
return nil



the procedure puts the windows one above the other,
and I can not understand where are the windows,
how can I do to put the first window then the second on the order and vertical ?
Best Regards, Saludos



Falconi Silvio

Continue the discussion