Public Class EF23

    'MiX------
    Dim FF As String = vbNewLine

    'MoMe-----
    Dim Moove As Boolean = False
    Dim Mox As Integer
    Dim Moy As Integer

    'Timer1------
    Dim MemSet As String


    Sub CreateDir(ByVal NewDir As String)
        On Error Resume Next
        MkDir(NewDir)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Height = 21

        FileOpen(1, MP & "MainCat", OpenMode.Append) : FileClose(1)
        FileOpen(1, MP & "MainCat", OpenMode.Input)
        Do While Not EOF(1)
            iMainCat.Items.Add(LineInput(1)) ' & vbNewLine)
        Loop
        FileClose(1)

        Me.Left = GetSetting("EFNew23", "Pos", "Left", 0)
        Me.Top = GetSetting("EFNew23", "Pos", "Top", 0)

    End Sub

    Private Sub iExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iExit.Click
        SaveSetting("EFNew23", "Pos", "Left", Me.Left)
        SaveSetting("EFNew23", "Pos", "Top", Me.Top)
        End
    End Sub

    Private Sub iMem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iMem.Click
        Clipboard.Clear()
    End Sub

    Private Sub iMem_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles iMem.MouseMove
        If Clipboard.GetText = "" Then
            ToolTip1.SetToolTip(iMem, "-empty-")
        Else
            ToolTip1.SetToolTip(iMem, Clipboard.GetText & vbNewLine & "(LClick to empty)")
        End If

    End Sub

    Private Sub MoMe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MoMe.Click

    End Sub

    Private Sub MoMe_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MoMe.MouseDown
        Moove = True
        Mox = e.X
        Moy = e.Y
    End Sub

    Private Sub MoMe_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MoMe.MouseMove
        If Moove = True Then
            Me.Location = New Point(Me.Location.X + e.X - Mox, Me.Location.Y + e.Y - Moy)
            Me.Refresh()
        End If
    End Sub

    Private Sub MoMe_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MoMe.MouseUp
        Moove = False
    End Sub

    Private Sub OToP_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OToP.CheckedChanged
        If OToP.Checked = True Then
            Me.TopMost = True
        Else
            Me.TopMost = False
        End If
    End Sub

    Private Sub iHeight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iHeight.Click
        If Me.Height = 47 Then
            Me.Height = 21
        Else
            Me.Height = 47
        End If
    End Sub

    Private Sub iClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iClear.Click

    End Sub

    Private Sub iClear_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles iClear.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            'clear fields
            iField1.Text = ""
            iField2.Text = ""
            iField3.Text = ""
            iField4.Text = ""

        ElseIf e.Button = Windows.Forms.MouseButtons.Middle Then
            'Upgrade old program
        End If
    End Sub

    Private Sub iLMR1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iLMR1.Click

    End Sub

    Private Sub iLMR1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles iLMR1.MouseDown, iLMR2.MouseDown, iLMR3.MouseDown, iLMR4.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            'copy
            If sender Is iLMR1 Then
                Clipboard.SetText(iField1.Text)
            ElseIf sender Is iLMR2 Then
                Clipboard.SetText(iField2.Text)
            ElseIf sender Is iLMR3 Then
                Clipboard.SetText(iField3.Text)
            ElseIf sender Is iLMR4 Then
                Clipboard.SetText(iField4.Text)
            End If
        ElseIf e.Button = Windows.Forms.MouseButtons.Middle Then
            'clear
            If sender Is iLMR1 Then
                iField1.Text = ""
            ElseIf sender Is iLMR2 Then
                iField2.Text = ""
            ElseIf sender Is iLMR3 Then
                iField3.Text = ""
            ElseIf sender Is iLMR4 Then
                iField4.Text = ""
            End If
        ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
            'paste
            If sender Is iLMR1 Then
                iField1.Text = Clipboard.GetText
            ElseIf sender Is iLMR2 Then
                iField2.Text = Clipboard.GetText
            ElseIf sender Is iLMR3 Then
                iField3.Text = Clipboard.GetText
            ElseIf sender Is iLMR4 Then
                iField4.Text = Clipboard.GetText
            End If
        End If

    End Sub

    Private Sub iDEFs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iDEFs.Click

    End Sub

    Private Sub iDEFs_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles iDEFs.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            'save DEF's
            FileOpen(1, pLF & "#FieldsDEF", OpenMode.Output)
            Print(1, iField1.Text + FF)
            Print(1, iField2.Text + FF)
            Print(1, iField3.Text + FF)
            Print(1, iField4.Text + FF)
            FileClose(1)

        ElseIf e.Button = Windows.Forms.MouseButtons.Middle Then
            'Copy MP
            Clipboard.SetText(MP)
            ToolTip1.SetToolTip(iDEFs, "LSave DEFs/MCopyMP/RShowMP")
        ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
            'Show MP
            ToolTip1.SetToolTip(iDEFs, MP)
        End If
    End Sub

    Private Sub iMainCat_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles iMainCat.GotFocus
        Alfa.Left = Me.Left '+ iMainCat.Left
        Alfa.Top = Me.Top + (iMainCat.Top + iMainCat.Height)
        WCi = 1
        Alfa.Show()
    End Sub

    Private Sub iMainCat_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles iMainCat.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            Dim vV As Byte = 0
            Dim i As Integer
            If iMainCat.Text <> "" Then
                vV = 5
                For i = 0 To iMainCat.Items.Count - 1
                    If UCase(iMainCat.Items.Item(i)) = UCase(iMainCat.Text) Then
                        vV = 8
                        Exit For
                    End If
                Next
                If vV = 5 Then
                    FileOpen(1, MP & "MainCat", OpenMode.Append)
                    Print(1, iMainCat.Text & FF)
                    FileClose(1)
                    iMainCat.Items.Add(iMainCat.Text) ' & FF)
                    iMainCat.Text = ""
                    e.KeyChar = Nothing
                End If
            End If
        End If
    End Sub

    Private Sub iMainCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iMainCat.SelectedIndexChanged
        CreateDir(MP & iMainCat.Text)
        pLMC = MP & iMainCat.Text & "\"

        iSubCat.Items.Clear()
        iSubCat.Text = ""
        iCat.Text = ""
        iField1.Text = ""
        iField2.Text = ""
        iField3.Text = ""
        iField4.Text = ""

        FileOpen(1, pLMC & "SubCat", OpenMode.Append) : FileClose(1)
        FileOpen(1, pLMC & "SubCat", OpenMode.Input)
        Do While Not EOF(1)
            iSubCat.Items.Add(LineInput(1)) ' & FF)
        Loop
        FileClose(1)
    End Sub

    Private Sub iSubCat_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles iSubCat.GotFocus
        Alfa.Left = Me.Left '+ iSubCat.Left
        Alfa.Top = Me.Top + (iSubCat.Top + iSubCat.Height)
        WCi = 2
        Alfa.Show()
    End Sub

    Private Sub iSubCat_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles iSubCat.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            Dim vV As Byte = 0
            Dim i As Integer
            If iSubCat.Text <> "" Then
                vV = 5
                For i = 0 To iSubCat.Items.Count - 1
                    If UCase(iSubCat.Items.Item(i)) = UCase(iSubCat.Text) Then
                        vV = 8
                        Exit For
                    End If
                Next
                If vV = 5 Then
                    FileOpen(1, pLMC & "SubCat", OpenMode.Append)
                    Print(1, iSubCat.Text & FF)
                    FileClose(1)
                    iSubCat.Items.Add(iSubCat.Text)

                    FileOpen(2, MP & "AllFields", OpenMode.Append)
                    Print(2, iMainCat.Text & " | " & iSubCat.Text & FF)
                    FileClose(2)

                    iSubCat.Text = ""
                End If
            End If
        End If
    End Sub

    Private Sub iSubCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iSubCat.SelectedIndexChanged
        CreateDir(pLMC & iSubCat.Text)
        pLC = pLMC & iSubCat.Text & "\"

        iCat.Items.Clear()
        iCat.Text = ""
        iField1.Text = ""
        iField2.Text = ""
        iField3.Text = ""
        iField4.Text = ""

        FileOpen(1, pLC & "Cat", OpenMode.Append) : FileClose(1)
        FileOpen(1, pLC & "Cat", OpenMode.Input)
        Do While Not EOF(1)
            iCat.Items.Add(LineInput(1)) ' & FF)
        Loop
        FileClose(1)
    End Sub

    Private Sub iCat_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles iCat.GotFocus
        Alfa.Left = Me.Left '+ iCat.Left
        Alfa.Top = Me.Top + (iCat.Top + iCat.Height)
        WCi = 3
        Alfa.Show()
    End Sub

    Private Sub iCat_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles iCat.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            Dim vV As Byte = 0
            Dim i As Integer
            If iCat.Text <> "" Then
                vV = 5
                For i = 0 To iCat.Items.Count - 1
                    If UCase(iCat.Items.Item(i)) = UCase(iCat.Text) Then
                        vV = 8
                        Exit For
                    End If
                Next
                If vV = 5 Then
                    FileOpen(1, pLC & "Cat", OpenMode.Append)
                    Print(1, iCat.Text & FF)
                    FileClose(1)
                    iCat.Items.Add(iCat.Text) ' & FF)

                    FileOpen(2, MP & "AllFields", OpenMode.Append)
                    Print(2, iMainCat.Text & " | " & iSubCat.Text & " | " & iCat.Text & FF)
                    FileClose(2)

                    iCat.Text = ""
                End If
            End If
        End If
    End Sub

    Private Sub iCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iCat.SelectedIndexChanged
        CreateDir(pLC & iCat.Text)
        pLF = pLC & iCat.Text & "\"

        iField1.Text = ""
        iField2.Text = ""
        iField3.Text = ""
        iField4.Text = ""
        iField1.Items.Clear()
        iField2.Items.Clear()
        iField3.Items.Clear()
        iField4.Items.Clear()

        Dim AA As String = ""
        FileOpen(1, pLF & "#Fields", OpenMode.Append) : FileClose(1)
        FileOpen(1, pLF & "#Fields", OpenMode.Input)
        Do While Not EOF(1)
            AA = LineInput(1)
            iField1.Items.Add(AA) ' & FF)
            iField2.Items.Add(AA) ' & FF)
            iField3.Items.Add(AA) ' & FF)
            iField4.Items.Add(AA) ' & FF)
        Loop
        FileClose(1)

        FileOpen(1, pLF & "#FieldsDEF", OpenMode.Append) : FileClose(1)
        FileOpen(1, pLF & "#FieldsDEF", OpenMode.Input)
        Do While Not EOF(1)
            iField1.Text = LineInput(1)
            iField2.Text = LineInput(1)
            iField3.Text = LineInput(1)
            iField4.Text = LineInput(1)
        Loop
        FileClose(1)
    End Sub

    Private Sub iField1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles iField1.KeyPress, iField2.KeyPress, iField3.KeyPress, iField4.KeyPress

        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            Dim vV As Byte = 0
            Dim i As Integer
            If sender.Text <> "" Then
                vV = 5
                For i = 0 To iField1.Items.Count - 1
                    If UCase(iField1.Items.Item(i)) = UCase(sender.Text) Then
                        vV = 8
                        Exit For
                    End If
                Next
                If vV = 5 Then
                    FileOpen(1, pLF & "#Fields", OpenMode.Append)
                    Print(1, sender.Text & FF)
                    FileClose(1)

                    iField1.Items.Add(sender.Text) ' & FF)
                    iField2.Items.Add(sender.Text) ' & FF)
                    iField3.Items.Add(sender.Text) ' & FF)
                    iField4.Items.Add(sender.Text) ' & FF)

                    FileOpen(2, MP & "AllFields", OpenMode.Append)
                    Print(2, iMainCat.Text & " | " & iSubCat.Text & " | " & iCat.Text & " | " & sender.Text & FF)
                    FileClose(2)

                    sender.text = ""
                End If
            End If
        End If
    End Sub

    Private Sub iField1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iField1.SelectedIndexChanged

    End Sub

    Private Sub iPrint_Click(sender As Object, e As EventArgs) Handles iPrint.Click
        FileOpen(2, MP & "AllFields", OpenMode.Append) : FileClose(2)
        FileOpen(2, MP & "AllFields", OpenMode.Input)
        Do While Not EOF(2)
            AllFields.LB.Items.Add(LineInput(2))
        Loop
        FileClose(2)

        AllFields.Visible = True
        'Show(AllFields)
    End Sub

    Private Sub iMainCat_ClientSizeChanged(sender As Object, e As EventArgs) Handles iMainCat.ClientSizeChanged

    End Sub

    Private Sub iLMR2_Click(sender As Object, e As EventArgs) Handles iLMR2.Click

    End Sub

    Private Sub iMini_Click(sender As Object, e As EventArgs) Handles iMini.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub


End Class
