explain me this code please !!

Status
Not open for further replies.

petogaz

In Runtime
Messages
164
hi all !!
is there someone could explain me this code please (just tell me what this code is supposed to do. very important plz):

Code:
Sub doSomething(filename As String) 

    Dim exApp As New Excel.Application 
    Dim exWork As Excel.Workbook 
    Dim exSheet As Excel.Worksheet 
    Dim strTmp As String 
    Dim i As Integer 
    Dim ttt As String 
    Dim tmp As String 
    Dim String1 As String 
    Dim VarT As String 
    Dim VarTb As String 
    
    
    
        
    exApp.Visible = True 
    On Error GoTo hell 
    i = InStrRev(filename, "\") 
    ttt = Mid(filename, i + 1, 2) 
    Set exWork = exApp.Workbooks.Open(filename, False, False) 
    Set exSheet = exWork.Sheets(1) 
    For Each exSheet In exWork.Sheets 
        String1 = "" 
        exSheet.Select 
        GoodDate = exSheet.Cells(2, "C") 
        GoodDate = Right(GoodDate, Len(GoodDate) - InStr(GoodDate, "day ") - 3) 
        GoodDate = Format(GoodDate, "YYYY-MM-DD") 
        i = 8 
        While Trim(exSheet.Cells(i, "A")) <> "" 
        
        ScheduleDate = "" 
        BroadCastDate = "" 
        Ttime = "" 
        txtrem = "" 
        Duration = "" 
        Title = "" 
        orig_desc = "" 
        channel_type = "" 
        ct_date_sch = "" 
        canceled = "" 
        video_uk = "" 
        video_eur = "" 
        vps = "" 
        teletex = "" 
        teletex_lan = "" 
        Live = "" 
        Stereo = "" 
        two_tone = "" 
        two_tone_lan = "" 
        subtitle = "" 
        subtitle_lan = "" 
        encryption = "" 
        Language = "" 
        highlight = "" 
        first_showing = "" 
        last_showing = "" 
        repeated_from = "" 
        simulcast = "" 
        pay_per_view = "" 
        is_umbrella = "" 
        channel_rating = "" 
        channel_cat = "" 
        Ori_Title = "" 
        episode_title = "" 
        ori_epi_title = "" 
        Episode_nb = "" 
        Version = "" 
        aka_title = "" 
        actor_list = "" 
        director = "" 
        presenter = "" 
        guests = "" 
        production = "" 
        distribution = "" 
        country = "" 
        Year_of_Prod = "" 
        Emission_duration = "" 
        ori_language = "" 
        black_white = "" 
        colorised = "" 
        categorie = "" 
        Ttype = "" 
        content = "" 
        starrating = "" 
        certification = "" 
        pilot = "" 
        synopsis = "" 
        text_1 = "" 
        text_2 = "" 
        credits = "" 
        Main_actor1 = "" 
        Role_actor1 = "" 
        Main_actor2 = "" 
        Role_actor2 = "" 
        Main_actor3 = "" 
        Role_actor3 = "" 
        Main_actor4 = "" 
        Role_actor4 = "" 
        Main_actor5 = "" 
        Role_actor5 = "" 
        Main_actor6 = "" 
        Role_actor6 = "" 
        Regional = "" 
        Silent = "" 
        Dolby = "" 
        SizeNine = "" 
        sched_extra = "" 
        dumpdate = "" 
        ID = "" 
        moved_id = "" 

        
            'strTmp = strTmp & "pmv" & vbTab & GoodDate & vbTab 
            VarT = exSheet.Cells(i, "A") 
            If i = 8 Then 
                VarT = "0600" 
            End If 
            
            If exSheet.Cells(i + 1, "A") <> "" Then 
                VarTb = exSheet.Cells(i + 1, "A") 
            Else 
                VarTb = "0600" 
            End If 
            If InStr(VarT, ":") <> 0 Then 
                VarT = Replace(VarT, ":", "") 
            End If 
            If InStr(VarTb, ":") <> 0 Then 
                VarTb = Replace(VarTb, ":", "") 
            End If 
            Ttime = Mid(VarT, 1, 2) & ":" & Mid(VarT, 3, 2) 
            Ttimeb = Mid(VarTb, 1, 2) & ":" & Mid(VarTb, 3, 2) 
            
            
            Ttime = Format(DateAdd("h", 1, CDate(Ttime)), "HH:NN") 
            Ttimeb = Format(DateAdd("h", 1, CDate(Ttimeb)), "HH:NN") 
            
            If Ttime < CDate("07:00") And Ttime >= CDate("00:00") Then 
                Broad_Date = Format(DateAdd("d", 1, GoodDate), "yyyy-mm-dd") & " " & Ttime 
            Else 
                Broad_Date = GoodDate & " " & Ttime 
            End If 
            
            Duration = DateDiff("N", Ttime, Ttimeb) 
            If Duration < 0 Then 
                Duration = Duration + 1440 
            End If 
            Ttime = Format(Ttime, "HHNN") 
                        
            Title = exSheet.Cells(i, "B") 
            If InStr(Title, "(") <> 0 Then 
                orig_desc = Right(Title, Len(Title) - InStr(Title, "(") + 1) 
                Title = Left(Title, InStr(Title, " (") - 1) 
            End If 
            If InStr(orig_desc, "Live") <> 0 Then 
                Live = "1" 
            End If 
            If InStr(orig_desc, "(R)") <> 0 Then 
                repeated_from = "01/01/1901" 
            End If 
            If InStr(orig_desc, "'") <> 0 Then 
                Emission_duration = Right(orig_desc, Len(orig_desc) - InStrRev(orig_desc, " ")) 
                Emission_duration = Replace(Emission_duration, "'", "") 
            End If 
            
            Episode_nb = exSheet.Cells(i, "C") 
            synopsis = exSheet.Cells(i, "E") 
            If exSheet.Cells(i, "F") <> "" Then 
                channel_cat = exSheet.Cells(i, "F") 
                If exSheet.Cells(i, "G") <> "" Then 
                    channel_cat = channel_cat & " / " & exSheet.Cells(i, "G") 
                End If 
            End If 
            
            'If exSheet.Cells(i, "C") <> "" Then 
            '    strTmp = strTmp & "Episode Number: " & exSheet.Cells(i, "C") & vbCrLf 
            'End If 
            'If exSheet.Cells(i, "F") <> "" Then 
            '    strTmp = strTmp & "Genre: " & exSheet.Cells(i, "F") & vbCrLf 
            'End If 
            'If exSheet.Cells(i, "G") <> "" Then 
            '    strTmp = strTmp & "Subgenre: " & exSheet.Cells(i, "G") & vbCrLf 
            'End If 
            'strTmp = strTmp & exSheet.Cells(i, "E") & vbCrLf 
            i = i + 1 
            
            String1 = String1 & "pmv" & vbTab & GoodDate & vbTab & Broad_Date & _ 
        vbTab & Ttime & vbTab & txtrem & vbTab & Duration & vbTab & Title & vbTab & _ 
        orig_desc & vbTab & channel_type & vbTab & ct_date_sch & vbTab & canceled & _ 
        vbTab & video_uk & vbTab & video_eur & vbTab & vps & vbTab & teletex & _ 
        vbTab & teletex_lan & vbTab & Live & vbTab & Stereo & vbTab & two_tone & _ 
        vbTab & two_tone_lan & vbTab & subtitle & vbTab & subtitle_lan & vbTab & _ 
        encryption & vbTab & Language & vbTab & highlight & vbTab & first_showing & _ 
        vbTab & last_showing & vbTab & repeated_from & vbTab & simulcast & vbTab & _ 
        pay_per_view & vbTab & is_umbrella & vbTab & channel_rating & vbTab & channel_cat & _ 
        vbTab & Ori_Title & vbTab & episode_title & vbTab & ori_epi_title & vbTab & _ 
        Episode_nb & vbTab & Version & vbTab & aka_title & vbTab & actor_list & vbTab & _ 
        director & vbTab & presenter & vbTab & guests & vbTab & production & vbTab & _ 
        distribution & vbTab & country & vbTab & Year_of_Prod & vbTab & _ 
        Emission_duration & vbTab & ori_language & vbTab & black_white & vbTab & _ 
        colorised & vbTab & categorie & vbTab & Ttype & vbTab & content & vbTab & _ 
        starrating & vbTab & certification & vbTab & pilot & vbTab & synopsis & _ 
        vbTab & text_1 & vbTab & text_2 & vbTab & credits & vbTab & Main_actor1 & _ 
        vbTab & Role_actor1 & vbTab & Main_actor2 & vbTab & Role_actor2 & vbTab & _ 
        Main_actor3 & vbTab & Role_actor3 & vbTab & Main_actor4 & vbTab & _ 
        Role_actor4 & vbTab & Main_actor5 & vbTab & Role_actor5 & vbTab & _ 
        Main_actor6 & vbTab & Role_actor6 & vbTab & Regional & vbTab & Silent & _ 
        vbTab & Dolby & vbTab & SizeNine & vbTab & sched_extra & vbTab & dumpdate & _ 
        vbTab & ID & vbTab & moved_id & vbCrLf 
          
        Wend 
        PrintOut String1, filename & ".txt" 
        
    Next 
    exWork.Close False 
    exApp.Quit 
    Set exApp = Nothing 
    Exit Sub 
hell: 
    MsgBox "error : " & Err.Number & ", " & Err.Description & ", " & Err.Source 
    exApp.Quit 
    Set exApp = Nothing 
End Sub 

Private Sub CmdDo_Click() 
    Dim i As Integer 
    For i = 0 To File1.ListCount - 1 
        If File1.Selected(i) Then doSomething File1.Path & "\" & File1.List(i) 
    Next 
End Sub 

Private Sub CmdExit_Click() 
    Unload Me 
End Sub 

Private Sub Dir1_Change() 
    File1.Path = Dir1.Path 
End Sub 

Private Sub Drive1_Change() 
    On Error GoTo hell 
    Dir1.Path = Drive1 
    File1.Path = Dir1.Path 
hell: 
    If Err.Number = 68 Then MsgBox "Drives unavailable." 
    Err.Clear 
End Sub 

Private Sub PrintOut(str As String, filename As String) 
    Open filename For Append Shared As #1 
    Print #1, str 
    Close #1 
End Sub
 
it looks like it's entering movie information from an Excel file to a text file using a lot of formatting and error-checking. can someone else elaborate?
 
Have you taken the code and pasted into a project and tried to run it?

A few lines of code is one thing but I do nto have the free time to walk through you block above and document it.
 
do you want it explaining line by line or what ? Also why dont you just try it out and see what happens when you try to use the code? That way you will see what happens when you try it out !
 
Status
Not open for further replies.
Back
Top Bottom