当我运行一个程序,它就会读取软盘中的"102mm.txt"与程序目录的"mm201.txt"对比,如果一样就启动程序,不一样(或没插入磁盘)就退出.

解决方案 »

  1.   

    陈述 or 提问 or else?
      

  2.   

    on error goto lin
    s1=读取软盘中的"102mm.txt" '这个会吧。
    s2=读取程序目录的"mm201.txt"
    if s1<>s2 then end
    exit sub
    lin:
    msgbox err.description
      

  3.   

    Private Sub Form_Load()
        If CompFile("a:\102mm.txt", App.Path + "\mm201.txt") = False Then
            End
        End If
    End Sub
    Private Function CompFile(ByVal file1 As String, ByVal file2 As String) As Boolean
        On Error GoTo myerr
        CompFile = False
        Dim buff1() As Byte
        Dim l1 As Long
        l1 = FileLen(file1)
        ReDim buff1(l1 - 1)
        Open file1 For Binary Access Read As #1
        Put #1, , buff1
        Close #1
        Dim s1 As String
        s1 = StrConv(buff1, vbUnicode)
        
        Dim buff2() As Byte
        Dim l2 As Long
        l2 = FileLen(file2)
        ReDim buff1(l2 - 1)
        Open file2 For Binary Access Read As #1
        Put #1, , buff2
        Close #1
        Dim s2 As String
        s2 = StrConv(buff2, vbUnicode)
        Dim a As Boolean
        a = StrComp(s1, s2, vbBinaryCompare)
        CompFile = Not a
        Exit Function
    myerr:
        CompFile = False
    End Function