1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
' Procedure permettant d'écrire les informations dans le fichier texte
Public Sub FormatFile()
Dim i, IdFic As Integer
Dim Chaine, mois, NCpt As String
Dim TtlCpt, TtlMnt As Double
i = 2
'y = Sheets(1).Cells(i, 5)
'Vérif période
mois = InputBox("Donnez la date de traitement au format 'jjmmaa'.", "Période")
IdFic = FreeFile
Open "C:\macrobank\VirSGB" & mois & ".txt" For Output As IdFic
Chaine = "02100001" & mois & "008" & FormatNb(111, 5) & FormatNb(30224399, 11) & FormatStrAfter("UA-Vie", 24) & "00028" & Space(66)
Print #IdFic, Chaine
i = 6: TtlCpt = 3022439
While (Sheets(1).Cells(i, 2).Value <> "")
NCpt = FormatNb(Sheets(1).Cells(i, 8).Value, 9) & Left(Sheets(1).Cells(i, 9).Value, 1)
Chaine = "022" & _
FormatNb(i - 4, 5) & _
mois & "008" & _
FormatNb(Sheets(1).Cells(i, 7).Value, 5) & _
NCpt & Right(Sheets(1).Cells(i, 9).Value, 1) & FormatNb(Sheets(1).Cells(i, 3).Value, 6) & " " & _
FormatStrAfter(Sheets(1).Cells(i, 4).Value & " " & Sheets(1).Cells(i, 5).Value, 24) & _
FormatStrAfter("SGBCI", 17) & _
FormatStrAfter("UA-Vie - Rentes", 30) & _
FormatNb(Sheets(1).Cells(i, 10), 12) & Space(5)
Print #IdFic, Chaine
TtlCpt = TtlCpt + CDbl(NCpt)
TtlMnt = TtlMnt + Sheets(1).Cells(i, 10).Value
i = i + 1
Wend
Chaine = "029" & FormatNb(i - 4, 5) & mois & Space(8) & FormatNbAfter(TtlCpt, 10) & Space(79) & FormatNbAfter(TtlMnt, 12) & Space(5)
Print #IdFic, Chaine
Close IdFic
End Sub
'Fonction permettant d'écrire une chaine de caractères (Str) sur un nombre fini (Lg) de positions
Public Function FormatStr(ByVal Str As String, ByVal Lg As Integer) As String
Dim Result As String
Dim Diff As Integer
Diff = Lg - Len(Str)
If Diff > 0 Then
Result = Space(Diff) & Str
Else
Result = Left(Str, Lg)
End If
FormatStr = Result
End Function
Public Function FormatStrAfter(ByVal Str As String, ByVal Lg As Integer) As String
Dim Result As String
Dim Diff As Integer
Diff = Lg - Len(Str)
If Diff > 0 Then
Result = Str & Space(Diff)
Else
Result = Left(Str, Lg)
End If
FormatStrAfter = Result
End Function
'Fonction permettant d'écrire un nombre (Nb) sur un nombre fini (Lg) de positions
Public Function FormatNb(ByVal Nb As Long, ByVal Lg As Integer) As String
Dim Result As String
Dim Diff As Integer
Diff = Lg - Len(CStr(Nb))
If Diff > 0 Then
Result = Space(Diff) & CStr(Nb)
Else
Result = Left(CStr(Nb), Lg)
End If
Result = Replace(Result, " ", "0")
FormatNb = Result
End Function
'Fonction permettant d'écrire un nombre (Nb) sur un nombre fini (Lg) de positions en prenant les chiffres de la droite vers la gauche
Public Function FormatNbAfter(ByVal Nb As Long, ByVal Lg As Integer) As String
Dim Result As String
Dim Diff As Integer
Diff = Lg - Len(CStr(Nb))
If Diff > 0 Then
Result = Space(Diff) & CStr(Nb)
Else
Result = Right(CStr(Nb), Lg)
End If
Result = Replace(Result, " ", "0")
FormatNbAfter = Result
End Function |
Partager