Ver Mensaje Individual
  #3 (permalink)  
Antiguo 21/03/2007, 03:03
natxojarto
 
Fecha de Ingreso: octubre-2006
Mensajes: 204
Antigüedad: 17 años, 7 meses
Puntos: 0
Re: problemas con fichero

Este es el coidog es simplemente cuando le doy al boton Generar me crea el fichero, es un fichero que mando al banco y la base de datos y la tabla estan seleccionadas de antes. He usado ADO.NET me imagino q lo conocereis. Me crea casi todo el fichero menos el final.


Código:
Friend Sub GenerarFichero(ByVal cif As String, ByVal fecha As String, ByVal recibo As String, ByVal año As String)

        Dim sucAux As String
        Dim entAux As String
        Dim dcAux As String
        Dim colAux As String
        Dim cueAux As String
        Dim ind As Integer
        Dim i As Integer = 0
        Dim iact As Integer
        Dim numCol As Integer = 0
        Dim nombre As String
        Dim apellido1 As String
        Dim apellido2 As String
        Dim longitud As Integer
        Dim fila As Data.DataRow
        Const fic As String = "C:\FACTENERO2006.txt"
        Dim sw As New System.IO.StreamWriter(fic)

        ' Imprime la primera linea hay q poner una variable CIF y Fecha Actual
        sw.Write("5180{0}000{1}      COIIE/EIIEO                                                 ", cif, fecha)
        sw.WriteLine("31834800                                                                  ")
        ' Imprime la segunda linea camnbiar CIF y Fecha actual
        sw.WriteLine("5380{0}000{1}{1}COIIE/EIIEO                             31834800560000492157        ", cif, fecha)
        sw.WriteLine("01                                                                ")
        'Para cada fila de la tabla de la base de datos
        For Each fila In dbDataSet.Tables(NombreTabla).Rows
            ' Saca el seq_banco y lo comprueba si le faltan numeros añade ceros por delante
            entAux = CStr(fila("seq_banco"))
            If Len(entAux) <> 4 Then
                For ind = 1 To 4
                    entAux = 0 & entAux
                    If Len(entAux) = 4 Then
                        Exit For
                    End If
                Next ind
            End If
            ' Saca el seq_suc y lo comprueba si le faltan numeros añade ceros por delante
            sucAux = CStr(fila("seq_suc"))
            If Len(sucAux) <> 4 Then
                For ind = 1 To 4
                    sucAux = 0 & sucAux
                    If Len(sucAux) = 4 Then
                        Exit For
                    End If
                Next ind
            End If
            ' Saca dc y lo comprueba si le faltan numeros añade ceros por delante
            dcAux = CStr(fila("dc"))
            If Len(dcAux) <> 2 Then
                For ind = 1 To 2
                    dcAux = 0 & dcAux
                    If Len(dcAux) = 2 Then
                        Exit For
                    End If
                Next ind
            End If
            ' Saca cuenta y lo comprueba si le faltan numeros añade ceros por delante
            cueAux = CStr(fila("cuenta"))
            If Len(cueAux) <> 10 Then
                For ind = 1 To 10
                    cueAux = 0 & cueAux
                    If Len(cueAux) = 10 Then
                        Exit For
                    End If
                Next ind
            End If
            ' Saca el nuemro de colegiado y lo comprueba si le faltan numeros añade ceros por delante
            colAux = CStr(fila("NCOLEGIADO"))
            If Len(colAux) <> 4 Then
                For ind = 1 To 4
                    colAux = 0 & colAux
                    If Len(colAux) = 4 Then
                        Exit For
                    End If
                Next ind
            End If
            ' Coge el nombre y apellidos de la fila
            nombre = CStr(fila("nombre"))
            apellido1 = CStr(fila("apellido1"))
            apellido2 = CStr(fila("apellido2"))
            longitud = 39 - (Len(nombre) + Len(apellido1) + Len(apellido2))
            sw.WriteLine("5680{0}00000000000{1}{2} {3} {4}", cif, colAux, apellido1, apellido2, nombre)
            sw.WriteLine("{0}{1}{2}{3}0000007890                {4} {5} COIIE/EIIEO             ", entAux, sucAux, dcAux, cueAux, recibo, año)
            i = i + 1
        Next
        numCol = i * 7890
        iact = i + 2
        sw.WriteLine("5880{0}000                                                                        ", cif)
        sw.WriteLine("000{0}      0000000{1}0000000{2}                                      ", numCol, i, iact)
        i = iact
        iact = i + 2
        sw.WriteLine("5980{0}000                                                    0001                ", cif)
        sw.WriteLine("000{0}      0000000{1}0000000{2}                                      ", numCol, i, iact)

        MsgBox("Se ha completado el fichero con exito")

    End Sub