Avatar billede cablenet.dk Nybegynder
08. november 2002 - 14:02 Der er 3 kommentarer og
1 løsning

VB.NET til VB 6

Nogen der gider at skrive denne kode om til VB6?

Imports System.IO

Public Class Winzip

    Const FejlKode_1 = 1 'okzip25.exe findes ikke - ugyldig path
    Const Fejlkode_2 = 2 'Den angivne fil med filer der skal pakkes findes ikke
    Const Fejlkode_3 = 3 'Zip-filen blev under en ukendt årsag ikke oprettet
    Const Fejlkode_4 = 4 ' Der er ikke noget start directory
    Const fejlkode_5 = 5 ' Path'en hvor zipfilen skal ligge findes ikke
    Const Fejlkode_76 = 76 'den angivne startpath findes ikke

    Private p_PkZip25Path As String
    Private p_Zipfile As String
    Private p_TxtFile As String
    Private p_FileStr As String
    Private P_StartDir As String
    Private P_LastDir As String
    Private p_LogFilePath As String '= "c:\temp\ZipLog.txt"
    Private p_ErrorFilePath As String '= "c:\temp\ZipError.txt"


    Public Function ZipFiles() As Long

        On Error Resume Next

        If PathExist(p_Zipfile) = False Then
            ZipFiles = fejlkode_5
            Exit Function
        End If

        Dim i As Long
        Dim j As Long
        Dim spath As String

        spath = p_TxtFile

        Dim ObjFS As System.IO.FileStream
        Dim ObjSR As System.IO.StreamReader

        If Not File.Exists(p_TxtFile) Then
            ZipFiles = Fejlkode_2
            Exit Function
        End If

        ObjFS = File.Open(spath, FileMode.Open, FileAccess.Read)
        ObjSR = New StreamReader(ObjFS)

        i = 1
        Do
            ObjSR.ReadLine()
            If ObjSR.Peek > -1 Then i = i + 1
        Loop While ObjSR.Peek > -1

        ObjSR.BaseStream.Seek(0, SeekOrigin.Begin)

        j = 1
        For j = 1 To i

            p_FileStr = p_FileStr + Chr(34) + P_StartDir + ObjSR.ReadLine + Chr(34) + " "
        Next j

        ObjSR.Close()

        If Not File.Exists(p_PkZip25Path) Then
            ZipFiles = FejlKode_1
            Exit Function
        End If

        P_LastDir = CurDir()

        If P_StartDir = "" Then
            ZipFiles = Fejlkode_4
            Exit Function
        End If

        If p_LogFilePath = "" Then
            p_LogFilePath = "c:\temp\ZipLog.txt"
        End If

        If p_ErrorFilePath = "" Then
            p_ErrorFilePath = "c:\temp\ZipError.txt"
        End If

        ChDir(P_StartDir)

        Shell("cmd.exe /c " + p_PkZip25Path + " -add -path=current " _
        + Chr(34) + p_Zipfile + Chr(34) _
        + " " + p_FileStr _
        + " " + "1>" + Chr(34) + p_LogFilePath _
        + Chr(34) + " " + "2>" + Chr(34) _
        + p_ErrorFilePath + Chr(34), vbHide, True)

        ZipFiles = 0

        ChDir(P_LastDir)

        If Not File.Exists(p_Zipfile) Then
            ZipFiles = Fejlkode_3
        End If

        If Err.Number Then
            Select Case Err.Number
                Case 76
                    ZipFiles = Fejlkode_76
                    Exit Function
            End Select
        End If

    End Function

    Private Function PathExist(ByVal FullPath) As Boolean
        Dim FuulLen As Integer
        Dim ZipFileLen As Integer

        ZipFileLen = Len(Path.GetFileName(FullPath))
        FuulLen = Len(Path.GetFullPath(FullPath))

        If Not Directory.Exists(Left(FullPath, FuulLen - ZipFileLen)) Then
            PathExist = False
        Else
            PathExist = True
        End If

    End Function

    Public Function GetErrorText() As String

        On Error Resume Next

        Dim ObjFS1 As System.IO.FileStream
        Dim ObjSR1 As System.IO.StreamReader

        If Not File.Exists(p_ErrorFilePath) Then
            GetErrorText = "No Error file found"
            Exit Function
        End If

        ObjFS1 = File.Open(p_ErrorFilePath, FileMode.Open, FileAccess.Read)
        ObjSR1 = New StreamReader(ObjFS1)
        ObjSR1.BaseStream.Seek(0, SeekOrigin.Begin)
        GetErrorText = ObjSR1.ReadToEnd()

        ObjSR1.Close()

    End Function

    Public Function GetLogText() As String

        On Error Resume Next

        Dim ObjFS1 As System.IO.FileStream
        Dim ObjSR1 As System.IO.StreamReader

        If Not File.Exists(p_LogFilePath) Then
            GetLogText = "No log file found"
            Exit Function
        End If

        ObjFS1 = File.Open(p_LogFilePath, FileMode.Open, FileAccess.Read)
        ObjSR1 = New StreamReader(ObjFS1)
        ObjSR1.BaseStream.Seek(0, SeekOrigin.Begin)
        GetLogText = ObjSR1.ReadToEnd()

        ObjSR1.Close()

    End Function

    Public Property StartPath() As String
        Get
            StartPath = P_StartDir
        End Get
        Set(ByVal Value As String)

            P_StartDir = Value

        End Set
    End Property

    Public Property ErrorFileNameAndPath() As String
        Get
            ErrorFileNameAndPath = p_ErrorFilePath
        End Get
        Set(ByVal Value As String)
            p_ErrorFilePath = Value
        End Set
    End Property

    Public Property LogFileNameAndPath() As String
        Get
            LogFileNameAndPath = p_LogFilePath
        End Get
        Set(ByVal Value As String)
            p_LogFilePath = Value
        End Set
    End Property

    Public Property TxtFilePath() As String
        Get
            TxtFilePath = p_TxtFile
        End Get
        Set(ByVal Value As String)
            p_TxtFile = Value
        End Set
    End Property

    Public Property Pkzip25Path() As String
        Get
            Pkzip25Path = p_PkZip25Path

        End Get
        Set(ByVal Value As String)
            p_PkZip25Path = Value
        End Set
    End Property

    Public Property ZipFileNameAndPath() As String
        Get
            ZipFileNameAndPath = p_Zipfile
        End Get
        Set(ByVal Value As String)
            p_Zipfile = Value
        End Set
    End Property
End Class
Avatar billede cablenet.dk Nybegynder
08. november 2002 - 14:04 #1
Det skal helst gå hurtigt! Inden ½ time...kl er nu: 14:01
Avatar billede cablenet.dk Nybegynder
08. november 2002 - 14:20 #2
Nogender kan hjælpe?
Avatar billede cablenet.dk Nybegynder
08. november 2002 - 14:39 #3
lukker.....sry...:(
Avatar billede cablenet.dk Nybegynder
08. november 2002 - 14:39 #4
lukker
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester