Check If .xps file is a v1 or v2

Private Function valid_xps(FName As String) As Boolean
    'function to check if file is xpo with xps header 
    'returns True if is a valid V2 save
 
    Dim vxbyte As Byte
    Dim nFileNum As Long
 
    nFileNum = FreeFile
 
    Open FName For Binary Access Read As #nFileNum
 
    Get #nFileNum, 18, vxbyte
    Close #nFileNum
 
    If vxbyte = &H1 Then
        Valid_xps = False
    Else:
        Valid_xps = True
    End If
 
End Function

Usage:

Assuming txtload.Text contains location of an Xport v2 save:

Dim isvalid As Boolean
 
isvalid = Valid_xps(txtload.Text)
Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback.

Leave a Reply