Attribute VB_Name = "Edit"
Option Explicit


'----------------------------------------------------------
'kontrola existence denniho textu (+ kontrola obsazeni textu)
'----------------------------------------------------------

Public Sub KontrolaTextu(OptA As Boolean)

    Dim i As Integer
    Dim j As Integer
    
    If (OptA = True) Then
    
        For i = 0 To 1442
            For j = 1 To 2
                CelyText(i, j) = ""
                CelyTextZ(i, j) = ""
            Next j
        Next i
        
    Else:
    
        For i = 0 To 1442
            CelyText(i, 1) = ""
            CelyText(i, 2) = ""
        Next i
        
    End If

    
    If (DenNeboNahr = "D") Then
        
        If (Dir(CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds") <> "") Then
        
            Open CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds" For Input As #9
                For i = 0 To 1442
                    Line Input #9, CelyText(i, 1)
                Next i
            Close #9
            
            If (ProbihaEditace = True) Then
                If (CelyText(1440, 1) = "" Or CelyText(1440, 1) = AktJmeno) Then
                
                    CelyText(1440, 1) = AktJmeno
                    CelyText(1441, 1) = Date & " v " & Time
                    CelyText(1442, 1) = Date & " v " & Time
            
                    Open CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds" For Output As #9
                        For i = 0 To 1442
                            Print #9, CelyText(i, 1)
                        Next i
                    Close #9
                        
                    IDT = True
                    
                    If (OptA = True) Then
                        ZobrazitDen
                    End If
                    
                Else
            
                    Form1.FraTextObsazeno.Visible = True
                    Form1.LblObsazenoE = CelyText(1440, 1)
                    Form1.LblObsazenoECas = CelyText(1441, 1)
                    Form1.LblObsazenoEPosledni = CelyText(1442, 1)
                    
                    For i = 0 To 1442
                        CelyTextZ(i, 1) = CelyText(i, 1)
                    Next i
                    
                    IDT = False
                
                End If
            Else
                
                If (OptA = True) Then
                    ZobrazitDen
                End If
                
            End If
            
        Else:   Form1.FraEditText1 = ""
                Form1.FraEditText2 = ""
                Form1.FraEditText3 = ""
                Form1.FraEditText4 = ""
                Form1.FraEditText5 = ""
                Form1.FraEditText6 = ""
                Form1.FraEditText7 = ""
                
                Form1.FraEditCas1 = ""
                Form1.FraEditCas2 = ""
                Form1.FraEditCas3 = ""
                Form1.FraEditCas5 = ""
                Form1.FraEditCas6 = ""
                Form1.FraEditCas7 = ""
                
                If (ProbihaEditace = True) Then
                    CelyText(1440, 1) = AktJmeno
                    CelyText(1441, 1) = Date & " v " & Time
                    CelyText(1442, 1) = Date & " v " & Time
            
                    Open CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds" For Output As #9
                        For i = 0 To 1442
                            Print #9, CelyText(i, 1)
                        Next i
                    Close #9
                        
                    IDT = True
                End If

        End If
    
    ElseIf (DenNeboNahr = "N") Then
    
        Open CestaSoubory & "/RDS-Texty/NahradniText.rds" For Input As #9
            For i = 0 To 1442
                Line Input #9, CelyText(i, 1)
            Next i
        Close #9
        
            If (ProbihaEditace = True) Then
                If (CelyText(1440, 1) = "" Or CelyText(1440, 1) = AktJmeno) Then
                
                    CelyText(1440, 1) = AktJmeno
                    CelyText(1441, 1) = Date & " v " & Time
                    CelyText(1442, 1) = Date & " v " & Time
            
                    Open CestaSoubory & "/RDS-Texty/NahradniText.rds" For Output As #9
                        For i = 0 To 1442
                            Print #9, CelyText(i, 1)
                        Next i
                    Close #9
                        
                    IDT = True
                    
                    If (OptA = True) Then
                        ZobrazitDen
                    End If
                    
                Else
            
                    Form1.FraTextObsazeno.Visible = True
                    Form1.LblObsazenoE = CelyText(1440, 1)
                    Form1.LblObsazenoECas = CelyText(1441, 1)
                    Form1.LblObsazenoEPosledni = CelyText(1442, 1)
                    
                    For i = 0 To 1442
                        CelyTextZ(i, 1) = CelyText(i, 1)
                    Next i
                    
                    IDT = False
                
                End If
             Else
                
                If (OptA = True) Then
                    ZobrazitDen
                End If
                
            End If
            
    Else:
        If (Dir(CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds") <> "") Then
        
            Open CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds" For Input As #9
                For i = 0 To 1442
                    Line Input #9, CelyText(i, 1)
                Next i
            Close #9
            
            If (ProbihaEditace = True) Then
                If (CelyText(1440, 1) = "" Or CelyText(1440, 1) = AktJmeno) Then
                
                    CelyText(1440, 1) = AktJmeno
                    CelyText(1441, 1) = Date & " v " & Time
                    CelyText(1442, 1) = Date & " v " & Time
            
                    Open CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds" For Output As #9
                        For i = 0 To 1442
                            Print #9, CelyText(i, 1)
                        Next i
                    Close #9
                        
                    IDT = True
                    
                    If (OptA = True) Then
                        ZobrazitDen
                    End If
                    
                Else
            
                    Form1.FraTextObsazeno.Visible = True
                    Form1.LblObsazenoE = CelyText(1440, 1)
                    Form1.LblObsazenoECas = CelyText(1441, 1)
                    Form1.LblObsazenoEPosledni = CelyText(1442, 1)
                    
                    For i = 0 To 1442
                        CelyTextZ(i, 1) = CelyText(i, 1)
                    Next i
                    
                    IDT = False
                
                End If
            Else
                
                If (OptA = True) Then
                    ZobrazitDen
                End If
                
            End If
                    
        Else:   Form1.FraEditText1 = ""
                Form1.FraEditText2 = ""
                Form1.FraEditText3 = ""
                Form1.FraEditText4 = ""
                Form1.FraEditText5 = ""
                Form1.FraEditText6 = ""
                Form1.FraEditText7 = ""
                
                Form1.FraEditCas1 = ""
                Form1.FraEditCas2 = ""
                Form1.FraEditCas3 = ""
                Form1.FraEditCas5 = ""
                Form1.FraEditCas6 = ""
                Form1.FraEditCas7 = ""
                
                If (ProbihaEditace = True) Then
                    CelyText(1440, 1) = AktJmeno
                    CelyText(1441, 1) = Date & " v " & Time
                    CelyText(1442, 1) = Date & " v " & Time
            
                    Open CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds" For Output As #9
                        For i = 0 To 1442
                            Print #9, CelyText(i, 1)
                        Next i
                    Close #9
                        
                    IDT = True
                End If
        End If

    End If

    ZbyvaNaRadku
    
    If (OptA = False) Then
        Form1.ScrollEdit.Value = Form1.FraCboCas.ListIndex
    End If
    
    EditScroll

End Sub


'----------------------------------------------------------
'zobrazeni vybraneho dne
'----------------------------------------------------------

Public Sub ZobrazitDen()

    Dim i As Integer
    Dim j As Integer
    
    For i = 0 To 1442
        For j = 1 To 2
            CelyTextZ(i, j) = ""
        Next j
        
    Next i
      For i = 0 To 1442
        For j = 1 To 2
            CelyTextZ(i, j) = CelyText(i, j)
        Next j
      Next i

    Pozice = 3
    Form1.ScrollEdit.Value = Pozice
    Form1.FraCboCas.ListIndex = Pozice

    Form1.FraEditText1 = CelyTextZ(0, 1)
    Form1.FraEditText2 = CelyTextZ(1, 1)
    Form1.FraEditText3 = CelyTextZ(2, 1)
    Form1.FraEditText4 = CelyTextZ(3, 1)
    Form1.FraEditText5 = CelyTextZ(4, 1)
    Form1.FraEditText6 = CelyTextZ(5, 1)
    Form1.FraEditText7 = CelyTextZ(6, 1)
    
    Form1.FraEditCas1 = "00:00"
    Form1.FraEditCas2 = "00:01"
    Form1.FraEditCas3 = "00:02"
    Form1.FraEditCas5 = "00:04"
    Form1.FraEditCas6 = "00:05"
    Form1.FraEditCas7 = "00:06"
    
    If (Form1.FraEditText4.Enabled = True) Then
        Form1.FraEditText4.SetFocus
    End If
    
End Sub


'----------------------------------------------------------
'uvolneni denniho textu
'----------------------------------------------------------

Public Sub UnloadEditText()

    Dim i As Integer
    Dim pomPrazdny As Boolean

    pomPrazdny = True
    Form1.FraTextObsazeno.Visible = False
    i = 0

    If (IDT = True) Then
        
        CelyText(1440, 1) = ""
        CelyText(1441, 1) = ""
        CelyText(1442, 1) = ""
        
        Do While (i < 1440 And pomPrazdny = True)
             
            If (CelyText(i, 1) <> "") Then
                pomPrazdny = False
            End If
            i = i + 1
             
        Loop
        
        If (pomPrazdny = False) Then
            
            If (DenNeboNahr = "D") Then
                Open CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds" For Output As #10
            ElseIf (DenNeboNahr = "N") Then
                Open CestaSoubory & "/RDS-Texty/NahradniText.rds" For Output As #10
            Else
                Open CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds" For Output As #10
            End If
                    
            For i = 0 To 1442
                Print #10, CelyText(i, 1)
            Next i
        
            Close #10
        
            IDT = False
            
        Else:
            If (DenNeboNahr <> "N") Then
                If (DenNeboNahr = "D") Then
                    If (Dir(CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds") <> "") Then
                        Kill (CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) + ".rds")
                    End If
                Else
                    If (Dir(CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds") <> "") Then
                        Kill (CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds")
                    End If
                End If
            End If
        End If
    
    End If
    
    DenUlozen = False

End Sub


'----------------------------------------------------------
'vytvoreni souboru
'----------------------------------------------------------

Public Sub UlozText()

    Dim j As Integer
    Dim k As Integer

    CelyTextZ(1440, 1) = AktJmeno
    CelyTextZ(1441, 1) = Date & " v " & Time
    CelyTextZ(1442, 1) = Date & " v " & Time
    
    If (DenNeboNahr = "D") Then
    
        If (Dir(CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds") <> "") Then
            Kill (CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds")
        End If
        
        Open CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds" For Output As #6
        
    ElseIf (DenNeboNahr = "N") Then
    
        Kill (CestaSoubory & "/RDS-Texty/NahradniText.rds")
        Open CestaSoubory & "/RDS-Texty/NahradniText.rds" For Output As #6
        
    Else
    
        If (Dir(CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds") <> "") Then
            Kill (CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds")
        End If
        
        Open CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds" For Output As #6
    
    End If
        
    LogEdit
    
    For k = 0 To 1442
        CelyText(k, 1) = CelyTextZ(k, 1)
        Print #6, CelyText(k, 1)
    Next k
            
    Print #6, "" & vbCrLf
        
    Close #6
    
    DenUlozen = True

End Sub


'----------------------------------------------------------
'kontrola ulozeni denniho textu
'----------------------------------------------------------

Public Sub KontrolaUlozeniTextu()

    Dim i As Integer
    Dim ZmenaTextu As Boolean
    
    ZmenaTextu = False
    i = 0
            
    Do While (i < 1440 And ZmenaTextu = False)
    
        If (CelyText(i, 1) <> CelyTextZ(i, 1)) Then
            ZmenaTextu = True
        End If
        
        i = i + 1
        
    Loop

    If (ZmenaTextu = True) Then
        
        Form1.FraEditUloz.Visible = True
        OdpovedUzivateleNaUlozeni = 0

         Do While OdpovedUzivateleNaUlozeni = 0
            
            DoEvents
      
            If (OdpovedUzivateleNaUlozeni = 1) Then
                UnloadEditText
            End If
                        
            If (OdpovedUzivateleNaUlozeni = 2) Then
                UlozText
                UnloadEditText
            End If

        Loop
        
    Form1.FraEditUloz.Visible = False
    Form1.Visible = True
    
    Else
    
        UnloadEditText
    
    End If

End Sub


'----------------------------------------------------------
'zobrazeni kalendare
'----------------------------------------------------------

Public Sub kalendar()

    KontrolaUlozeniTextu
    Form1.FraTextObsazeno.Visible = False
    EDen = Form1.Calendar1.Day
    EMesic = Form1.Calendar1.Month
    ERok = Form1.Calendar1.Year
    EDatum = (EDen + "/" + EMesic + "/" + ERok)
    Form1.LblEditDen.Caption = Format(EDatum, "dddd  dd . mm . yyyy")
    EDatumPom = EDatum
    DenNeboNahr = "D"
    Form1.FraEditCal.Visible = False
    
    If (ProbihaEditace = True) Then
        Editace
    End If
    
    KontrolaTextu True

End Sub
    
    
'----------------------------------------------------------
'vyhledani dennich textu a jejich zobrazeni v kalendari
'----------------------------------------------------------

Public Sub HledejDenniTexty()

    Dim fl As Folder
    Dim i As Integer
    
    For i = 0 To 41
        Form1.PicCal(i).Visible = False
    Next i
    
    For i = 0 To 41
        Form1.PicCalSed(i).Visible = False
    Next i
        
    Set fl = fso.GetFolder(CestaSoubory & "/RDS-Texty/")
    
    Select Case Weekday(EDatumPom, vbMonday)
        
        Case 1: EDatumPom = DateAdd("d", -7, EDatumPom)
        Case 2: EDatumPom = DateAdd("d", -1, EDatumPom)
        Case 3: EDatumPom = DateAdd("d", -2, EDatumPom)
        Case 4: EDatumPom = DateAdd("d", -3, EDatumPom)
        Case 5: EDatumPom = DateAdd("d", -4, EDatumPom)
        Case 6: EDatumPom = DateAdd("d", -5, EDatumPom)
        Case 7: EDatumPom = DateAdd("d", -6, EDatumPom)
            
    End Select

    For i = 0 To 41
    
        If (Dir(CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(DateAdd("d", i, EDatumPom)) & ".rds") <> "") Then
    
            If (Month(DateAdd("d", i, EDatumPom)) = CboCalIndex(1) + 1) Then
                Form1.PicCal(i).Visible = True
            Else
                Form1.PicCalSed(i).Visible = True
            End If
    
        End If
        
    Next i
    
    EDatumPom = Date
    
End Sub


'----------------------------------------------------------
'zmena mesice
'----------------------------------------------------------

Public Sub NovyMesic()

    If (CboCalIndex(1) > Form1.CboCalMes.ListIndex) Then
    
        Do While (CboCalIndex(1) > Form1.CboCalMes.ListIndex)
            CboCalIndex(1) = CboCalIndex(1) - 1
            Form1.Calendar1.PreviousMonth
        Loop
    
    Else
    
        Do While (CboCalIndex(1) < Form1.CboCalMes.ListIndex)
            CboCalIndex(1) = CboCalIndex(1) + 1
            Form1.Calendar1.NextMonth
        Loop
    
    End If
    
        Form1.CboCalMes.ListIndex = CboCalIndex(1)
        EDatumPom = ("1" & "/" & CboCalIndex(1) + 1 & "/" & CboCalIndex(2) + 1950)
        HledejDenniTexty

End Sub


'----------------------------------------------------------
'zmena roku
'----------------------------------------------------------

Public Sub Novyrok()

    If (CboCalIndex(2) > Form1.CboCalRok.ListIndex) Then
    
        Do While (CboCalIndex(2) > Form1.CboCalRok.ListIndex)
            CboCalIndex(2) = CboCalIndex(2) - 1
            Form1.Calendar1.PreviousYear
        Loop
    
    Else
    
        Do While (CboCalIndex(2) < Form1.CboCalRok.ListIndex)
            CboCalIndex(2) = CboCalIndex(2) + 1
            Form1.Calendar1.NextYear
        Loop
    
    End If
    
        Form1.CboCalRok.ListIndex = CboCalIndex(2)
        EDatumPom = ("1" & "/" & CboCalIndex(1) + 1 & "/" & CboCalIndex(2) + 1950)
        HledejDenniTexty
    
End Sub


'----------------------------------------------------------
'scrollovani
'----------------------------------------------------------

Public Sub EditScroll()

    Dim c As String
    Dim i As Integer
    
    Pozice = Form1.ScrollEdit.Value
    Form1.FraCboCas.ListIndex = Form1.ScrollEdit.Value
    
    If (Pozice >= 3) And (Pozice <= 1436) Then
        Form1.FraEditText1 = CelyTextZ(Pozice - 3, 1)
        Form1.FraEditText2 = CelyTextZ(Pozice - 2, 1)
        Form1.FraEditText3 = CelyTextZ(Pozice - 1, 1)
        Form1.FraEditText4 = CelyTextZ(Pozice, 1)
        Form1.FraEditText5 = CelyTextZ(Pozice + 1, 1)
        Form1.FraEditText6 = CelyTextZ(Pozice + 2, 1)
        Form1.FraEditText7 = CelyTextZ(Pozice + 3, 1)
            
        Form1.FraEditCas1 = CasTextu(Pozice - 3)
        Form1.FraEditCas2 = CasTextu(Pozice - 2)
        Form1.FraEditCas3 = CasTextu(Pozice - 1)
        Form1.FraEditCas5 = CasTextu(Pozice + 1)
        Form1.FraEditCas6 = CasTextu(Pozice + 2)
        Form1.FraEditCas7 = CasTextu(Pozice + 3)
        
        For i = 0 To 6
        
            Form1.FraEditCheck(i).Enabled = True
            
            If (CelyTextZ(Pozice - 3 + i, 2) = "A") Then
                Form1.FraEditCheck(i).Value = 1
            Else
                Form1.FraEditCheck(i).Value = 0
            End If
            
        Next i
        
    ElseIf (Pozice < 3) Then
        
        Form1.FraEditText1 = ""
        Form1.FraEditText2 = ""
        Form1.FraEditText3 = ""
        
        Form1.FraEditCas1 = ""
        Form1.FraEditCas2 = ""
        Form1.FraEditCas3 = ""
        
        If Pozice = 2 Then
            
            Form1.FraEditText2 = CelyTextZ(Pozice - 2, 1)
            Form1.FraEditText3 = CelyTextZ(Pozice - 1, 1)
        
            Form1.FraEditCas2 = CasTextu(Pozice - 2)
            Form1.FraEditCas3 = CasTextu(Pozice - 1)
            
            For i = 1 To 2
            
                Form1.FraEditCheck(i).Enabled = True
                
                If (CelyTextZ(Pozice - 3 + i, 2) = "A") Then
                    Form1.FraEditCheck(i).Value = 1
                Else
                    Form1.FraEditCheck(i).Value = 0
                End If
                
            Next i
            
        ElseIf Pozice = 1 Then
        
            Form1.FraEditText3 = CelyTextZ(Pozice - 1, 1)
            
            Form1.FraEditCas3 = CasTextu(Pozice - 1)
            
            Form1.FraEditCheck(2).Enabled = True
            
            If (CelyTextZ(Pozice - 1, 2) = "A") Then
                Form1.FraEditCheck(2).Value = 1
            Else
                Form1.FraEditCheck(2).Value = 0
            End If
            
            
        End If
        
        Form1.FraEditText4 = CelyTextZ(Pozice, 1)
        Form1.FraEditText5 = CelyTextZ(Pozice + 1, 1)
        Form1.FraEditText6 = CelyTextZ(Pozice + 2, 1)
        Form1.FraEditText7 = CelyTextZ(Pozice + 3, 1)
        
        Form1.FraEditCas5 = CasTextu(Pozice + 1)
        Form1.FraEditCas6 = CasTextu(Pozice + 2)
        Form1.FraEditCas7 = CasTextu(Pozice + 3)
        
        For i = 3 To 6
        
            Form1.FraEditCheck(i).Enabled = True
            
            If (CelyTextZ(Pozice - 3 + i, 2) = "A") Then
                Form1.FraEditCheck(i).Value = 1
            Else
                Form1.FraEditCheck(i).Value = 0
            End If
            
        Next i
        
        For i = 0 To 2
            Form1.FraEditCheck(i).Enabled = False
        Next i
    
    ElseIf (Pozice > 1436) Then
        
        Form1.FraEditText5 = ""
        Form1.FraEditText6 = ""
        Form1.FraEditText7 = ""
        
        Form1.FraEditCas5 = ""
        Form1.FraEditCas6 = ""
        Form1.FraEditCas7 = ""
        
        If Pozice = 1437 Then
            
                Form1.FraEditText5 = CelyTextZ(Pozice + 1, 1)
                Form1.FraEditText6 = CelyTextZ(Pozice + 2, 1)
            
                Form1.FraEditCas5 = CasTextu(Pozice + 1)
                Form1.FraEditCas6 = CasTextu(Pozice + 2)
                
           For i = 4 To 5
           
                Form1.FraEditCheck(i).Enabled = True
                
                If (CelyTextZ(Pozice - 3 + i, 2) = "A") Then
                    Form1.FraEditCheck(i).Value = 1
                Else
                    Form1.FraEditCheck(i).Value = 0
                End If
                
           Next i
            
        ElseIf Pozice = 1438 Then
        
            Form1.FraEditText5 = CelyTextZ(Pozice + 1, 1)
            
            Form1.FraEditCas5 = CasTextu(Pozice + 1)
            
            Form1.FraEditCheck(4).Enabled = True
            
            If (CelyTextZ(Pozice, 2) = "A") Then
                Form1.FraEditCheck(4).Value = 1
            Else
                Form1.FraEditCheck(4).Value = 0
            End If
            
        End If
        
        Form1.FraEditText1 = CelyTextZ(Pozice - 3, 1)
        Form1.FraEditText2 = CelyTextZ(Pozice - 2, 1)
        Form1.FraEditText3 = CelyTextZ(Pozice - 1, 1)
        Form1.FraEditText4 = CelyTextZ(Pozice, 1)
        
        Form1.FraEditCas1 = CasTextu(Pozice - 3)
        Form1.FraEditCas2 = CasTextu(Pozice - 2)
        Form1.FraEditCas3 = CasTextu(Pozice - 1)
        
        For i = 0 To 3
        
            Form1.FraEditCheck(i).Enabled = True
            
            If (CelyTextZ(Pozice - 3 + i, 2) = "A") Then
                Form1.FraEditCheck(i).Value = 1
            Else
                Form1.FraEditCheck(i).Value = 0
            End If
            
        Next i
        
        For i = 4 To 6
            Form1.FraEditCheck(i).Enabled = False
        Next i
        
    End If
    
    If (Form1.FraEditText4.Enabled = True) Then
        Form1.FraEditText4.SetFocus
    End If
End Sub


'----------------------------------------------------------
'zmena textu
'----------------------------------------------------------

Public Sub TextChange()

    Dim i As Integer

    CelyTextZ(Pozice, 1) = Form1.FraEditText4
    ZbyvaNaRadku
    EditScroll
    
    If (ProbihaEditace = True) Then
        CelyText(1442, 1) = Date & " v " & Time
        
        If (DenNeboNahr = "D") Then
            Open CestaSoubory & "/RDS-Texty/" & GenerujNazevSouboru(EDatum) & ".rds" For Output As #10
        ElseIf (DenNeboNahr = "N") Then
            Open CestaSoubory & "/RDS-Texty/NahradniText.rds" For Output As #10
        Else
            Open CestaSoubory & "/RDS-Texty/" & DenNeboNahr & ".rds" For Output As #10
        End If
        
        For i = 0 To 1442
            Print #10, CelyText(i, 1)
        Next i
                
        Close #10
    End If

End Sub


'----------------------------------------------------------
'vypocet a zobrazeni zbyvajicich pismen na radku
'----------------------------------------------------------

Public Sub ZbyvaNaRadku()
    
    Form1.FraEditLabelZbyva.Caption = 64 - Len(CelyTextZ(Pozice, 1))

End Sub


'----------------------------------------------------------
'vyhledani dalsiho vyskytu
'----------------------------------------------------------

Public Sub HledejDalsi()

    Where = 0
    WherePom = Pozice
    
    Do While (WherePom < 1439 And Where = 0)
        WherePom = WherePom + 1
        Where = InStr(1, CelyTextZ(WherePom, 1), Form1.TxtEditHled.Text)
    Loop
    
    Hledej

End Sub


'----------------------------------------------------------
'vyhledani predchoziho vyskytu
'----------------------------------------------------------

Public Sub HledejPredchozi()

    Where = 0
    WherePom = Pozice

    Do While (WherePom > 0 And Where = 0)
        WherePom = WherePom - 1
        Where = InStr(1, CelyTextZ(WherePom, 1), Form1.TxtEditHled.Text)
    Loop
    
    Hledej

End Sub


'----------------------------------------------------------
'vyhledavani
'----------------------------------------------------------

Public Sub Hledej()
    
    If (Where = 0) Then
        MsgBox "Výraz nenalezen"
    Else
        Form1.ScrollEdit.Value = WherePom
        EditScroll
        Form1.FraEditText4.SelStart = Where - 1
        Form1.FraEditText4.SelLength = Len(Form1.TxtEditHled.Text)
    End If

End Sub


'----------------------------------------------------------
'nahrazeni textu
'----------------------------------------------------------

Public Sub Nahradit()

    Dim zacatek As String
    Dim konec As String
    
    Form1.FraEditText4.SelStart = 0
    Form1.FraEditText4.SelLength = Where - 1
    zacatek = Form1.FraEditText4.SelText
    
    Form1.FraEditText4.SelStart = Where + Len(Form1.TxtEditHled.Text) - 1
    Form1.FraEditText4.SelLength = Len(Form1.FraEditText4.Text) - Where + Len(Form1.TxtEditHled.Text)
    konec = Form1.FraEditText4.SelText
    
    CelyTextZ(WherePom, 1) = Left((zacatek & Form1.TxtEditNahr.Text & konec), 64)
    
    EditScroll
    Form1.FraEditText4.SelStart = Where - 1
    Form1.FraEditText4.SelLength = Len(Form1.TxtEditNahr.Text)
    
End Sub


'----------------------------------------------------------
'pridani vybranych radku do vyberu
'----------------------------------------------------------

Public Sub PridejRadky()

    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim l As Integer
    Dim m As Integer
    Dim pom As Integer
    Dim konec As Boolean
    Dim vyber As Boolean
    Dim VybranyTextP(1442, 2) As String
    Dim VybranyTextP2(1442, 2) As String
    
    m = 0
    
    vyber = False
    konec = False
    
    For i = 0 To 1439
        
        If CelyTextZ(i, 2) = "A" Then
            VybranyTextP(m, 1) = CelyTextZ(i, 1)
            VybranyTextP(m, 2) = i
            m = m + 1
            vyber = True
        End If
    
    Next i
    
    i = 0
    
    Do While (i < Form1.FraEditListVybrane.ListCount - 1 And konec = False)
        
        If (Form1.FraEditListVybrane.Selected(i) = True) Then
            j = Form1.FraEditListVybrane.ListIndex + 1
            konec = True
        End If
        
        i = i + 1
        
    Loop
   
    If (konec = False) Then
        j = PocetVybranych
    End If
    
    
    If vyber = True Then
    
        If EditDotaz = True Then
                   
            VybranyTextP2(0, 1) = VybranyTextP(0, 1)
            l = 1
            pom = VybranyTextP(0, 2)
            
            For k = 1 To m - 1
                
                If (pom < VybranyTextP(k, 2)) Then
                
                    Do While pom < VybranyTextP(k, 2) - 1
                        
                        VybranyTextP2(l, 1) = "xdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxd"
                        VybranyTextP2(l, 2) = pom
                        l = l + 1
                        pom = pom + 1
                    
                    Loop
                    
                End If
                    
                VybranyTextP2(l, 1) = VybranyTextP(k, 1)
                VybranyTextP2(l, 2) = VybranyTextP(k, 2)
                l = l + 1
                pom = VybranyTextP(k, 2)
                
            Next k
            
        Else:
        
            For k = 0 To m - 1
                VybranyTextP2(k, 1) = VybranyTextP(k, 1)
                VybranyTextP2(k, 2) = VybranyTextP(k, 2)
            Next k
            
            l = m
                
        End If
       
       k = 0
       
    For i = j To PocetVybranych - 1
        VybranyTextP(k, 1) = VybranyText(i, 1)
        VybranyTextP(k, 2) = VybranyText(i, 2)
        k = k + 1
    Next i
        
    m = j
        
    For i = 0 To l - 1
            VybranyText(j, 1) = VybranyTextP2(i, 1)
            VybranyText(j, 2) = VybranyTextP2(i, 2)
            j = j + 1
            PocetVybranych = PocetVybranych + 1
    Next i
    
    For i = 0 To k
        VybranyText(i + m + l, 1) = VybranyTextP(i, 1)
        VybranyText(i + m + l, 2) = VybranyTextP(i, 2)
    Next i
                
        Form1.FraEditListVybrane.Clear
        
        For j = 0 To PocetVybranych - 1
            If VybranyText(j, 1) = "xdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxd" Then
                Form1.FraEditListVybrane.AddItem " "
            Else
                Form1.FraEditListVybrane.AddItem VybranyText(j, 1)
            End If
        Next j
        
        Form1.FraEditLabelPocet.Caption = Form1.FraEditListVybrane.ListCount
        Form1.FraEditListVybrane.ListIndex = m
        
        If Form1.FraEditListVybrane.ListCount > 1440 Then
            Form1.FrameEROREDIT.Visible = True
        End If
    
    End If
        
End Sub


'----------------------------------------------------------
'smazani vybranych radku
'----------------------------------------------------------

Public Sub SmazatVyber()

    Dim i As Integer
    
    For i = 0 To 1439
        VybranyText(i, 1) = ""
        VybranyText(i, 2) = ""
    Next i
    
    PocetVybranych = 0
    Form1.FraEditListVybrane.Clear
    Form1.FraEditLabelPocet.Caption = Form1.FraEditListVybrane.ListCount

End Sub


'----------------------------------------------------------
'vlozeni vybranych radku
'----------------------------------------------------------

Public Sub VlozText()

    Dim i As Integer
    Dim j As Integer
    Dim pom As Boolean
    
    pom = True
    
    If Form1.FraEditListVybrane.ListCount > 0 Then
    
        For i = 0 To Form1.FraEditListVybrane.ListCount - 1
        
            If Pozice + i < 1440 Then
                
                If Form1.FraEditListVybrane.List(i) = "" Then
                
                Else
                    If VybranyText(i, 1) = "xdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxd" Then
                    Else
                        CelyTextZ(Pozice + i, 1) = VybranyText(i, 1)
                    End If
                End If
                
            Else
            
                pom = False
                
            End If
        
        Next i
        
        If pom = False Then
            Form1.FrameEROREDIT.Visible = True
        End If
        
    End If
    
    EditScroll
    
End Sub


'----------------------------------------------------------
'smazani ozancenych radku
'----------------------------------------------------------

Public Sub SmazatOznaceneRadky()

    Dim i As Integer

    For i = 0 To 1439
        
        If CelyTextZ(i, 2) = "A" Then
            CelyTextZ(i, 1) = ""
            CelyTextZ(i, 2) = ""
        End If
    
    Next i
    
    EditScroll

End Sub


'----------------------------------------------------------
'smazani oznacenych radku ve vyberu
'----------------------------------------------------------

Public Sub SmazatOznacenyVyber()
    
    Dim i As Integer
    Dim j As Integer
    Dim pomC As Integer
    Dim konec As Boolean
    
    j = 0
    konec = False

    Do While (j < Form1.FraEditListVybrane.ListCount And konec = False)
        
        If (Form1.FraEditListVybrane.Selected(j) = True) Then
            
            konec = True
            pomC = Form1.FraEditListVybrane.ListIndex
            
            For i = pomC To 1438
                VybranyText(i, 1) = VybranyText(i + 1, 1)
                VybranyText(i, 2) = VybranyText(i + 1, 2)
            Next i
        
            PocetVybranych = PocetVybranych - 1
            
            Form1.FraEditListVybrane.Clear
            
            For i = 0 To PocetVybranych - 1
                If VybranyText(i, 1) = "xdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxdxd" Then
                    Form1.FraEditListVybrane.AddItem " "
                Else
                    Form1.FraEditListVybrane.AddItem VybranyText(i, 1)
                End If
            Next i
                
            Form1.FraEditLabelPocet.Caption = Form1.FraEditListVybrane.ListCount
                
            If Form1.FraEditListVybrane.ListCount > 1440 Then
                Form1.FrameEROREDIT.Visible = True
            End If
        
        End If
        
        j = j + 1
        
    Loop
    
End Sub


'----------------------------------------------------------
'Nacist znova text
'----------------------------------------------------------

Public Sub UndoEdit()

    KontrolaUlozeniTextu
    UnloadEditText
    KontrolaTextu True

End Sub


'----------------------------------------------------------
'Vypnout/zapnout editaci
'----------------------------------------------------------

Public Sub Editace()

If (ProbihaEditace = False) Then
    Form1.FraEdit.BackColor = &H4BF8FC
    Form1.CmdEditovat.BackColor = &H4BF8FC
    Form1.CmdEditovat.Caption = "Ukončit editaci a uvolnit text pro vysílání"
    ProbihaEditace = True
    KontrolaTextu False
    
    Form1.CmdEditOznacit.Enabled = True
    Form1.CmdEditOdznacit.Enabled = True
    Form1.CmdEditSmazatOznacene.Enabled = True
    Form1.CmdEditAdd.Enabled = True
    Form1.CmdEditVlozit.Enabled = True
    Form1.CmdEditDelOzn.Enabled = True
    Form1.CmdEditDel.Enabled = True
    Form1.CmdEditUndo.Enabled = True
    Form1.CmdEditSave.Enabled = True
    Form1.CmdEditNahr.Enabled = True
    Form1.FraEditText4.Locked = False
    Form1.FraEditText4.ForeColor = &HFF0000
    Form1.FraEditText4.Font.Bold = True
    Form1.Timer4.Enabled = True
    Form1.FraEditText4.SetFocus
    
Else
    Form1.FraEdit.BackColor = &HFBC695
    Form1.CmdEditovat.BackColor = &HFBC695
    Form1.CmdEditovat.Caption = "Začít editovat vybraný den"
    ProbihaEditace = False
    
    Form1.CmdEditOznacit.Enabled = False
    Form1.CmdEditOdznacit.Enabled = False
    Form1.CmdEditSmazatOznacene.Enabled = False
    Form1.CmdEditAdd.Enabled = False
    Form1.CmdEditVlozit.Enabled = False
    Form1.CmdEditDelOzn.Enabled = False
    Form1.CmdEditDel.Enabled = False
    Form1.CmdEditUndo.Enabled = False
    Form1.CmdEditSave.Enabled = False
    Form1.CmdEditNahr.Enabled = False
    Form1.FraEditText4.Locked = True
    Form1.FraEditText4.ForeColor = &H80000008
    Form1.FraEditText4.Font.Bold = False
    Form1.Timer4.Enabled = False
    
    KontrolaUlozeniTextu
    UnloadEditText
    KontrolaTextu False
    
End If

End Sub
