reading ini file

reading ini file

Postby Silvio » Wed Apr 15, 2009 5: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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: reading ini file

Postby sysctrl2 » Wed Apr 15, 2009 6: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 "
User avatar
sysctrl2
 
Posts: 1020
Joined: Mon Feb 05, 2007 7:15 pm

Re: reading ini file

Postby ukoenig » Wed Apr 15, 2009 9:31 pm

Silvio,

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

Code: Select all  Expand view

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 :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

Re: reading ini file

Postby Enrico Maria Giordano » Wed Apr 15, 2009 10:31 pm

Code: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: reading ini file

Postby Silvio » Thu Apr 16, 2009 10:20 am

thanks Emg and Uwe
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: reading ini file

Postby Silvio » 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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: reading ini file

Postby Enrico Maria Giordano » Thu Apr 16, 2009 11:29 am

Silvio wrote:lOCAL cIniFile :="testfile.ini"


Code: Select all  Expand view
lOCAL cIniFile :=".\testfile.ini"


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: reading ini file

Postby Silvio » Thu Apr 16, 2009 1:04 pm

ooppss...
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: reading ini file

Postby Silvio » Thu Apr 16, 2009 1: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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: reading ini file

Postby StefanHaupt » Fri Apr 17, 2009 11:57 am

Silvio,

you can try this to get the entry and its value

Code: Select all  Expand view
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
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: reading ini file

Postby Enrico Maria Giordano » Fri Apr 17, 2009 2: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: Select all  Expand view
Local aValues := {}
Local i

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


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: reading ini file

Postby Silvio » Sat Apr 18, 2009 1:21 pm

thanks enrico but perhaps I made some errors

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


Code: Select all  Expand view
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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: reading ini file

Postby Enrico Maria Giordano » Sat Apr 18, 2009 1:35 pm

Silvio wrote:Local nAreas := STRTRAN( GETPVPROFSTRING( "Areas", , "", cIniFile ), CHR( 0 ), CRLF )
Local aAreas := GETPVPROFSECTION( "Areas", cIniFile )


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


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: reading ini file

Postby Silvio » Sat Apr 18, 2009 3: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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 73 guests