I have a ready-made ticket program but it generates the wrong barcode

0

I have a Macoratti program in ASP.NET that generates a bank slip but the barcode always has a 0 in the beginning of the numbers, how do I get it?

private string CodigoBarras25I( string Valor)
    {
        int f, f1, f2, i;
        string s;
        string texto;
        int fino = 1;
        int largo = 3;
        int altura = 50;
        string[] BarCodes= new string[100];
        StringBuilder Codbarras = new System.Text.StringBuilder();

        BarCodes[0] = "00110";
        BarCodes[1] = "10001";
        BarCodes[2] = "01001";
        BarCodes[3] = "11000";
        BarCodes[4] = "00101";
        BarCodes[5] = "10100";
        BarCodes[6] = "01100";
        BarCodes[7] = "00011";
        BarCodes[8] = "10010";
        BarCodes[9] = "01010";
        for( f1=9; f1>=0; f1--)
            for( f2=9; f2>=0; f2--)
            {
                f = f1 * 10 + f2;
                texto = "";
                for( i=0; i<=4; i++)
                    texto += BarCodes[f1].Substring( i, 1) + BarCodes[f2].Substring( i, 1);
                BarCodes[f] = texto;
            }

        texto = Valor;
        if( (texto.Length % 2)!=0)
            texto = "0" + texto;

        //draw da guarda inicial
        Codbarras.Append("<img src=\"" + _ImagesFolder + "/p.gif\" width=\"" + fino.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");
        Codbarras.Append("<img src=\"" + _ImagesFolder + "/b.gif\" width=\"" + fino.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");
        Codbarras.Append("<img src=\"" + _ImagesFolder + "/p.gif\" width=\"" + fino.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");
        Codbarras.Append("<img src=\"" + _ImagesFolder + "/b.gif\" width=\"" + fino.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");

        // Draw dos dados
        while( texto.Length>0)
        {
            i = Convert.ToInt32( texto.Substring(0, 2));
            texto = texto.Remove( 0, 2);

            s = BarCodes[i];

            for( i=0; i<=9; i+=2)
            {
                if( s[i]=='0') f1 = fino;
                else f1 = largo;

                Codbarras.Append( "<img src=\"" + _ImagesFolder + "/p.gif\" width=\"" + f1.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");

                if( s[ i+1]=='0') f2 = fino;
                else f2 = largo;

                Codbarras.Append( "<img src=\"" + _ImagesFolder + "/b.gif\" width=\"" + f2.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");
            }
        }

        // draw da guarda final
        Codbarras.Append("<img src=\"" + _ImagesFolder + "/p.gif\" width=\"" + largo.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");
        Codbarras.Append("<img src=\"" + _ImagesFolder + "/b.gif\" width=\"" + fino.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");
        Codbarras.Append("<img src=\"" + _ImagesFolder + "/p.gif\" width=\"" + fino.ToString() + "\" height=\"" + altura.ToString() + "\" border=0>");

        return Codbarras.ToString();
    }

    private StringBuilder _Buffer = new StringBuilder();
    private bool _Encerrado = false;
    private int _Counter = 0;
}

I think the problem is in this part of the code:

texto = Valor;
        if ((texto.Length % 2) != 0)
            texto = "0" + texto;

But if I withdraw or try to change it it gets the whole code wrong, how can I do it?

    
asked by anonymous 26.08.2018 / 07:05

0 answers