Posted: Thu Sep 26, 2002 1:53 pm
Restored from previous forum. Originally posted by ojahier.
I dont undertand what goes on with my purebasic debugger...after a part a code well executed (in the beginning the debugger indicate correctly all the line code executed )but after it's begin to loop marking all line code ,lines not really executed ??!
I verificate the identation (il else while wend...), it's seems ok.
I think thats the origin of the problem are perhaps the database access (the external instruction sql generated as freehandle ??!!) but i'm not sure.
What do you think of ?
------------------------------------------
XIncludeFile "convmontant.pb"
XIncludeFile "addMontant.pb"
Gosub Inipgm
Gosub iniDB
Gosub AnalyseDriver
If ReadFile(0, FichierEntree.s)
While Eof(0) = 0
tt$.s = ReadString()
Gosub alimRub
If compte.s=cpt$
Input()
If code_enr.s="01"
Anc_solde.s=Montant.s
Else
If code_enr.s="04"
If cd_AFB.s="01"
Gosub Lect_database
;B_emi_num_chq$="0043570"
If numchq.s=B_emi_num_chq$
Input()
If mt_mvt.s=B_emi_montant.s
;Test si lettrage fait
If B_emi_emet.s "L"
; zone lettrée => B_emi_emet.s='L'
Gosub Lettrage_DB
If DatabaseQuery(Command$)
If cd_BNPP.s="0001"
nb1.l=nb1.l+1
LCH_let_cpt.s=AddString(LCH_let_cpt.s,mt_mvt.s)
Else
If cd_BNPP.s="0002"
nb11.l=nb11.l+1
LCH_let_gui.s=AddString(LCH_let_gui.s,mt_mvt.s)
Else
nb3.l=nb3.l+1
ligne_ano.s="chq débité avec cd ope BNPP non répertorié"+""+cd_BNPP
Gosub Ecr_ano
EndIf
EndIf
Else
Gosub PB_maj
EndIf
Else
;cas d'un chq déjà léttré
nb3.l=nb3.l+1
ligne_ano.s="chq débité déjà lettré (second débit) "+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
EndIf
Else
; cas d'un chq débité avec un montant du montant émis
;B_sec_code_ano (zone à toper)
Gosub Topage_DB ; zone topée => B_sec_code_ano='A'
If DatabaseQuery(Command$)
nb2.l=nb2.l+1
LCH_non_let.s=AddString(LCH_non_let.s,mt_mvt.s)
ligne_ano.s="mnt débité mnt émis "+numchq.s+" "+mt_mvt.s+" "+B_emi_montant.s
Gosub Ecr_ano
Else
;Gosub PB_maj
EndIf
EndIf
Else
nb3.l=nb3.l+1
LCH_div_D.s=AddString(LCH_div_D.s,mt_mvt.s)
ligne_ano.s="chq débité non émis "+numchq.s
Gosub Ecr_ano
EndIf
Else
If cd_AFB.s="99"
nb4.l=nb4.l+1
LCH_div_C.s=AddString(LCH_div_C.s,mt_mvt.s)
Gosub Lect_database
If numchq.s=B_emi_num_chq$
mt_mvt.s=Mid(convmontant(Montant.s),2,14)
If mt_mvt.s=B_emi_montant
;le chèque est lettré
If B_emi_emet.s="L"
;zone delettrée => B_emi_emet=' '
Gosub Delettrage_DB
If DatabaseQuery(Command$)
PrintN("delettrage")
Else
Gosub PB_maj
EndIf
Else
ligne_ano.s="régul inapropriée car opé déjà lettrée"+numchq.s
Gosub Ecr_ano
EndIf
Else
ligne_ano.s="régul inapropriée car mnt régul mnt chq émis"+numchq.s
Gosub Ecr_ano
EndIf
Else
ligne_ano.s="régul inapropriée chq non trouvé dans base chq"+numchq.s
Gosub Ecr_ano
EndIf
Else
;opération avec cd AFB "01" et "99"
Gosub Lect_database_cd
If sens.s="D"
nb3.l=nb3.l+1
LCH_div_D.s=AddString(LCH_div_D.s,mt_mvt.s)
ligne_ano.s="opération débit atypique"+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
Else
;crédit
nb4.l=nb4.l+1
LCH_div_C.s=AddString(LCH_div_C.s,mt_mvt.s)
ligne_ano.s="opération crédit atypique"+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
EndIf
EndIf
EndIf
Else
If code_enr.s="07"
Nouv_solde.s=Montant.s
EndIf
EndIf
EndIf
EndIf
Print(numchq.s)
Print(" ")
PrintN(cd_BNPP.s)
Wend
PrintN (anc_solde.s)
PrintN (Nouv_solde.s)
CloseFile(0)
CloseFile(1)
Else
MessageRequester("CPAM", "impossible d'ouvrir le fichier", #PB_MessageRequester_Ok)
EndIf
End
;---------------------
;Corps du pgm
;---------------------
;---------------------
;sous programme
;---------------------
alimRub:
compte.s=Mid(tt$.s,22,11)
code_enr.s=Mid(tt$.s,1,2)
date_oper.s=Mid(tt$.s,35,6)
Montant.s=Mid(tt$.s,91,14)
cd_AFB.s=Mid(tt$.s,33,2)
numchq.s=Mid(tt$.s,82,7)
cd_BNPP.s=Mid(tt$.s,8,4)
mt_mvt.s=Mid(convmontant(Montant.s),2,14)
Return
Inipgm:
OpenConsole()
ClearConsole()
cd4$="04"
cd1$="01"
cpt$="00016w33w76"
#Fichier=1
Fichier$ = "0108cpam2"
FichierEntree.s = "C:\dgd\CPAM\" + Fichier$ + ".txt"
nb1.l=0
nb11.l=0
nb2.l=0
nb3.l=0
nb4.l=0
LCH_let_cpt.s=""
LCH_let_gui.s=""
LCH_div_D.s=""
LCH_div_C.s=""
LCH_non_let.s=""
Anc_solde.s=""
Nouv_solde.s=""
Montant.s=""
ligne_ano.s=""
sens.s=""
Return
Ecr_ano:
If CreateFile(1, "CPAM_ano.txt")
WriteStringN(ligne_ano.s)
Else
MessageRequester("Denotage CPAM", "Error: can't write the file", 1)
End
EndIf
Return
Lect_ano:
If ReadFile(1, "CPAM_ano.txt")
First$ = Trim(ReadString()) ; trim supprime les espaces avant et après
MessageRequester("PureBasic", "Line read: "+First$, 1)
CloseFile(1)
Else
MessageRequester("Denotage CPAM", "Error: Can't read the file", 0)
EndIf
WriteStringN(Texte$)
Return
;---------------------------------------------------------------------
;Lecture base cheque
;---------------------------------------------------------------------
iniDB :
If InitDatabase() = 0
MessageRequester("Error", "Can't initialize Database (ODBC v3 or better) environment", 0)
End
EndIf
Dim DatabaseType.s(4)
DatabaseType(0) = "Unknown"
DatabaseType(1) = "Numeric"
DatabaseType(2) = "String"
DatabaseType(3) = "Float"
Return
; First, let's see which drivers are attached to the system..
;
AnalyseDriver:
If ExamineDatabaseDrivers()
While NextDatabaseDriver()
PrintN(DatabaseDriverName()+" - "+DatabaseDriverDescription())
Wend
EndIf
Return
Lect_database:
If OpenDatabase(0,"bd1.mdb","m907052","wwww0002")
Command$="select * from extract where B_emi_num_chq="+"'"+numchq.s+"'"+";"
If DatabaseQuery(Command$)
While NextDatabaseRow()
B_emi_num_chq$=GetDatabaseString(2)
B_mont.f=GetDatabaseFloat(6)
B_ms_correct.l=GetDatabaseLong(21)
B_rej_perime.l=GetDatabaseLong(57)
B_emi_benef$=GetDatabaseString(5)
B_emi_emet.s=GetDatabaseString(0)
B_emi_montant.s=Str(B_mont.f)
B_emi_montant.s=Right("00000000000000"+B_emi_montant.s, 14)
Wend
EndIf
Else
MessageRequester("Info", "Operation canceled", 0)
EndIf
Return
Lettrage_DB:
Command$="update extract set B_emi_emet='L' where B_emi_num_chq="+"'"+numchq.s+"'"+";"
Return
Delettrage_DB:
Command$="update extract set B_emi_emet=' ' where B_emi_num_chq="+"'"+numchq.s+"'"+";"
Return
Topage_DB:
Command$="update extract set B_sec_code_ano='A' where ="+"'"+numchq.s+"'"+";"
Return
PB_maj:
MessageRequester("CPAM", "Pb de maj table : arret TRT", #PB_MessageRequester_Ok)
End
Return
;---------------------------------------------------------------------
;Lecture base cd bnpp
;---------------------------------------------------------------------
Lect_database_cd:
If OpenDatabase(0,"bd1.mdb","m907052","wwww0002")
Command$="select * from cdBNPP where Code_BNP="+"'"+cd_BNPP.s+"'"+";"
If DatabaseQuery(Command$)
While NextDatabaseRow()
SENS_DEBIT.s=GetDatabaseString(2)
SENS_CREDIT.s=GetDatabaseString(3)
If SENS_DEBIT.s="débit"
sens.s="D"
Else
If SENS_CREDIT.s="crédit"
sens.s="C"
EndIf
EndIf
If sens.s "D" And sens.s "C"
MessageRequester("Info", "Operation canceled: sens comptable non déterminé", 0)
End
EndIf
Wend
EndIf
Else
MessageRequester("Info", "Operation canceled", 0)
EndIf
Return
----------------------------
source of addmontant :
Structure CharType
Char.b
EndStructure
Procedure.s AddString(arg1.s, arg2.s)
DefType.CharType *p1, *p2, *pend1, *pend2
sum.s = "" : carry.l = 0
arg1 = "0" + arg1 : arg2 = "0" + arg2
a1 = FindString(arg1, ".", 1)
a2 = FindString(arg2, ".", 1)
If a1 Or a2
If a1 : l1 = Len(arg1) - a1 : Else : arg1 + "." : EndIf
If a2 : l2 = Len(arg2) - a2 : Else : arg2 + "." : EndIf
If l1 l2
If l1 > l2
diff = l1 - l2
sum = Right(arg1, diff)
arg1 = Left(arg1, Len(arg1)-diff)
ElseIf l2 > l1
diff = l2 - l1
sum = Right(arg2, diff)
arg2 = Left(arg2, Len(arg2)-diff)
EndIf
EndIf
EndIf
*pend1 = @arg1 : *p1 = *pend1 + Len(arg1) - 1
*pend2 = @arg2 : *p2 = *pend2 + Len(arg2) - 1
Repeat
If *p1\Char = '.'
sum = "." + sum
Else
tmp = *p1\Char - '0' + *p2\Char - '0' + carry
If tmp >= 10
carry = 1
tmp - 10
Else
carry = 0
EndIf
sum = Chr(tmp + '0') + sum
EndIf
If *p1 > *pend1 : *p1 - 1 : EndIf
If *p2 > *pend2 : *p2 - 1 : EndIf
Until *p1 = *pend1 And *p2=*pend2
If carry
sum = Chr(carry + '0') + sum
EndIf
ProcedureReturn sum
EndProcedure
; Example 1
;b1.s = "1.123456789"
;b2.s = "2.111111111"
;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum
; Example 2
;b1.s = "999999999"
;b2.s = "1"
;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum
;Example 3
;b1.s = "12345678901234"
;b2.s = "1501"
;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum
-------------------------------
Commo estan? Bien ? Me alegro!
(registered PureBasic user)
I dont undertand what goes on with my purebasic debugger...after a part a code well executed (in the beginning the debugger indicate correctly all the line code executed )but after it's begin to loop marking all line code ,lines not really executed ??!
I verificate the identation (il else while wend...), it's seems ok.
I think thats the origin of the problem are perhaps the database access (the external instruction sql generated as freehandle ??!!) but i'm not sure.
What do you think of ?
------------------------------------------
XIncludeFile "convmontant.pb"
XIncludeFile "addMontant.pb"
Gosub Inipgm
Gosub iniDB
Gosub AnalyseDriver
If ReadFile(0, FichierEntree.s)
While Eof(0) = 0
tt$.s = ReadString()
Gosub alimRub
If compte.s=cpt$
Input()
If code_enr.s="01"
Anc_solde.s=Montant.s
Else
If code_enr.s="04"
If cd_AFB.s="01"
Gosub Lect_database
;B_emi_num_chq$="0043570"
If numchq.s=B_emi_num_chq$
Input()
If mt_mvt.s=B_emi_montant.s
;Test si lettrage fait
If B_emi_emet.s "L"
; zone lettrée => B_emi_emet.s='L'
Gosub Lettrage_DB
If DatabaseQuery(Command$)
If cd_BNPP.s="0001"
nb1.l=nb1.l+1
LCH_let_cpt.s=AddString(LCH_let_cpt.s,mt_mvt.s)
Else
If cd_BNPP.s="0002"
nb11.l=nb11.l+1
LCH_let_gui.s=AddString(LCH_let_gui.s,mt_mvt.s)
Else
nb3.l=nb3.l+1
ligne_ano.s="chq débité avec cd ope BNPP non répertorié"+""+cd_BNPP
Gosub Ecr_ano
EndIf
EndIf
Else
Gosub PB_maj
EndIf
Else
;cas d'un chq déjà léttré
nb3.l=nb3.l+1
ligne_ano.s="chq débité déjà lettré (second débit) "+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
EndIf
Else
; cas d'un chq débité avec un montant du montant émis
;B_sec_code_ano (zone à toper)
Gosub Topage_DB ; zone topée => B_sec_code_ano='A'
If DatabaseQuery(Command$)
nb2.l=nb2.l+1
LCH_non_let.s=AddString(LCH_non_let.s,mt_mvt.s)
ligne_ano.s="mnt débité mnt émis "+numchq.s+" "+mt_mvt.s+" "+B_emi_montant.s
Gosub Ecr_ano
Else
;Gosub PB_maj
EndIf
EndIf
Else
nb3.l=nb3.l+1
LCH_div_D.s=AddString(LCH_div_D.s,mt_mvt.s)
ligne_ano.s="chq débité non émis "+numchq.s
Gosub Ecr_ano
EndIf
Else
If cd_AFB.s="99"
nb4.l=nb4.l+1
LCH_div_C.s=AddString(LCH_div_C.s,mt_mvt.s)
Gosub Lect_database
If numchq.s=B_emi_num_chq$
mt_mvt.s=Mid(convmontant(Montant.s),2,14)
If mt_mvt.s=B_emi_montant
;le chèque est lettré
If B_emi_emet.s="L"
;zone delettrée => B_emi_emet=' '
Gosub Delettrage_DB
If DatabaseQuery(Command$)
PrintN("delettrage")
Else
Gosub PB_maj
EndIf
Else
ligne_ano.s="régul inapropriée car opé déjà lettrée"+numchq.s
Gosub Ecr_ano
EndIf
Else
ligne_ano.s="régul inapropriée car mnt régul mnt chq émis"+numchq.s
Gosub Ecr_ano
EndIf
Else
ligne_ano.s="régul inapropriée chq non trouvé dans base chq"+numchq.s
Gosub Ecr_ano
EndIf
Else
;opération avec cd AFB "01" et "99"
Gosub Lect_database_cd
If sens.s="D"
nb3.l=nb3.l+1
LCH_div_D.s=AddString(LCH_div_D.s,mt_mvt.s)
ligne_ano.s="opération débit atypique"+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
Else
;crédit
nb4.l=nb4.l+1
LCH_div_C.s=AddString(LCH_div_C.s,mt_mvt.s)
ligne_ano.s="opération crédit atypique"+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
EndIf
EndIf
EndIf
Else
If code_enr.s="07"
Nouv_solde.s=Montant.s
EndIf
EndIf
EndIf
EndIf
Print(numchq.s)
Print(" ")
PrintN(cd_BNPP.s)
Wend
PrintN (anc_solde.s)
PrintN (Nouv_solde.s)
CloseFile(0)
CloseFile(1)
Else
MessageRequester("CPAM", "impossible d'ouvrir le fichier", #PB_MessageRequester_Ok)
EndIf
End
;---------------------
;Corps du pgm
;---------------------
;---------------------
;sous programme
;---------------------
alimRub:
compte.s=Mid(tt$.s,22,11)
code_enr.s=Mid(tt$.s,1,2)
date_oper.s=Mid(tt$.s,35,6)
Montant.s=Mid(tt$.s,91,14)
cd_AFB.s=Mid(tt$.s,33,2)
numchq.s=Mid(tt$.s,82,7)
cd_BNPP.s=Mid(tt$.s,8,4)
mt_mvt.s=Mid(convmontant(Montant.s),2,14)
Return
Inipgm:
OpenConsole()
ClearConsole()
cd4$="04"
cd1$="01"
cpt$="00016w33w76"
#Fichier=1
Fichier$ = "0108cpam2"
FichierEntree.s = "C:\dgd\CPAM\" + Fichier$ + ".txt"
nb1.l=0
nb11.l=0
nb2.l=0
nb3.l=0
nb4.l=0
LCH_let_cpt.s=""
LCH_let_gui.s=""
LCH_div_D.s=""
LCH_div_C.s=""
LCH_non_let.s=""
Anc_solde.s=""
Nouv_solde.s=""
Montant.s=""
ligne_ano.s=""
sens.s=""
Return
Ecr_ano:
If CreateFile(1, "CPAM_ano.txt")
WriteStringN(ligne_ano.s)
Else
MessageRequester("Denotage CPAM", "Error: can't write the file", 1)
End
EndIf
Return
Lect_ano:
If ReadFile(1, "CPAM_ano.txt")
First$ = Trim(ReadString()) ; trim supprime les espaces avant et après
MessageRequester("PureBasic", "Line read: "+First$, 1)
CloseFile(1)
Else
MessageRequester("Denotage CPAM", "Error: Can't read the file", 0)
EndIf
WriteStringN(Texte$)
Return
;---------------------------------------------------------------------
;Lecture base cheque
;---------------------------------------------------------------------
iniDB :
If InitDatabase() = 0
MessageRequester("Error", "Can't initialize Database (ODBC v3 or better) environment", 0)
End
EndIf
Dim DatabaseType.s(4)
DatabaseType(0) = "Unknown"
DatabaseType(1) = "Numeric"
DatabaseType(2) = "String"
DatabaseType(3) = "Float"
Return
; First, let's see which drivers are attached to the system..
;
AnalyseDriver:
If ExamineDatabaseDrivers()
While NextDatabaseDriver()
PrintN(DatabaseDriverName()+" - "+DatabaseDriverDescription())
Wend
EndIf
Return
Lect_database:
If OpenDatabase(0,"bd1.mdb","m907052","wwww0002")
Command$="select * from extract where B_emi_num_chq="+"'"+numchq.s+"'"+";"
If DatabaseQuery(Command$)
While NextDatabaseRow()
B_emi_num_chq$=GetDatabaseString(2)
B_mont.f=GetDatabaseFloat(6)
B_ms_correct.l=GetDatabaseLong(21)
B_rej_perime.l=GetDatabaseLong(57)
B_emi_benef$=GetDatabaseString(5)
B_emi_emet.s=GetDatabaseString(0)
B_emi_montant.s=Str(B_mont.f)
B_emi_montant.s=Right("00000000000000"+B_emi_montant.s, 14)
Wend
EndIf
Else
MessageRequester("Info", "Operation canceled", 0)
EndIf
Return
Lettrage_DB:
Command$="update extract set B_emi_emet='L' where B_emi_num_chq="+"'"+numchq.s+"'"+";"
Return
Delettrage_DB:
Command$="update extract set B_emi_emet=' ' where B_emi_num_chq="+"'"+numchq.s+"'"+";"
Return
Topage_DB:
Command$="update extract set B_sec_code_ano='A' where ="+"'"+numchq.s+"'"+";"
Return
PB_maj:
MessageRequester("CPAM", "Pb de maj table : arret TRT", #PB_MessageRequester_Ok)
End
Return
;---------------------------------------------------------------------
;Lecture base cd bnpp
;---------------------------------------------------------------------
Lect_database_cd:
If OpenDatabase(0,"bd1.mdb","m907052","wwww0002")
Command$="select * from cdBNPP where Code_BNP="+"'"+cd_BNPP.s+"'"+";"
If DatabaseQuery(Command$)
While NextDatabaseRow()
SENS_DEBIT.s=GetDatabaseString(2)
SENS_CREDIT.s=GetDatabaseString(3)
If SENS_DEBIT.s="débit"
sens.s="D"
Else
If SENS_CREDIT.s="crédit"
sens.s="C"
EndIf
EndIf
If sens.s "D" And sens.s "C"
MessageRequester("Info", "Operation canceled: sens comptable non déterminé", 0)
End
EndIf
Wend
EndIf
Else
MessageRequester("Info", "Operation canceled", 0)
EndIf
Return
----------------------------
source of addmontant :
Structure CharType
Char.b
EndStructure
Procedure.s AddString(arg1.s, arg2.s)
DefType.CharType *p1, *p2, *pend1, *pend2
sum.s = "" : carry.l = 0
arg1 = "0" + arg1 : arg2 = "0" + arg2
a1 = FindString(arg1, ".", 1)
a2 = FindString(arg2, ".", 1)
If a1 Or a2
If a1 : l1 = Len(arg1) - a1 : Else : arg1 + "." : EndIf
If a2 : l2 = Len(arg2) - a2 : Else : arg2 + "." : EndIf
If l1 l2
If l1 > l2
diff = l1 - l2
sum = Right(arg1, diff)
arg1 = Left(arg1, Len(arg1)-diff)
ElseIf l2 > l1
diff = l2 - l1
sum = Right(arg2, diff)
arg2 = Left(arg2, Len(arg2)-diff)
EndIf
EndIf
EndIf
*pend1 = @arg1 : *p1 = *pend1 + Len(arg1) - 1
*pend2 = @arg2 : *p2 = *pend2 + Len(arg2) - 1
Repeat
If *p1\Char = '.'
sum = "." + sum
Else
tmp = *p1\Char - '0' + *p2\Char - '0' + carry
If tmp >= 10
carry = 1
tmp - 10
Else
carry = 0
EndIf
sum = Chr(tmp + '0') + sum
EndIf
If *p1 > *pend1 : *p1 - 1 : EndIf
If *p2 > *pend2 : *p2 - 1 : EndIf
Until *p1 = *pend1 And *p2=*pend2
If carry
sum = Chr(carry + '0') + sum
EndIf
ProcedureReturn sum
EndProcedure
; Example 1
;b1.s = "1.123456789"
;b2.s = "2.111111111"
;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum
; Example 2
;b1.s = "999999999"
;b2.s = "1"
;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum
;Example 3
;b1.s = "12345678901234"
;b2.s = "1501"
;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum
-------------------------------
Commo estan? Bien ? Me alegro!
(registered PureBasic user)