Reading a ini file
Reading a ini file
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 ?
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
Falconi Silvio
-
- Posts: 363
- Joined: Wed Feb 15, 2006 2:06 pm
- Location: Oxford, England
Re: Reading a ini file
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
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
-
- Posts: 1033
- Joined: Fri Oct 07, 2005 3:33 pm
- Location: Cochabamba - Bolivia
Re: Reading a ini file
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
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
Re: Reading a ini file
Marcello, I not Know How Many Entries I have
Best Regards, Saludos
Falconi Silvio
Falconi Silvio
Re: Reading a ini file
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?
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
Falconi Silvio
Re: Reading a ini file
Dear silvio,
INI file
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
Code: Select all
//----------------------------------------------------------------------------------
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.
Code: Select all
[DATABASECONNECTION]
DBName="payroll"
ServerName="195.168.0.999"
DriverName="Driver={MySQL ODBC 5.1 Driver}"
PortAddress="3306"
DBUser="root"
DBPassword="1234"
u will get the data s belonging to these name.no need to look at the line.
Hope u got it.
Regards,
sajith
- gkuhnert
- Posts: 274
- Joined: Fri Apr 04, 2008 1:25 pm
- Location: Aachen - Germany // Kerkrade - Netherlands
- Contact:
Re: Reading a ini file
Maybe this function can help you?
Code: Select all
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
-
- Posts: 363
- Joined: Wed Feb 15, 2006 2:06 pm
- Location: Oxford, England
Re: Reading a ini file
Change your code to: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?
cEntries := StrTran(GetPvProfString(,"AREAS","","", cIniFile) , Chr(0), CRLF)
Make sure cIniFile is drive & full path as well as inifile name
Pete
-
- Posts: 363
- Joined: Wed Feb 15, 2006 2:06 pm
- Location: Oxford, England
Re: Reading a ini file
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
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
Re: Reading a ini file
#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 :
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)
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 :
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
Falconi Silvio
- gkuhnert
- Posts: 274
- Joined: Fri Apr 04, 2008 1:25 pm
- Location: Aachen - Germany // Kerkrade - Netherlands
- Contact:
Re: Reading a ini file
Silvio,
did you try my suggestion to use "GetPvProfA" which gives you all entries to a section in an array?
did you try my suggestion to use "GetPvProfA" which gives you all entries to a section in an array?
Re: Reading a ini file
Gilbert,
where I can load the function GETPVPROFA ?
Error: Unresolved external '_HB_FUN_GETPVPROFA' referenced from C:\WORK\ERRORI\TEST_INI\OBJ\TEST.OBJ
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
Falconi Silvio
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Reading a ini file
I believe mlcount() uses chr(0) to count the lines. Try not removing the chr(0)'s before calling mlcount().
James
James
- gkuhnert
- Posts: 274
- Joined: Fri Apr 04, 2008 1:25 pm
- Location: Aachen - Germany // Kerkrade - Netherlands
- Contact:
Re: Reading a ini file
Found this function in C in my source code: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
Code: Select all
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++;
}
}