Ver Mensaje Individual
  #1  
Antiguo 08-10-2010
Avatar de sitrico
[sitrico] sitrico is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Caracas, Venezuela
Posts: 295
Reputación: 22
sitrico Va por buen camino
Cool Barcode 128a Generar codigo de barras

Buenas, actualmente tengo una función escrita en delphi que permite calcular el código de barras en formato code128a, para usarlo solo tengo que instalar una fuente code128 y calcular la cadena antes de mandar a imprimir.

Lo que quisiera es poder implementar una funcion similar en SQL Server.

Pongo el código delphi.

Código Delphi [-]
unit BarcodeTools;

interface

Function Code128a(DataToEncode:String) : String;

implementation

Uses sysutils;

Function Code128a(DataToEncode:String) : String;
// Esta funcion fue traducida desde un macro excel descargado de internet
// permite codificar en code 128a una texto dado.
// Incluye calculo de digito de verificación
Var
PrintableString : String;
StringLength, i, WeightedTotal,
CurrentCharNum, CurrentValue : Integer;
CheckDigitValue : Integer;
C128CheckDigit : Char;
Begin
DataToEncode := Trim(DataToEncode);
PrintableString := '';
WeightedTotal := 103;
PrintableString := Char(203);
StringLength := Length(DataToEncode);
CurrentValue := 0;
For i := 1 To StringLength do
   Begin
   CurrentCharNum := ord(DataToEncode[i]);
   If CurrentCharNum < 135 Then CurrentValue := CurrentCharNum - 32;
   If CurrentCharNum > 134 Then CurrentValue := CurrentCharNum - 100;
   CurrentValue := CurrentValue * i;
   WeightedTotal := WeightedTotal + CurrentValue;
   If CurrentCharNum = 32 Then CurrentCharNum := 194;
   PrintableString := PrintableString + Chr(CurrentCharNum);
   End;
CheckDigitValue := (WeightedTotal Mod 103);
C128CheckDigit := #0;
If (CheckDigitValue < 95) And (CheckDigitValue > 0) Then C128CheckDigit := Char(CheckDigitValue + 32);
If (CheckDigitValue > 94) Then C128CheckDigit := Char(CheckDigitValue + 100);
If CheckDigitValue = 0 Then C128CheckDigit := Char(194);
PrintableString := PrintableString + C128CheckDigit + Char(206);
Result := PrintableString;
End;

end.

Es más me arriesgo a proponer al foro completar la unidad con otros "generadores" de códigos de barras, hasta ahora siempre he usado solo el 128a pero hay otros formatos que se podrían definir fácilmente en la unidad.

Gracias
__________________
Sitrico
Responder Con Cita