Algoritmi Vari

1. Conversione di un numero in una base qualunque (con segni arbitrari) e viceversa

‘es definisco la base 8
Public Shared key As String = “ABCDEFGW”

Public Shared Function baseN2dec(ByVal value As String, ByVal inBase As String) As Long
Dim strValue, x As String
Dim i, y As Long
strValue = StrReverse(CStr(UCase(value)))
For i = 0 To Len(strValue) – 1
x = Mid(strValue, i + 1, 1)
y = y + (inBase.IndexOf(x)) * (inBase.Length ^ i)
Next
Return y
End Function

Public Shared Function dec2baseN(ByVal value As Long, ByVal outBase As String, ByVal lunghezza As Integer) As String
Dim q, r, m As Long
Dim y, t, u As String
m = outBase.Length
q = value
Do
r = q Mod m
q = Int(q / m)
t = outBase.Substring(r, 1)
y = y & CStr(t)
Loop Until q = 0
u = StrReverse(y)
If u.Length < lunghezza Then Return (New String(outBase.Substring(0, 1), lunghezza - u.Length)) & u Else Return u End If End Function 2. Calcolo del Lhun

Public Shared Function getLhun(ByVal CodiceIn As String) As Integer
Dim tot As Integer
Dim contatore As Integer
Dim oddCheck As Integer
Dim valore As Integer
Dim carattere As String
oddCheck = 0
For contatore = Len(CodiceIn) To 1 Step -1
oddCheck = oddCheck + 1
carattere = Mid(CodiceIn, contatore, 1)
If IsNumeric(carattere) Then
valore = CInt(carattere)
If (oddCheck And 1) = 0 Then
tot = tot + valore
Else
If valore * 2 >= 10 Then
tot = tot + (valore * 2) – 10 + 1
Else
tot = tot + (valore * 2)
End If
End If
End If
Next
getLhun = (10 – (tot Mod 10)) Mod 10
End Function

3. Calcolo del Bar Code

Public Shared Function getBarCode(ByVal CodiceIn As String) As Integer
Dim tot As Integer
Dim contatore As Integer
Dim oddCheck As Integer
Dim valore As Integer
Dim carattere As String
oddCheck = 0
For contatore = 1 To Len(CodiceIn)
oddCheck = oddCheck + 1
carattere = Mid(CodiceIn, contatore, 1)
If IsNumeric(carattere) Then
valore = CInt(carattere)
If (oddCheck And 1) = 0 Then
tot = tot + valore * 3
Else
tot = tot + (valore * 1)
End If
End If
Next
tot = (10 – (tot Mod 10)) Mod 10
getBarCode = tot
End Function

3. Stampa di Bar Code
Implementazioni web della stampa di barcode e di barcode ean 13. Non ricordo piu dove ho recuperato la base del sorgente ma certamente l’ho riadattato per il web

BARCODE

BARCODE_EAN

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *