Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Fast italian-code-for-companies check function Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Jan-03
Category
Algorithm
Language
Delphi All Versions
Views
88
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Christian Cristofori

In my old article "How to check italian code for companies" there was a explanation 
how to get information from italian code for companies, but someone recently mailed 
me that a simply checker version of that function is needed instead. There's the 
solution.

Answer:
1   
2   function PartitaIVA(code: string): boolean;
3     function ReduceSum(n: Integer): Integer;
4     var
5       i: Integer;
6       s: string;
7     begin
8       s := inttostr(n);
9       if (length(s) = 1) then
10      begin
11        result := n;
12        exit;
13      end;
14      result := 0;
15      for i := 1 to length(s) do
16      begin
17        result := result + strtointdef(s[i], 0);
18      end;
19    end;
20    function ReduceNum(n: Integer): Integer;
21    var
22      s: string;
23    begin
24      result := n;
25      s := inttostr(n);
26      if (length(s) > 1) then
27      begin
28        result := strtointdef(s[length(s)], 0)
29      end;
30    end;
31  var
32    i: Integer;
33    c: Integer;
34  begin
35    result := false;
36    if (length(code) <> 11) then
37      exit;
38    for i := 1 to 11 do
39      if (not (code[i] in ['0'..'9'])) then
40        exit;
41    i := strtointdef(copy(code, 8, 3), 0) - 1;
42    if ((i < 0) or (i > 102)) then
43      exit;
44    c := 0;
45    for i := 1 to 10 do
46    begin
47      if ((i mod 2) = 0) then
48        inc(c, reducesum(strtointdef(code[i], 0) * 2))
49      else
50        inc(c, strtointdef(code[i], 0));
51    end;
52    result := ((10 - ReduceNum(c)) = strtointdef(code[11], -1));
53  end;


That's all, removed all output parameter variables for a quickly validity check.

Christian Cristofori

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC