Reading a ini file

Reading a ini file

Postby Silvio » Mon Oct 12, 2009 8:26 am

can see how many line there are for a topic ?
sample

[DATA]
1=bla bla
2=bla bla
3=bla ble
4=bla bla
5=bla bla

But I not Know if there are 5 lines or 4 lines . Can I see it ?
Best Regards, Saludos

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

Re: Reading a ini file

Postby PeterHarmes » Mon Oct 12, 2009 11:25 am

Silvio,

Try this:

LOCAL cEntries := StrTran(GetPVProfString(<Header>, , ,<Full Path & ini file>), Chr(0), CRLF)

for example:

cEntries := StrTran(GetPVProfString("DATA", , ,"c:\app\inifile.INI"), Chr(0), CRLF)

This should return the number of entries:

? MlCount(cEntries)

Regards,

Pete
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Reading a ini file

Postby Marcelo Via Giglio » Mon Oct 12, 2009 11:40 am

Hi,

an idea only:

you can try to read from 1 to n ini entries, but test before every read this way you can know how many lines you have in the ini file

Another possible solution, add other section with line information

[CONTROL]
lines=5
[DATA]
1=bla bla
2=bla bla
3=bla ble
4=bla bla
5=bla bla

regards

Marcelo
Marcelo Via Giglio
 
Posts: 1051
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Reading a ini file

Postby Silvio » Mon Oct 12, 2009 12:16 pm

Marcello, I not Know How Many Entries I have
Best Regards, Saludos

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

Re: Reading a ini file

Postby Silvio » Mon Oct 12, 2009 12:22 pm

I made :

Function test()
Local cNSys:="TEST"
Local INI:=cIniFile := cFilePath( GetModuleFileName( GetInstance() ) ) + cNSys+".ini"
Local cEntries := StrTran(GetPvProfString(cNSys,"AREAS","", cIniFile) , Chr(0), CRLF)
?MlCount(cEntries)
return nil

this test retun 0 but there are 6 lines on test.ini

Test.ini
[AREAS]
1=WFL.T01
2=WFL.T02
3=WFL.T03
4=WFL.T06
5=WFL.T04
6=WFL.T05


Any Idea?
Best Regards, Saludos

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

Re: Reading a ini file

Postby sajith » Mon Oct 12, 2009 12:48 pm

Dear silvio,

Code: Select all  Expand view


//----------------------------------------------------------------------------------
FUNCTION   SetConnection()     //###########   FOR DATABASE CONNECTION FROM INI  ###############
//-----------------------------------------------------------------------------------

   lOCAL cIniFile :="Ini\INIDBConnection.INI"
   if !File(cIniFile)
      MsgBox("Connection File Does Not Exist")
      RETURN .F.
  END IF

    oApp:cDbServerIP:=AllTrim(GETPVPROFSTRING( "DATABASECONNECTION","ServerName" , "", cIniFile))
    oApp:cDbName    :=Alltrim(GETPVPROFSTRING( "DATABASECONNECTION","DBName" , "", cIniFile ))
    oApp:cDbUser    :="root"
    oApp:cDbPassword:=Alltrim(GETPVPROFSTRING( "DATABASECONNECTION","DBPassword" , "", cIniFile ))
    oApp:cDbPort    :=Alltrim(GETPVPROFSTRING( "DATABASECONNECTION","PortAddress" , "", cIniFile ))
    oApp:cDriver    :=Alltrim(GETPVPROFSTRING( "DATABASECONNECTION","DriverName" , "", cIniFile ))


   oApp:cConnectSring:=oApp:cDriver+";"+"Server="+oApp:cDbServerIP+";"+"Port="+oApp:cDbPort+       ;
                    ";"+"Database="+oApp:cDbName+";"+"User="+oApp:cDbUser+";"+                     ;
                    "Password="+oApp:cDbPassword+";"+"Option=3;"

  oApp:oConnection:=CreateObject("ADODB.Connection")
  oApp:oConnection:ConnectionString:=oApp:cConnectSring
  CursorWait()
  TRY
     oApp:oConnection:Open()

  CATCH oError
    MsgBox("Failed to Open connection")
    RETURN .F.
  END
  CursorArrow()
  oError:=NIL

RETURN .T.

 


INI file

Code: Select all  Expand view

[DATABASECONNECTION]
DBName="payroll"  
ServerName="195.168.0.999"
DriverName="Driver={MySQL ODBC 5.1 Driver}"
PortAddress="3306"
DBUser="root"
DBPassword="1234"
 

here is the sample to read data frm Ini.here the importance is the name(DBName,--------,DBPassword)frm these name
u will get the data s belonging to these name.no need to look at the line.
Hope u got it.

Regards,
sajith
sajith
 
Posts: 110
Joined: Wed Feb 18, 2009 9:58 am
Location: India

Re: Reading a ini file

Postby gkuhnert » Mon Oct 12, 2009 1:02 pm

Maybe this function can help you?

Code: Select all  Expand view
FUNCTION GetIniArray(cSection,cFile)        // reads a complete section from a *.ini file into an array
LOCAL nI
LOCAL aString := {}

    aEntry := GetPvProfA(cSection,NIL, "", cFile)

    IF EMPTY(aEntry)
        return {}
    ENDIF
    for nI:=1 to LEN(aEntry)
        AADD(aString,GetPvProfString(cSection,aEntry[nI],"",cFile))
    next
return aString
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Reading a ini file

Postby PeterHarmes » Mon Oct 12, 2009 1:06 pm

Silvio wrote:I made :

Function test()
Local cNSys:="TEST"
Local INI:=cIniFile := cFilePath( GetModuleFileName( GetInstance() ) ) + cNSys+".ini"
Local cEntries := StrTran(GetPvProfString(cNSys,"AREAS","", cIniFile) , Chr(0), CRLF)
?MlCount(cEntries)
return nil

this test retun 0 but there are 6 lines on test.ini

Test.ini
[AREAS]
1=WFL.T01
2=WFL.T02
3=WFL.T03
4=WFL.T06
5=WFL.T04
6=WFL.T05


Any Idea?


Change your code to:

cEntries := StrTran(GetPvProfString(,"AREAS","","", cIniFile) , Chr(0), CRLF)

Make sure cIniFile is drive & full path as well as inifile name

Pete
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Reading a ini file

Postby Silvio » Mon Oct 12, 2009 3:20 pm

gime me 0
Best Regards, Saludos

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

Re: Reading a ini file

Postby PeterHarmes » Mon Oct 12, 2009 3:38 pm

What does GetPvProfString("AREAS","","", cIniFile) return? if it contains all of the [AREAS] section of the ini file, maybe you could count the number of "=" in the returned string?

Regards,

Pete

oops just noticed i made a mistake on previous message - make sure your code is GetPvProfString("AREAS","","", cIniFile) not GetPvProfString(,"AREAS","","", cIniFile) - sorry :oops:
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Reading a ini file

Postby Silvio » Mon Oct 12, 2009 5:17 pm

#include "Fivewin.ch"

Function test()
Local cNSys:="TEST"
Local INI:=cIniFile := cFilePath( GetModuleFileName( GetInstance() ) ) + cNSys+".ini"
Local cEntries := StrTran(GetPvProfString("AREAS","","", cIniFile) , Chr(0), CRLF)
?MlCount(cEntries)
return nil

It Return 0

As U can see here :

Image


I must count How many entries there are on [areas]
then I must read the name of each entries

sample
[AREAS]
1=FIRST.T01
2=SECOND.T02
3=THIRD.T03

THE COUNT MUST BE 3
BUT i NOT kNOW hOW MANY ENTRIES i FOUND ON TEST.INI


then i must read the name of each entries because I load each file
sample : I must open first.to1 only on this last file I Know each entries( areaheight,areawidth,areaTitle)
Best Regards, Saludos

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

Re: Reading a ini file

Postby gkuhnert » Tue Oct 13, 2009 10:05 am

Silvio,

did you try my suggestion to use "GetPvProfA" which gives you all entries to a section in an array?
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Reading a ini file

Postby Silvio » Tue Oct 13, 2009 11:34 am

Gilbert,
where I can load the function GETPVPROFA ?
Error: Unresolved external '_HB_FUN_GETPVPROFA' referenced from C:\WORK\ERRORI\TEST_INI\OBJ\TEST.OBJ
Best Regards, Saludos

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

Re: Reading a ini file

Postby James Bott » Tue Oct 13, 2009 11:36 am

I believe mlcount() uses chr(0) to count the lines. Try not removing the chr(0)'s before calling mlcount().

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Reading a ini file

Postby gkuhnert » Wed Nov 11, 2015 3:00 pm

Silvio wrote:Gilbert,
where I can load the function GETPVPROFA ?
Error: Unresolved external '_HB_FUN_GETPVPROFA' referenced from C:\WORK\ERRORI\TEST_INI\OBJ\TEST.OBJ


Found this function in C in my source code:

Code: Select all  Expand view
HB_FUNC( GETPVPROFA )
{
CHAR bBuffer[ 2048 ];
WORD wLen;
WORD anzahl;
WORD pos,i;

    wLen = GetPrivateProfileString( hb_parc( 1 ),     // Section
                              NULL,     // Entry
                           hb_parc( 3 ),     // Default
                           bBuffer,        // Destination Buffer
                           sizeof( bBuffer ) - 1,   // M x Len
                           hb_parc( 4 ) );   // INI File
    anzahl=0;
    for(pos=0;pos<wLen;pos++)
        {
        if(bBuffer[pos]==0)
            {
            anzahl++;
            if(bBuffer[pos+1]==0) break;
            }
        }
    if(anzahl==0) hb_ret();

    hb_reta(anzahl);
    pos=0;
    for(i=0;i<anzahl;i++)
        {
        hb_storc(bBuffer+pos, -1, i+1 ); // hb_storc, umgestellt auf fwh1502
        while(pos<wLen && bBuffer[pos]!=0) pos++;
        pos++;
        }
}
 
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Rick Lipkin and 36 guests