Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #3758 > unrolled thread
| Started by | Milun Vasilijevic <milun.vasilijevic@gmail.com> |
|---|---|
| First post | 2012-07-12 18:36 -0700 |
| Last post | 2015-08-01 08:12 -0700 |
| Articles | 13 — 8 participants |
Back to article view | Back to comp.lang.clipper.visual-objects
Mod() function and large numbers Milun Vasilijevic <milun.vasilijevic@gmail.com> - 2012-07-12 18:36 -0700
Re: Mod() function and large numbers "Stephen Quinn" <stevejqNO@bigpondSPAM.net.au> - 2012-07-13 15:50 +1000
Re: Mod() function and large numbers Sherlock <sherlock@sherlock.com.au> - 2015-08-01 17:15 -0700
Re: Mod() function and large numbers Norbert Kolb <n.kolb_entferne_dies@aon.at> - 2012-07-13 10:36 +0200
Re: Mod() function and large numbers Norbert Kolb <n.kolb_entferne_dies@aon.at> - 2012-07-13 10:45 +0200
Re: Mod() function and large numbers Paulo Oliveira <paulo@clipinfor.com> - 2012-07-13 04:20 -0700
Re: Mod() function and large numbers Norbert Kolb <n.kolb_entferne_dies@aon.at> - 2012-07-13 16:59 +0200
Re: Mod() function and large numbers Milun Vasilijevic <milun.vasilijevic@gmail.com> - 2012-07-14 11:40 -0700
Re: Mod() function and large numbers Milun Vasilijevic <milun.vasilijevic@gmail.com> - 2012-07-14 11:43 -0700
Re: Mod() function and large numbers Malcolm G <malcolm-news2012delete@delete.jobstream.com> - 2012-07-13 09:38 +0100
Re: Mod() function and large numbers Malcolm G <malcolm-news2012delete@delete.jobstream.com> - 2012-07-13 09:42 +0100
Re: Mod() function and large numbers "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> - 2012-07-13 17:37 +0200
Re: Mod() function and large numbers jamesvdb@lavabit.com - 2015-08-01 08:12 -0700
| From | Milun Vasilijevic <milun.vasilijevic@gmail.com> |
|---|---|
| Date | 2012-07-12 18:36 -0700 |
| Subject | Mod() function and large numbers |
| Message-ID | <a7fd55fb-41b1-41bb-86d4-5c264caad5e3@googlegroups.com> |
Hi all, I've searched the newsgroup regarding the subject of my message but haven't found the answer, so I need you're help. Here's the example: String: 1201000030921111100 I need to convert string this length to integer, and then to use Mod() function: Mod(1201000030921111100,97) which using windows calculator returns: 39 The problem occurs when I try to use Val() function - I get the number: 12010000309211111000 - with extra 0 in the end. So, Mod(,97) returns 76 instead 39. I've seen Frans de Witt CPU Class, but haven't been able to implement it. I would appreciate your's help. Regards, Milun Vasilijevic
[toc] | [next] | [standalone]
| From | "Stephen Quinn" <stevejqNO@bigpondSPAM.net.au> |
|---|---|
| Date | 2012-07-13 15:50 +1000 |
| Message-ID | <GDOLr.380$Oq4.214@viwinnwfe02.internal.bigpond.com> |
| In reply to | #3758 |
Milun > The problem occurs when I try to use Val() function - I get the number: > 12010000309211111000 - with extra 0 in the end. So, Mod(,97) returns 76 > instead 39. No idea how you got that - all I get is a numeric overflow error (ie the text/number is to big for a 32bit value) If it came from a 64bit system then you'll need 64bit routines to handle it. VO isn't a 64bit system and more than likely never will be<bg> You might try using Vulcan to do the conversion, I believe .NET can handle 64bit numerics. CYA Steve
[toc] | [prev] | [next] | [standalone]
| From | Sherlock <sherlock@sherlock.com.au> |
|---|---|
| Date | 2015-08-01 17:15 -0700 |
| Message-ID | <31df5f70-906f-4c9a-a881-441051dc682b@googlegroups.com> |
| In reply to | #3759 |
Interesting to hear from Steve Quinn who has been dead for 2.5 years.. Still with the commentary.. Phil
[toc] | [prev] | [next] | [standalone]
| From | Norbert Kolb <n.kolb_entferne_dies@aon.at> |
|---|---|
| Date | 2012-07-13 10:36 +0200 |
| Message-ID | <4fffddb1$0$1580$91cee783@newsreader04.highway.telekom.at> |
| In reply to | #3758 |
Hello Milun!
I think you will check the IBAN-number. You will get numbers up to 50
signs and this number is correct for x mod 97 = 1
Here is a function that will do that:
FUNCTION CheckIBAN(cIban AS STRING, lInfo AS LOGIC) AS LOGIC
LOCAL lRet AS LOGIC
LOCAL nP AS INT
LOCAL cTemp AS STRING
LOCAL cC AS STRING
LOCAL cLand AS STRING
LOCAL aTemp AS ARRAY
LOCAL i AS DWORD
LOCAL nLen AS DWORD
lRet := FALSE
cIban := Trim(cIban)
IF Empty(cIban)
lRet := TRUE
ELSEIF Between(Asc(Left(cIban, 1)), 48, 57) // erstes Zeichen ist eine
Ziffer
lRet := TRUE
ELSEIF Between(Asc(Left(cIban, 1)), 65, 90) .AND.
Between(Asc(SubStr(cIban, 2, 1)), 65, 90)
IF !Between(SLen(cIban), 15, 31)
lRet := FALSE
ELSE
// Albanien AL47212110090000000235698741 5 - 12 28
// Andorra AD1200012030200359100100 5 - 12 24
// Belgien BE62510007547061 5 - 7 16
// Bosnien und Herzegowina BA391290079401028494 5 - 11 20
// Bulgarien BG80BNBG96611020345678 5 - 12 22
// Dänemark DK5000400440116243 5 - 8 18
// Deutschland DE89370400440532013000 5 - 12 22
// Estland EE975500000550008329 5 - 8 20
// Finnland FI2112345600000785 5 - 10 18
// Faroer Insel FO2000400440116243 5 - 8 18
// Frankreich FR1420041010050500013M02606 5 - 14 27
// Gibraltar GI75NWBK000000007099453 5 - 8 23
// Griechenland GR1601101250000000012300695 5 - 11 27
// Grönland GL2000400440116243 5 - 8 18
// Großbritannien GB29NWBK60161331926819 5 - 8 22
// Irland IE29AIBK93115212345678 5 - 8 22
// Island IS140159260076545510730339 5 - 8 26
// Italien IT40S0542811101000000123456 6 - 15 27
// Kroatien HR1210010051863000160 5 - 11 21
// Lettland LV80BANK0000435195001 5 - 8 21
// Litauen LT121000011101001000 5 - 9 20
// Luxemburg LU280019400644750000 5 - 7 20
// Malta MT84MALT011000012345MTLCAST001S 5 - 13 31
// Mazedonien MK07250120000058984 5 - 8 19
// Mauritius MU17BOMM0101101030300200000MUR 5 - 11 30
// Monaco MC9320041010050500013M02606 5 - 14 27
// Niederlande NL39RABO0300065264 5 - 8 18
// Norwegen NO9386011117947 5 - 8 15
// Österreich AT617601300035746811 5 - 9 20
// Polen PL61109010140000071219812874 5 - 12 28
// Portugal PT50000201231234567890154 5 - 12 25
// Rumänien* RO83UNCR0100xxxxxx771USD 5 - 8 24
// San Marino SM68S0542811101000000123456 6 - 15 27
// Saudi-Arabien SA5655000000000570400546 5 - 6 24
// Schweden SE3550000000054910000003 5 - 7 24
// Schweiz CH9300762011623852957 5 - 9 21
// Slowakei SK3112000000198742637541 5 - 8 24
// Slowenien SI56191000000123438 5 - 9 19
// Spanien ES0700120345030000067890 5 - 12 24
// Tschechien CZ6508000000192000145399 5 - 8 24
// Türkei TR760006100519786457841326 5 - 10 26
// Ungarn HU42117730161111101800000000 5 - 11 28
// Zypern CY17002001280000001200527600 5 - 12 28
// DE68210501700012345678
nLen := SLen(cIban)
cLand := SubStr(cIban, 1, 2)
IF nLen = 20 .AND. Instr(cLand, "AT,BA;EE,LT,LU")
lRet := TRUE
ELSEIF nLen = 22 .AND. Instr(cLand, "DE,BG,GB,IE")
lRet := TRUE
ELSEIF nLen = 15 .AND. Instr(cLand, "NO")
lRet := TRUE
ELSEIF nLen = 16 .AND. Instr(cLand, "BE")
lRet := TRUE
ELSEIF nLen = 18 .AND. Instr(cLand, "DK,FI,FO,GL,NL")
lRet := TRUE
ELSEIF nLen = 19 .AND. Instr(cLand, "MK,SI")
lRet := TRUE
ELSEIF nLen = 21 .AND. Instr(cLand, "HR,LV,CH,LI")
lRet := TRUE
ELSEIF nLen = 23 .AND. Instr(cLand, "GI")
lRet := TRUE
ELSEIF nLen = 24 .AND. Instr(cLand, "AD,RO,SA,SE,SK,ES,CZ")
lRet := TRUE
ELSEIF nLen = 25 .AND. Instr(cLand, "PT")
lRet := TRUE
ELSEIF nLen = 26 .AND. Instr(cLand, "IS,TR")
lRet := TRUE
ELSEIF nLen = 27 .AND. Instr(cLand, "FR,GR,IT,MC,SM")
lRet := TRUE
ELSEIF nLen = 28 .AND. Instr(cLand, "AL,PL,HU,CY")
lRet := TRUE
ELSEIF nLen = 30 .AND. Instr(cLand, "MU")
lRet := TRUE
ELSEIF nLen = 31 .AND. Instr(cLand, "MT")
lRet := TRUE
ENDIF
IF lRet
cTemp := SubStr(cIban, 5) + SubStr(cIban, 1, 4)
// 210501700012345678DE68
// Buchstaben werden durch Zahlenwerte, Position im Alphabet + 9,
ersetzt
FOR i := 1 UPTO SLen(cTemp)
cC := SubStr(cTemp, i, 1)
IF Between(cC, "A", "Z")
cTemp := SubStr(cTemp, 1 , i-1) + NTrim(Asc(cC)-55) +
SubStr(cTemp, i+1)
i += 1
ENDIF
NEXT
Log2DB(cTemp)
aTemp := {}
WHILE cTemp <> NULL_STRING
// Zerlegung in 4er-Gruppen von rechts her
AAdd(aTemp, Val(Right(cTemp, 4)))
IF SLen(cTemp) > 4
cTemp := SubStr(cTemp, 1, SLen(cTemp)-4)
ELSE
cTemp := NULL_STRING
ENDIF
ENDDO
Log2DB(aTemp)
nP := 0
FOR i := 1 UPTO ALen(aTemp)
// wir nützen die Rechenregeln für Modulo aus
// (a + b) mod m = (a mod m) + (b mod m)
// (a * b) mod m = (a mod m) * (b mod m)
// 10.000 mod 97 = 9
nP := (nP + ((aTemp[i] % 97) * (9^(i-1)))) % 97
//c Log2DB(FloatFormat(9^(i-1),20,0))
NEXT
Log2DB(nP)
// Prüfzahl modulo 97 muss 1 sein
lRet := (nP = 1)
ENDIF
ENDIF
ENDIF
IF !lRet .AND. lInfo
Info("Kontonummer ist ungültig!")
ENDIF
RETURN lRet
Best regards
Norbert
[toc] | [prev] | [next] | [standalone]
| From | Norbert Kolb <n.kolb_entferne_dies@aon.at> |
|---|---|
| Date | 2012-07-13 10:45 +0200 |
| Message-ID | <4fffdfbe$0$1582$91cee783@newsreader04.highway.telekom.at> |
| In reply to | #3760 |
Delete all lines with Log2DB(...) This was only for test. Norbert
[toc] | [prev] | [next] | [standalone]
| From | Paulo Oliveira <paulo@clipinfor.com> |
|---|---|
| Date | 2012-07-13 04:20 -0700 |
| Message-ID | <d9d6d6d4-9c62-4881-9926-ac26f1701030@googlegroups.com> |
| In reply to | #3763 |
Hi Norbert, Great Function, in Portugal the 21 digits on the right are the NIB, any idea to validate only these digits? all suggestions are welcome. TIA Paulo Oliveira
[toc] | [prev] | [next] | [standalone]
| From | Norbert Kolb <n.kolb_entferne_dies@aon.at> |
|---|---|
| Date | 2012-07-13 16:59 +0200 |
| Message-ID | <5000374e$0$1578$91cee783@newsreader04.highway.telekom.at> |
| In reply to | #3766 |
Hi Paolo, > Great Function, in Portugal the 21 digits on the right are the NIB, any idea to validate only these digits? Sorry NO. But a really good function is Remainder97 from Malcolm - Congratulation. Best will be to combine these 2 functions. Norbert
[toc] | [prev] | [next] | [standalone]
| From | Milun Vasilijevic <milun.vasilijevic@gmail.com> |
|---|---|
| Date | 2012-07-14 11:40 -0700 |
| Message-ID | <0c44198a-6f0c-4263-b9f1-f5edf1b640d6@googlegroups.com> |
| In reply to | #3768 |
Hi Norbert, Malcom, and everybody who came to the rescue, Thank you for your time, you've been very helpful. In the end I implemented Malcom's great function Remainder97. You were right - I needed this function for digit checking in my e-banking payment order module. It wasn't IBAN numbers but rather similar thing: adding control number to the reference number of payment order. Once again thank you very much. Milun Vasilijevic петак, 13. јул 2012. 16.59.10 UTC+2, Norbert Kolb је написао/ла: > Hi Paolo, > > > Great Function, in Portugal the 21 digits on the right are the NIB, > any idea to validate only these digits? > > Sorry NO. > > But a really good function is Remainder97 from Malcolm - Congratulation. > Best will be to combine these 2 functions. > > Norbert
[toc] | [prev] | [next] | [standalone]
| From | Milun Vasilijevic <milun.vasilijevic@gmail.com> |
|---|---|
| Date | 2012-07-14 11:43 -0700 |
| Message-ID | <b717206a-f42f-4833-8f64-cf9dc91dd93a@googlegroups.com> |
| In reply to | #3772 |
One more thing. It was ISO 7064 Mod 97,10 standard I had to implement: http://code.google.com/p/checkdigits/wiki/CheckDigitSystems Milun
[toc] | [prev] | [next] | [standalone]
| From | Malcolm G <malcolm-news2012delete@delete.jobstream.com> |
|---|---|
| Date | 2012-07-13 09:38 +0100 |
| Message-ID | <j8RLr.803269$S84.238223@fx23.am4> |
| In reply to | #3758 |
On 13/07/2012 02:36, Milun Vasilijevic wrote: > Hi all, > > I've searched the newsgroup regarding the subject of my message but haven't found the answer, so I need you're help. Here's the example: > > String: 1201000030921111100 > > I need to convert string this length to integer, and then to use Mod() function: First of all, as noted, that number is too large to fit into a VO integer (largest value in a 32 bit signed integer 2147483648==2^32-1) You are even running close to the limit of 64 bit integers 1201000030921111100 your number 9223372036854775807==2^63-1 which strongly suggests that the 64 bit float that is used by val cannot be exact (I think an IEEE 64 bit real8 has about 48 bits of accurancy? ), which means it is meaningless to use mod > Mod(1201000030921111100,97) > > which using windows calculator returns: 39 > > The problem occurs when I try to use Val() function - I get the number: 12010000309211111000 - with extra 0 in the end. So, Mod(,97) returns 76 instead 39. yes - this is the expected result because there is no datatype in VO that can exactly store that number. probably the most important question is whether a 64 bit int would be enough or whether you have to use arbitrary precision classes instead.
[toc] | [prev] | [next] | [standalone]
| From | Malcolm G <malcolm-news2012delete@delete.jobstream.com> |
|---|---|
| Date | 2012-07-13 09:42 +0100 |
| Message-ID | <6cRLr.803270$S84.659476@fx23.am4> |
| In reply to | #3761 |
On 13/07/2012 09:38, Malcolm G wrote:
> On 13/07/2012 02:36, Milun Vasilijevic wrote:
>> Hi all,
>>
>> I've searched the newsgroup regarding the subject of my message but haven't found the answer, so I need you're help. Here's the example:
>>
>> String: 1201000030921111100
>>
>> I need to convert string this length to integer, and then to use Mod() function:
As someone else has pointed out you may well be using IBANS.
If you are specifically doing that, this code may be some help,
no warrently but I assume you can see why it works.
static function Remainder97 (cCheck as string) as int
local retval as int
IF LEN (cCheck) < 9
retval := VAL (cCheck)
retval := retval % 97
ELSE
retval := Remainder97 (TrimStr (Remainder97 (Left (cCheck, 8))) +
Substr (cCheck, 9))
ENDIF
return retval
[toc] | [prev] | [next] | [standalone]
| From | "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> |
|---|---|
| Date | 2012-07-13 17:37 +0200 |
| Message-ID | <jtpfbu$rh4$1@dont-email.me> |
| In reply to | #3762 |
I can also offer some IBAN Check code using the arithmetic of an Oracle
database.
Arne Ortlinghaus
ACS Data Systems
method ValidateIBAN(cIBANChar as string) class clsIBAN
local cIBANTmp1, cIBANTmp2, cChar, cSql as string
local iPos as dword
local nChDig as usual
if ascan(_aLaender,left(cIBANChar,2)) == 0
return true
end if
cIBANChar := AllTrim(cIBANChar) // Todo 66425 AO 12.07.2012 Runtimefehler
bei IBAN-Prüfung im Falle von falschen Zeichen
cIBANTmp1 := substr(cIBANChar,5)+left(cIBANChar,4)
cIBANTmp2 := ""
for iPos := 1 to slen(cIBANTmp1)
cChar := substr(cIBANTmp1,iPos,1)
if ! isdigit(string2psz(cChar))
cChar := str(asc(cChar)-55,2)
end if
cIBANTmp2 += cChar
next
if !Empty(Val(cIBANTmp2)) // Todo 63367 Fehlermeldung bei Import IBAN in
Kunden/Lieferanten
cSql := 'SELECT MOD('+SQLValue2SQLString(cIBANTmp2)+',97) "Modulus" FROM
DUAL'
nChDig := GetSQLValueFast(cSql, "N", 10, 0, 0, null_object, true)
else
nChDig := 0
endif
//msginfo(cIBANChar+chr(13)+chr(10)+cIBANTmp1+chr(13)+chr(10)+cIBANTmp2+chr(13)+chr(10)+cSql+chr(13)+chr(10)+typevalue2string(nChDig))
return nChDig == 1
method Init(oOwner, oServer) class clsIBAN
_oOwner := oOwner
_oServer := oServer
_aLaender := ArrayCreate(18)
_aLaengen := ArrayCreate(18)
_aLaender[1] := "IT"
_aLaengen[1] := 27
_aLaender[2] := "AT"
_aLaengen[2] := 20
_aLaender[3] := "BE"
_aLaengen[3] := 16
_aLaender[4] := "CH"
_aLaengen[4] := 21
_aLaender[5] := "DE"
_aLaengen[5] := 22
_aLaender[6] := "DK"
_aLaengen[6] := 18
_aLaender[7] := "ES"
_aLaengen[7] := 24
_aLaender[8] := "FI"
_aLaengen[8] := 18
_aLaender[9] := "FR"
_aLaengen[9] := 27
_aLaender[10] := "GB"
_aLaengen[10] := 22
_aLaender[11] := "IE"
_aLaengen[11] := 22
_aLaender[12] := "IS"
_aLaengen[13] := 26
_aLaender[13] := "LU"
_aLaengen[13] := 20
_aLaender[14] := "NL"
_aLaengen[14] := 18
_aLaender[15] := "NO"
_aLaengen[15] := 15
_aLaender[16] := "PT"
_aLaengen[16] := 25
_aLaender[17] := "SE"
_aLaengen[17] := 24
_aLaender[18] := "SM"
_aLaengen[18] := 27
return self
class clsIBAN
protect _oOwner as object
protect _oServer as object
protect _aLaender as array
protect _aLaengen as array
declare method ValidateIBAN
[toc] | [prev] | [next] | [standalone]
| From | jamesvdb@lavabit.com |
|---|---|
| Date | 2015-08-01 08:12 -0700 |
| Message-ID | <8eacbf42-2e43-4ee9-a8e3-be12dfa02ff1@googlegroups.com> |
| In reply to | #3758 |
Op vrijdag 13 juli 2012 03:36:41 UTC+2 schreef Milun Vasilijevic:
> Hi all,
>
> I've searched the newsgroup regarding the subject of my message but haven't found the answer, so I need you're help. Here's the example:
>
> String: 1201000030921111100
>
> I need to convert string this length to integer, and then to use Mod() function:
>
> Mod(1201000030921111100,97)
>
> which using windows calculator returns: 39
>
> The problem occurs when I try to use Val() function - I get the number: 12010000309211111000 - with extra 0 in the end. So, Mod(,97) returns 76 instead 39.
>
> I've seen Frans de Witt CPU Class, but haven't been able to implement it. I would appreciate your's help.
>
> Regards,
>
> Milun Vasilijevic
I have written a function that you can use instead of the Clipper function MOD(). My function works with any number with UNLIMITED digits !!!! You have to call it with the number as a string :
? rvmod97("3214282912345698765432161182")
will return 1
This example is the IBAN number : GB82WEST12345698765432 converted to only numeric values, so the function returns 1 which means it is a valid IBAN nr)
My function is a very simple function (It always calculates the MOD 97 of a group of 4, putting it then before the next group of 4 digits, etc until the end of the strings is reached. The result of the last MOD 97 calculation is the result ! This function can easily calculate MOD 97 of a number of 1000 digits :)
FUNCTION RVMOD97
PARAMETERS RVM1
RVM4=""
DO WHILE LEN(RVM1)>0
IF LEN(RVM1)>4
RVM2=VAL(RVM4+SUBS(RVM1,1,4))
RVM1=SUBS(RVM1,5)
ELSE
RVM2=VAL(RVM4+RVM1)
RVM1=""
ENDIF
RVM3=RVM2-97*INT(RVM2/97)
RVM4=LTRIM(STR(RVM3,2,0))
ENDDO
RETURN RVM3
Note : I'm using clipper for more than 25 years and I allways use capitals :) If questions or thank you mail : clement.germain@hotmail.be
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.clipper.visual-objects
csiph-web