calculate an IBAN Key and a rib for a french banking account

Share your advanced PureBasic knowledge/code with the community.
KIKI
Enthusiast
Enthusiast
Posts: 145
Joined: Thu Dec 28, 2006 11:49 am
Location: FRANCE

calculate an IBAN Key and a rib for a french banking account

Post by KIKI »

Here is the method to calculate an IBAN Code for a bankin g account in all part of the word and a method to calculate the rib for a french banking account





Code: Select all

Procedure.s Caliban( compte.s, pays.s)
Protected  compte1.s,clerib.s="",clerib1.l,clerib2.l
If pays = "" ;Cas ou l'on fournit seulement le BBAN (RIB) on considére qu'il sagit d'un compte Français par défaut 
pays = "FR"
EndIf 
;On élimine les blancs et les "-"
compte = ReplaceString(compte, " " ,"")
compte = ReplaceString(compte, "-" ,"")
;Teste si le premier caractére est une lettre auxquelles cas nous sommes en face d'un IBAN
If Asc( Left(compte,1) ) >= 48 And Asc( Left(compte,1) ) <= 59
compte1.s = compte + pays + "FR00"
Else
compte1.s = Mid(compte,5,Len(compte)-4 ) + pays +"00"
EndIf 
clerib.s= ""
For i= 1 To Len(compte1)
  If Asc(Mid(compte1,i,1)) >= 65 And Asc(Mid(compte1,i,1)) <= 90 
    clerib = clerib + Str( Asc(Mid(compte1,i,1))-55)
  Else 
    clerib = clerib + Mid(compte1,i,1)
  EndIf
Next
clerib1 = ValQ( Left(clerib,19 ) ) % 97
clerib2 =98 -ValQ ( StrQ(clerib1) + Right(clerib,Len(clerib)-19 ) ) % 97
;Teste si le compte a été fourni au format BBAN ou au format IBAN 

If Asc( Left(compte,1) ) >= 48 And Asc( Left(compte,1) ) <= 59
ProcedureReturn  pays + RSet( Str(clerib2) , 2 , "0") + compte
Else 
ProcedureReturn  pays + RSet( Str(clerib2) , 2 , "0") + Mid(compte,5,Len(compte)-4)
EndIf 
EndProcedure  

Procedure.s Clef_rib(bban.s)
	;==================
	;Calculer la cle rib
	;===================
	Protected a.s,i.b=1,b.b=1,banque.s,agence.s,rib.s,compte.s,clerib2.s=""
	If Len(bban) = 23 
	banque.s= Left(bban,5)
	agence.s = Mid(bban,6,5)
	rib.s = Mid(bban,11,11)
	Else
	banque.s= Mid(bban,5,5)
	agence.s = Mid(bban,10,5)
	rib.s = Mid(bban,15,11)
	EndIf
	
	Protected HOLLERITH.s = "AJ BKSCLTDMUENVFOWGPXHQYIRZ"
	;Agence
	;===============================
	;Calcul de la cle rib
	;===============================
	For i = 1 To 11
		a = Mid(rib, i , 1 )
		If Asc(a) >= 65
					b = FindString(HOLLERITH,a ,1)
			If b % 3 <> 0
				b = Int(b / 3) + 1
			Else
				b = b / 3
			EndIf
			rib = Left(rib, i - 1) + Str(b) + Right(rib, 11 - i)
		EndIf
	Next
	compte= banque+agence+rib+"00"
	clerib1 = ValQ( Left( compte ,19 ) ) % 97
	clerib2 =  StrQ(  97- ( ValQ(  StrQ(clerib1) +Mid( compte,20,4) ) % 97) )
	clerib2 = RSet( clerib2,2,"0")
 ProcedureReturn Mid(bban,1, Len(BBan)-2)+ clerib2
EndProcedure   ;==>Clef
_rib
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

:?: So what exactly is this useful for :?:

The only thing in Texas that uses ribs is the Barbeque place down the street...
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
KIKI
Enthusiast
Enthusiast
Posts: 145
Joined: Thu Dec 28, 2006 11:49 am
Location: FRANCE

Post by KIKI »

Rook Zimbabwe wrote::?: So what exactly is this useful for :?:

The only thing in Texas that uses ribs is the Barbeque place down the street...
When You have an account in a bank and you want to pay someone in every part of the world the way to do it is to convert you local account in a foreign account that everyone can read. This is an ISO norm and to verify that account is good you ought to verify the Key. This program allow you to calculate this key
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

this explains the key...

but a rib is on a BBQ, or with Sauerkraut, but not in a bank...?
oh... and have a nice day.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

RIB is the French language acronym for what the rest of Europe calls BIC
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

:D BIC is a brand of Cigarrette Lighter... here anyway! I think they make disposable ballpoint pens as well... I use a Parker Fountain Pen... I don't know why anyone would use anything else!

What were we talking about???

Oh look... cheese! :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Rook Zimbabwe wrote::D BIC is a brand of Cigarrette Lighter... here anyway! I think they make disposable ballpoint pens as well...

And guess where those were made, France ! ;)
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
KIKI
Enthusiast
Enthusiast
Posts: 145
Joined: Thu Dec 28, 2006 11:49 am
Location: FRANCE

Post by KIKI »

dell_jockey wrote:
Rook Zimbabwe wrote::D BIC is a brand of Cigarrette Lighter... here anyway! I think they make disposable ballpoint pens as well...

And guess where those were made, France ! ;)
Thanks for all which encourage programmer to shared what they do , uo are so funny !.....................................................
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I can use this code, thanks Kiki. :)
Post Reply