Tutoriel [VB.NET] Source - EOF ( End Of File )

Kilo-25

Premium™
Premium™
28/4/17
75
57
618
#1
Code:
Public Function ReadEOFData(ByRef FilePath As String) As String
        On Error GoTo Err_Renamed
        Dim sEOFBuf, sFileBuf, sChar As String
        Dim lPos2, lFF, lPos, lCount As Integer
        If Dir(FilePath) = "" Then GoTo Err_Renamed
        lFF = FreeFile()
        FileOpen(lFF, FilePath, OpenMode.Binary)
        sFileBuf = Space(LOF(lFF))
        FileGet(lFF, sFileBuf)
        FileClose(lFF)
        lPos = InStr(1, StrReverse(sFileBuf), GetNullBytes(30))
        sEOFBuf = (Mid(StrReverse(sFileBuf), 1, lPos - 1))
        ReadEOFData = StrReverse(sEOFBuf)
        If ReadEOFData = "" Then
        End If
        Exit Function
Err_Renamed:
        ReadEOFData = vbNullString
    End Function
    Public Function GetNullBytes(ByRef lNum As Object) As String
       Dim Buf as String
        Dim i As Short
        For i = 1 To lNum
            Buf = Buf & Chr(0)
        Next
        GetNullBytes = Buf
    End Function
====================================
Exemple :  
_ ofd1 : fichier initial
_ sfd1 : fichier final
_ eofpresent : boolean
Bouton de l'ouverture fichier initial :
If ReadEOFData(ofd1.Filename) = vbNullString Then
        eofpresent = false
    Else
        eofpresent = true
End If
Enregistrement fichier final :
If eofpresent = true Then
        ReadEOFData(sfd1.Filename)
Else
End If
 
J'aime: RoRoH_AR
R

RoRoH_AR

Visiteur
Visiteur
#2
Code:
Public Function ReadEOFData(ByRef FilePath As String) As String
        On Error GoTo Err_Renamed
        Dim sEOFBuf, sFileBuf, sChar As String
        Dim lPos2, lFF, lPos, lCount As Integer
        If Dir(FilePath) = "" Then GoTo Err_Renamed
        lFF = FreeFile()
        FileOpen(lFF, FilePath, OpenMode.Binary)
        sFileBuf = Space(LOF(lFF))
        FileGet(lFF, sFileBuf)
        FileClose(lFF)
        lPos = InStr(1, StrReverse(sFileBuf), GetNullBytes(30))
        sEOFBuf = (Mid(StrReverse(sFileBuf), 1, lPos - 1))
        ReadEOFData = StrReverse(sEOFBuf)
        If ReadEOFData = "" Then
        End If
        Exit Function
Err_Renamed:
        ReadEOFData = vbNullString
    End Function
    Public Function GetNullBytes(ByRef lNum As Object) As String
       Dim Buf as String
        Dim i As Short
        For i = 1 To lNum
            Buf = Buf & Chr(0)
        Next
        GetNullBytes = Buf
    End Function
====================================
Exemple : 
_ ofd1 : fichier initial
_ sfd1 : fichier final
_ eofpresent : boolean
Bouton de l'ouverture fichier initial :
If ReadEOFData(ofd1.Filename) = vbNullString Then
        eofpresent = false
    Else
        eofpresent = true
End If
Enregistrement fichier final :
If eofpresent = true Then
        ReadEOFData(sfd1.Filename)
Else
End If
zhacken tu as du boulot dans tout ces topics :mouahaha:
 
J'aime: Kilo-25

Kilo-25

Premium™
Premium™
28/4/17
75
57
618
#3
Je crée de l'emploi ; nous avons trouvé la solution pour le chomage :D
 
J'aime: RoRoH_AR