VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form_EstadUTP2 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Unidad Técnico Pedagógica"
   ClientHeight    =   6015
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11055
   Icon            =   "Form_EstadUTP2.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   Moveable        =   0   'False
   ScaleHeight     =   6015
   ScaleWidth      =   11055
   Begin VB.Frame Frame_Compprofe 
      Height          =   5775
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   10815
      Begin VB.Frame Frame_por_subsector 
         Height          =   4455
         Left            =   120
         TabIndex        =   1
         Top             =   120
         Width           =   10575
         Begin VB.TextBox txt_cont_prof_comp 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   9720
            Locked          =   -1  'True
            TabIndex        =   25
            Top             =   4080
            Width           =   615
         End
         Begin VB.TextBox txt_cont_prof_disp 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   120
            Locked          =   -1  'True
            TabIndex        =   24
            Top             =   4080
            Width           =   615
         End
         Begin VB.ListBox lst_niveles_Compprofe 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   780
            Left            =   8950
            Style           =   1  'Checkbox
            TabIndex        =   4
            Top             =   240
            Width           =   1455
         End
         Begin VB.CheckBox chk_todos_niveles_rendcurso 
            Caption         =   "Todos los niveles"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   8880
            TabIndex        =   16
            Top             =   1080
            Width           =   1575
         End
         Begin VB.CommandButton Btn_Quitaprofe 
            Caption         =   "<< Quitar "
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   0
            Left            =   5520
            TabIndex        =   15
            Top             =   4080
            Width           =   1215
         End
         Begin VB.CommandButton Btn_agregaprofe 
            Caption         =   "Agregar >>"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   0
            Left            =   3840
            TabIndex        =   14
            Top             =   4080
            Width           =   1215
         End
         Begin VB.ComboBox cmb_mod_Compprofe 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   4200
            TabIndex        =   5
            Top             =   480
            Width           =   3735
         End
         Begin VB.ComboBox cmb_asig_Compprofe 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   120
            TabIndex        =   2
            Top             =   480
            Width           =   3735
         End
         Begin MSFlexGridLib.MSFlexGrid Grd_profesdisp 
            Height          =   2745
            Left            =   120
            TabIndex        =   10
            Top             =   1320
            Width           =   5055
            _ExtentX        =   8916
            _ExtentY        =   4842
            _Version        =   393216
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin MSFlexGridLib.MSFlexGrid Grd_profescomp 
            Height          =   2745
            Left            =   5400
            TabIndex        =   12
            Top             =   1320
            Width           =   5055
            _ExtentX        =   8916
            _ExtentY        =   4842
            _Version        =   393216
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin VB.Label Label2 
            Caption         =   "Docentes a comparar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00000000&
            Height          =   255
            Left            =   5400
            TabIndex        =   13
            Top             =   1080
            Width           =   1575
         End
         Begin VB.Label Label1 
            Caption         =   "Docentes disponibles"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00000000&
            Height          =   255
            Left            =   120
            TabIndex        =   11
            Top             =   1080
            Width           =   1575
         End
         Begin VB.Label Label3 
            Caption         =   "Tipo de Enseñanza"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   4200
            TabIndex        =   7
            Top             =   240
            Width           =   1575
         End
         Begin VB.Label Label4 
            Caption         =   "Niveles"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   8160
            TabIndex        =   6
            Top             =   480
            Width           =   735
         End
         Begin VB.Label Label20 
            Caption         =   "Subsectores"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   3
            Top             =   240
            Width           =   1095
         End
      End
      Begin VB.CommandButton Btn_Carga_Grilla_Comp 
         Caption         =   "Carga Oculta Comparativo"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   9120
         TabIndex        =   18
         Top             =   4800
         Visible         =   0   'False
         Width           =   1455
      End
      Begin VB.CommandButton btn_can_Compprofe 
         Caption         =   "Cancelar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7560
         TabIndex        =   9
         Top             =   5280
         Width           =   1455
      End
      Begin VB.CommandButton Btn_limpiar_Compprofe 
         Caption         =   "Limpiar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7560
         TabIndex        =   8
         Top             =   4800
         Width           =   1455
      End
      Begin VB.Frame Frame2 
         Height          =   855
         Left            =   120
         TabIndex        =   19
         Top             =   4800
         Width           =   7215
         Begin VB.ComboBox cmb_per_Compprofe 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   4200
            TabIndex        =   22
            Top             =   360
            Width           =   2775
         End
         Begin VB.OptionButton Opt_Estilo 
            Caption         =   "Agrupado"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   0
            Left            =   120
            TabIndex        =   21
            Top             =   360
            Width           =   1575
         End
         Begin VB.OptionButton Opt_Estilo 
            Caption         =   "Individual"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   1
            Left            =   1920
            TabIndex        =   20
            Top             =   360
            Width           =   1215
         End
         Begin VB.Line Line3 
            BorderColor     =   &H80000005&
            X1              =   3255
            X2              =   3255
            Y1              =   110
            Y2              =   840
         End
         Begin VB.Line Line2 
            BorderColor     =   &H8000000C&
            X1              =   3240
            X2              =   3240
            Y1              =   110
            Y2              =   840
         End
         Begin VB.Label Label5 
            Caption         =   "Período"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   3480
            TabIndex        =   23
            Top             =   360
            Width           =   735
         End
      End
   End
   Begin VB.ListBox lst_rut_seleccionados 
      Enabled         =   0   'False
      Height          =   1815
      Left            =   4320
      TabIndex        =   17
      Top             =   1680
      Visible         =   0   'False
      Width           =   2535
   End
End
Attribute VB_Name = "Form_EstadUTP2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Subsectoresi() As String, ACodens() As String
Dim AProfesdisp() As String, AProfescomp As String
Dim IndicePeriodo As Integer
Dim Ordenar As Boolean
Sub Cargaprofesdisp()
Dim Orden As String
If Ordenar Then
    Orden = "p.ape1_prof, p.noms_prof" '= IIf(Campoorden = 0, "p.ape1_prof, p.noms_prof", "a.num_gra, p.ape1_prof, p.noms_prof")
    Codsector = Subsectoresi(Me.cmb_asig_Compprofe.ListIndex, 1)
    Codasig = Subsectoresi(Me.cmb_asig_Compprofe.ListIndex, 2)
    Codens = ACodens(Me.cmb_mod_Compprofe.ListIndex)
    NumGra = Me.lst_niveles_Compprofe.List(Me.lst_niveles_Compprofe.ListIndex)
    'If Me.lst_niveles_Compprofe.SelCount >= 0 Then
        For t = 0 To Me.lst_niveles_Compprofe.ListCount - 1
            If Me.lst_niveles_Compprofe.Selected(t) Then
                Con = t
            End If
        Next t
' Aquí debo crear la consulta que trae los subsectores del encabezado
' según los niveles seleccionados
        For t = 0 To Me.lst_niveles_Compprofe.ListCount - 1
            If Me.lst_niveles_Compprofe.Selected(t) Then
                If t = Con Then
                    SelCursos = SelCursos & "a.num_gra = '" & Me.lst_niveles_Compprofe.List(t) & "'"
                    Niveles = Niveles & t + 1
                Else
                    SelCursos = SelCursos & "a.num_gra = '" & Me.lst_niveles_Compprofe.List(t) & "' or "
                    Niveles = Niveles & t + 1 & "-"
                End If '{}
            End If
        Next
        SelCursos = "(" & SelCursos & ")"
Call Grillaprofesdisp
If Len(SelCursos) > 2 Then
    
    
    RsAux.CursorLocation = adUseClient
    RsAux.Open "select  distinct p.rut_prof, p.ape1_prof, p.noms_prof  from  profesores p, asi_x_cur_prof a where p.rut_prof=a.rut_prof and a.cod_sec = '" & Codsector & "' and a.cod_asi ='" & Codasig & "' and a.cod_ens ='" & Codens & "' and " & SelCursos & " order by " & Orden, conn
    If RsAux.RecordCount > 0 Then
        ReDim AProfesdisp(RsAux.RecordCount, 3)
        c = 1: Me.txt_cont_prof_disp.Text = 0
        While Not RsAux.EOF
            'aquí debo preguntar si existe un elemento X en una matriz
            'If Not valorenmatriz( Then
            If Not valorenlista(lst_rut_seleccionados, RsAux("rut_prof")) Then
                AProfesdisp(c, 1) = RsAux("rut_prof")
                AProfesdisp(c, 2) = RsAux("ape1_prof") & " " & RsAux("noms_prof")
                Me.Grd_profesdisp.TextMatrix(c, 0) = RsAux("ape1_prof") & " " & RsAux("noms_prof")
                Me.txt_cont_prof_disp = Val(Me.txt_cont_prof_disp) + 1
                rs.CursorLocation = adUseClient
                rs.Open "select distinct num_gra from asi_x_cur_prof a where a.rut_prof ='" & RsAux("rut_prof") & "' and a.cod_sec = '" & Codsector & "' and a.cod_asi ='" & Codasig & "' and a.cod_ens ='" & Codens & "' and " & SelCursos & " order by num_gra", conn
                Niveles = ""
                If rs.RecordCount > 0 Then
                    While Not rs.EOF
                        Niveles = Niveles & rs("num_gra") & "-"
                        rs.MoveNext
                    Wend
                End If
                Niveles = Left(Niveles, Len(Niveles) - 1)
                AProfesdisp(c, 3) = Niveles
                Me.Grd_profesdisp.TextMatrix(c, 1) = Niveles
                rs.Close
                c = c + 1
                Me.Grd_profesdisp.Rows = Me.Grd_profesdisp.Rows + 1
               ' Me.Grd_profesdisp.Refresh
            End If
            RsAux.MoveNext
        Wend
            If Me.Grd_profesdisp.Rows > 2 Then
                Me.Grd_profesdisp.Rows = Me.Grd_profesdisp.Rows - 1
            Else
                Me.Grd_profesdisp.TextMatrix(1, 0) = ""
                Me.Grd_profesdisp.TextMatrix(1, 1) = ""
            End If
    Else
        Me.txt_cont_prof_comp.Text = 0
    End If
    RsAux.Close
End If
   
   
   'End If
'Nsubsectores = 0
'rs.CursorLocation = adUseClient
'rs.Open "select distinct cod_asi, nom_asi from subsectores where cod_ens = '" & modalidad & "' and " & selcursos & " and ord_asi > 0 order by ord_asi", conn
'Nsubsectores = rs.RecordCount

End If
End Sub
Sub Grillainicial()
Form_Comparativo.Grd_compprofe.Clear
Form_Comparativo.Grd_compprofe.Rows = 2
Form_Comparativo.Grd_compprofe.Cols = 16
Form_Comparativo.Grd_compprofe.FixedCols = 1
Form_Comparativo.Grd_compprofe.FixedRows = 1
Form_Comparativo.Grd_compprofe.MergeCells = 2
Form_Comparativo.Grd_compprofe.MergeCol(0) = True
Form_Comparativo.Grd_compprofe.FormatString = "Profesor                                             |^ Nivel|^ Cursos|^ Alumnos|^ Prom.alumnos|^ General|^ Más alto|^ Más bajo|^ 6,0 y 7,0|^ 5,0 y 5,9|^ 4,0 y 4,9|^ 3,0 y 3,9|^ 2,0 y 2,9|^ 1,0 y 1,9|^ Sin promedio|^ Deficientes"
Form_Comparativo.Grd_compprofe.ColWidth(0) = 3000
End Sub
Sub Grillaprofesdisp()
Me.Grd_profesdisp.Clear: Me.Grd_profesdisp.FixedRows = 1: Me.Grd_profesdisp.FixedCols = 0: Me.Grd_profesdisp.Rows = 2: Me.Grd_profesdisp.Cols = 2
Me.Grd_profesdisp.ColWidth(0) = 2700: Me.Grd_profesdisp.ColWidth(1) = 2000: Me.Grd_profesdisp.TextMatrix(0, 0) = "Profesor": Me.Grd_profesdisp.TextMatrix(0, 1) = "Niveles donde imparte"
End Sub
Sub Grillaprofescomp()
Me.Grd_profescomp.Clear: Me.Grd_profescomp.FixedRows = 1: Me.Grd_profescomp.FixedCols = 0: Me.Grd_profescomp.Rows = 2: Me.Grd_profescomp.Cols = 2
Me.Grd_profescomp.ColWidth(0) = 2700: Me.Grd_profescomp.ColWidth(1) = 2000: Me.Grd_profescomp.TextMatrix(0, 0) = "Profesor": Me.Grd_profescomp.TextMatrix(0, 1) = "Niveles donde imparte"
End Sub
Private Sub cmb_asig_exist_Change()

End Sub

Private Sub Btn_agregaprofe_Click(Index As Integer)
Filagrd = 1
iniCiclo = 1
finCiclo = 1
If Index = 0 Then
    If Me.Grd_profesdisp.Row > 0 And Me.Grd_profesdisp.TextMatrix(1, 0) <> "" Then
        
                
        
        If Me.Grd_profesdisp.Row > Me.Grd_profesdisp.RowSel Then
            iniCiclo = Me.Grd_profesdisp.Row
            finCiclo = Me.Grd_profesdisp.RowSel
        ElseIf Me.Grd_profesdisp.RowSel > Me.Grd_profesdisp.Row Then
            iniCiclo = Me.Grd_profesdisp.RowSel
            finCiclo = Me.Grd_profesdisp.Row
        Else
            iniCiclo = Me.Grd_profesdisp.Row
            finCiclo = Me.Grd_profesdisp.RowSel
        End If
        Avanzafila = 0
        For t = iniCiclo To finCiclo Step -1
            If Me.Grd_profescomp.Rows = 2 Then
                If Me.Grd_profescomp.TextMatrix(1, 0) = "" Then
                    Filagrd = 1
                Else
                    Me.Grd_profescomp.Rows = Me.Grd_profescomp.Rows + 1
                    Filagrd = Me.Grd_profescomp.Rows - 1
                End If
            ElseIf Me.Grd_profescomp.Rows > 2 Then
                Me.Grd_profescomp.Rows = Me.Grd_profescomp.Rows + 1
                Filagrd = Me.Grd_profescomp.Rows - 1
            End If
            Me.lst_rut_seleccionados.AddItem AProfesdisp(t, 1)
            Me.txt_cont_prof_comp.Text = Me.lst_rut_seleccionados.ListCount
            Me.Grd_profescomp.TextMatrix(Filagrd, 0) = AProfesdisp(t, 2)
            Me.Grd_profescomp.TextMatrix(Filagrd, 1) = AProfesdisp(t, 3)
            Call lst_niveles_Compprofe_Click
            'Avanzafila = Avanzafila + 1
        Next t
        
        
        
        
        
    Else
    
        'MsgBox ("No hay elementos en la grilla")
    
    End If
Else
End If
End Sub

Private Sub btn_can_Compprofe_Click()
Unload Me
End Sub

Private Sub btn_carga_grilla_comp_Click()
Dim AComp() As String, Hayniveles As Boolean, Indica As Boolean
Dim FechaFinPer As Date, Finperiodo As Date
Call Grillainicial
Form_Comparativo.Grd_compprofe.MergeCells = flexMergeNever

Finperiodo = "30-11-" & Anno ' Parametrizar esta fecha
If IndicePeriodo = -1 Then
    campo = "PG"
    FechaFinPer = Finperiodo
Else
    FechaFinPer = devuelvecampo("periodos", "", "fec_ter_per", "num_per= '" & IndicePeriodo & "'", conn)
    If FechaFinPer >= Finperiodo Then
        FechaFinPer = Finperiodo
    End If
    If IndicePeriodo = 0 Then
        campo = "P1"
    ElseIf IndicePeriodo = 1 Then
        campo = "P2"
    ElseIf IndicePeriodo = 2 Then
        campo = "P3"
    End If
End If
Codsec = Subsectoresi(Me.cmb_asig_Compprofe.ListIndex, 1)
Codasi = Subsectoresi(Me.cmb_asig_Compprofe.ListIndex, 2)
Codens = ACodens(Me.cmb_mod_Compprofe.ListIndex)
numgramax = devuelvecampo("codigos_ensenanza", "", "num_gra_max", "des_ens = '" & Me.cmb_mod_Compprofe.Text & "'", conn)
largolista = Me.lst_rut_seleccionados.ListCount
ReDim AComp(largolista, numgramax + 2) ' Creo una matriz donde poder sacar los valores de forma mas automática
For t = 0 To largolista - 1
    AComp(t, 0) = Me.lst_rut_seleccionados.List(t) ' En la pos 0 guardo el rut del profesor
    AComp(t, numgramax + 1) = Me.Grd_profescomp.TextMatrix(t + 1, 0)
    For h = 1 To Len(Me.Grd_profescomp.TextMatrix(t + 1, 1)) Step 2
        Indice = Val(Mid(Me.Grd_profescomp.TextMatrix(t + 1, 1), h, 1))
        AComp(t, Indice) = "1" ' Con este valor le indico que imparte el nivel
    Next h
Next t
Form_Progress.Label1.Caption = "Generando Tabla ..."
Form_Progress.Show
Abarra = Val(numgramax) * largolista
Form_Progress.ProgBar1.MaxValue = Abarra
Abarra = 0

'Load Form_Comparativo
If Me.Opt_Estilo(0).Value Then ' Si el estilo de informe es agrupado
    '*********Agrupado***********
    fila = 1
    For c = 1 To Val(numgramax)
        Hayniveles = False ' Esta variable indica si encontro niveles impartidos
        SubCurpornivel = 0: SubA6070 = 0: SubA5059 = 0: SubA4049 = 0: SubA3039 = 0: SubA2029 = 0: SubA1019 = 0
        SubAlumnos = 0: SubMaximo = 0: Subminimo = 0: contador = 0
        Subgeneral = 0: SubMaximo = "-": Subminimo = "-"
        Subletras = "": Subletras2 = ""
        Indica = True
        For t = 0 To largolista - 1
            If AComp(t, c) = "1" Then
                Ngrado = c
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 0) = AComp(t, numgramax + 1)
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 1) = Ngrado
                'a = "select count(rut_prof) from asi_x_cur_prof where rut_prof ='" & AComp(t, 0) & "' and cod_ens = '" & Codens & "' and num_gra = '" & c & "' and cod_sec ='" & Codsec & "' and cod_asi = '" & Codasi & "'"
                'rs.CursorLocation = adUseClient: rs.Open a, conn: Curpornivel = rs(0): rs.Close
                rs.Open "select * from asi_x_cur_prof where rut_prof ='" & AComp(t, 0) & "' and cod_ens = '" & Codens & "' and num_gra = '" & Ngrado & "' and cod_sec ='" & Codsec & "' and cod_asi = '" & Codasi & "'", conn
                Alumnos = 0
                Curpornivel = 0: A6070 = 0: A5059 = 0: A4049 = 0: A3039 = 0: A2029 = 0: A1019 = 0
                General = "-": Maximo = "-": minimo = "-"
                Letras = "": letras2 = ""
                If rs.RecordCount > 0 Then
                    Curpornivel = rs.RecordCount
                    While Not rs.EOF
                        'Aqui acumulo las letras de los cursos para las próximas consulta
                        'Campo let_cur
                        Letras = Letras & "a.let_cur = '" & rs("let_cur") & "' or "
                        'Campo letra_curso
                        letras2 = letras2 & "p.letra_curso = '" & rs("let_cur") & "' or "
                        rs.MoveNext
                    Wend
                    Letras = "(" & Left(Letras, Len(Letras) - 4) & ")": letras2 = "(" & Left(letras2, Len(letras2) - 4) & ")"
                    
                    'rsaux.Open "select count(ci_alu) from alu_x_cur where ucase(activo_alu) = 'SI' and fec_cam ='1111-11-11' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & Letras, conn: Alumnos = rsaux(0): rsaux.Close
                    RsAux.Open "select count(a.ci_alu) from alu_x_cur a, matriculas m where a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and m.fec_mat=a.fec_mat and a.cod_ens ='" & Codens & "' and a.num_gra = '" & Ngrado & "' and " & Letras & " and ucase(a.activo_alu)='SI' and a.fec_cam='1111-11-11' and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "'", conn: Alumnos = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select avg(" & campo & ") from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & letras2, conn: General = rsaux(0): rsaux.Close
                    RsAux.Open "select avg(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 1.0", conn: General = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select max(" & campo & ") from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & letras2, conn: Maximo = rsaux(0): rsaux.Close
                    RsAux.Open "select max(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 1.0", conn: Maximo = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select min(" & campo & ") from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & letras2, conn: minimo = rsaux(0): rsaux.Close
                    RsAux.Open "select min(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and   p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 1.0", conn: minimo = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select count(ci_alu) from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & Letras2 & " and p1 >6.0 and p1 <=7.0", conn: A6070 = rsaux(0): rsaux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 6.0 and p." & campo & " <= 7.0", conn: A6070 = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select count(ci_alu) from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & Letras2 & " and p1 >5.0 and p1 <=5.9", conn: A5059 = rsaux(0): rsaux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 5.0 and p." & campo & " <= 5.9", conn: A5059 = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select count(ci_alu) from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & Letras2 & " and p1 >4.0 and p1 <=4.9", conn: A4049 = rsaux(0): rsaux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 4.0 and p." & campo & " <= 4.9", conn: A4049 = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select count(ci_alu) from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & Letras2 & " and p1 >3.0 and p1 <=3.9", conn: A3039 = rsaux(0): rsaux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 3.0 and p." & campo & " <= 3.9", conn: A3039 = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select count(ci_alu) from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & Letras2 & " and p1 >2.0 and p1 <=2.9", conn: A2029 = rsaux(0): rsaux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 2.0 and p." & campo & " <= 2.9", conn: A2029 = RsAux(0): RsAux.Close
                    
                    'rsaux.Open "select count(ci_alu) from promedios where cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and cod_ens = '" & CodEns & "' and num_gra = '" & Ngrado & "' and " & Letras2 & " and p1 >1.0 and p1 <=1.9", conn: A1019 = rsaux(0): rsaux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 1.0 and p." & campo & " <= 1.9", conn: A1019 = RsAux(0): RsAux.Close
                Else
                    Curpornivel = 0
                End If
                rs.Close
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 2) = Curpornivel
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 3) = Alumnos
                
                If Alumnos <> 0 And Curpornivel <> 0 Then
                    Prommat = CSng(Alumnos) / CSng(Curpornivel)
                    ' Preguntar si es decimal, de lo contrario no aplicar formato
                    Prommat = Round(Prommat, 1)
                    'Prommat = Format((Prommat), "#0.0")
                Else
                    Prommat = "-"
                End If
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 4) = Prommat
                If IsNull(General) Then
                    General = "-"
                Else
                    General = IIf(Len(CStr(General)) = 1, Format(General, ".0"), Mid(CStr(General), 1, 3))
                    Colorcel = IIf(General < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 5: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
                End If
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 5) = General
                
                If IsNull(Maximo) Then
                    Maximo = "-"
                Else
                    Maximo = IIf(Len(CStr(Maximo)) = 1, Format(Maximo, ".0"), Mid(CStr(Maximo), 1, 3))
                    Colorcel = IIf(Maximo < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 6: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
                End If
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 6) = Maximo
                
                If IsNull(minimo) Then
                    minimo = "-"
                Else
                    minimo = IIf(Len(CStr(minimo)) = 1, Format(minimo, ".0"), Mid(CStr(minimo), 1, 3))
                    Colorcel = IIf(minimo < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 7: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
                End If
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 7) = minimo
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 8) = A6070
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 9) = A5059
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 10) = A4049
                Form_Comparativo.Grd_compprofe.Col = 11: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
                Form_Comparativo.Grd_compprofe.Col = 12: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
                Form_Comparativo.Grd_compprofe.Col = 13: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
                Form_Comparativo.Grd_compprofe.Col = 15: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 11) = A3039
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 12) = A2029
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 13) = A1019
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 14) = Alumnos - (A1019 + A2029 + A3039 + A4049 + A5059 + A6070)
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 15) = A1019 + A2029 + A3039
                If Maximo >= SubMaximo Then SubMaximo = Maximo
                If Indica And minimo <> "-" Then
                    Subminimo = minimo
                    Indica = False
                End If
                If minimo < Subminimo And minimo <> "-" Then Subminimo = minimo
                SubCurpornivel = SubCurpornivel + Curpornivel
                SubAlumnos = SubAlumnos + Alumnos
                If General = "-" Then General = 0
                If A6070 = "-" Then A6070 = 0
                If A5059 = "-" Then A5059 = 0
                If A4049 = "-" Then A4049 = 0
                If A3039 = "-" Then A3039 = 0
                If A2029 = "-" Then A2029 = 0
                If A1019 = "-" Then A1019 = 0
                Subgeneral = Subgeneral + General
                SubA6070 = SubA6070 + A6070
                SubA5059 = SubA5059 + A5059
                SubA4049 = SubA4049 + A4049
                SubA3039 = SubA3039 + A3039
                SubA2029 = SubA2029 + A2029
                SubA1019 = SubA1019 + A1019
                contador = contador + 1
                fila = fila + 1
                Form_Comparativo.Grd_compprofe.Rows = Form_Comparativo.Grd_compprofe.Rows + 1
                Hayniveles = True
            End If
            Abarra = Abarra + 1
            Form_Progress.ProgBar1.ShowProgress Abarra
            Form_Progress.SetFocus
            DoEvents
        Next t
        'Imprimir Subtotales
        If Hayniveles Then
            For te = 1 To Form_Comparativo.Grd_compprofe.Cols - 1
                Form_Comparativo.Grd_compprofe.Row = fila
                Form_Comparativo.Grd_compprofe.Col = te
                Form_Comparativo.Grd_compprofe.CellBackColor = &H8000000F
            Next te
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 0) = "Totales por grupo"
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 2) = SubCurpornivel
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 3) = SubAlumnos
            If SubAlumnos <> 0 And SubCurpornivel <> 0 Then
                SubPrommat = CSng(SubAlumnos) / CSng(SubCurpornivel)
                SubPrommat = Round(SubPrommat, 1)
            Else
                SubPrommat = "-"
            End If
            If Subgeneral > 0 And contador > 0 Then
                Subgeneral = Subgeneral / contador
                Subgeneral = IIf(Len(CStr(Subgeneral)) = 1, Format(Subgeneral, ".0"), Mid(CStr(Subgeneral), 1, 4))
                Colorcel = IIf(Subgeneral < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 5: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
            Else
                Subgeneral = "-"
            End If
            If SubMaximo <> "-" Then
                SubMaximo = IIf(Len(CStr(SubMaximo)) = 1, Format(SubMaximo, ".0"), Mid(CStr(SubMaximo), 1, 3))
                Colorcel = IIf(SubMaximo < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 6: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
            End If
            If Subminimo <> "-" Then
                Subminimo = IIf(Len(CStr(Subminimo)) = 1, Format(Subminimo, ".0"), Mid(CStr(Subminimo), 1, 3))
                Colorcel = IIf(Subminimo < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 7: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
            End If
            
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 4) = SubPrommat
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 5) = Subgeneral
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 6) = SubMaximo
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 7) = Subminimo
            'Form_Comparativo.Grd_compprofe.TextMatrix(Fila, 7) = Minimo
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 8) = SubA6070
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 9) = SubA5059
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 10) = SubA4049
            Form_Comparativo.Grd_compprofe.Col = 11: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
            Form_Comparativo.Grd_compprofe.Col = 12: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
            Form_Comparativo.Grd_compprofe.Col = 13: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
            Form_Comparativo.Grd_compprofe.Col = 15: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 11) = SubA3039
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 12) = SubA2029
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 13) = SubA1019
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 14) = SubAlumnos - (SubA1019 + SubA2029 + SubA3039 + SubA4049 + SubA5059 + SubA6070)
            Form_Comparativo.Grd_compprofe.TextMatrix(fila, 15) = SubA1019 + SubA2029 + SubA3039
            'If Hayniveles Then
            If c = Val(numgramax) Then
                Form_Comparativo.Grd_compprofe.Rows = Form_Comparativo.Grd_compprofe.Rows + 1
            Else
                Form_Comparativo.Grd_compprofe.Rows = Form_Comparativo.Grd_compprofe.Rows + 2
                fila = fila + 2
            End If
            Abarra = Abarra + 1
            Form_Progress.ProgBar1.ShowProgress Abarra
            Form_Progress.SetFocus
            DoEvents
        End If
    Next c
Else
    '*********Individual***********
fila = 1
    For c = 0 To largolista - 1
        Hayniveles = False ' Esta variable indica si encontro niveles impartidos
        SubCurpornivel = 0: SubA6070 = 0: SubA5059 = 0: SubA4049 = 0: SubA3039 = 0: SubA2029 = 0: SubA1019 = 0
        SubAlumnos = 0: SubMaximo = 0: Subminimo = 0: contador = 0
        Subgeneral = 0: SubMaximo = "-": Subminimo = "-"
        Subletras = "": Subletras2 = ""
        Indica = True
        For t = 1 To Val(numgramax)
            
            If AComp(c, t) = "1" Then
                Ngrado = t
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 0) = AComp(c, numgramax + 1)
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 1) = Ngrado
                'a = "select count(rut_prof) from asi_x_cur_prof where rut_prof ='" & AComp(t, 0) & "' and cod_ens = '" & Codens & "' and num_gra = '" & c & "' and cod_sec ='" & Codsec & "' and cod_asi = '" & Codasi & "'"
                'rs.CursorLocation = adUseClient: rs.Open a, conn: Curpornivel = rs(0): rs.Close
                
                rs.Open "select * from asi_x_cur_prof where rut_prof ='" & AComp(c, 0) & "' and cod_ens = '" & Codens & "' and num_gra = '" & Ngrado & "' and cod_sec ='" & Codsec & "' and cod_asi = '" & Codasi & "'", conn
                Alumnos = 0
                Curpornivel = 0: A6070 = 0: A5059 = 0: A4049 = 0: A3039 = 0: A2029 = 0: A1019 = 0
                General = "-": Maximo = "-": minimo = "-"
                Letras = "": letras2 = ""
                If rs.RecordCount > 0 Then
                    Curpornivel = rs.RecordCount
                    While Not rs.EOF
                        'Aqui acumulo las letras de los cursos para las próximas consulta
                        'Campo let_cur
                        Letras = Letras & "let_cur = '" & rs("let_cur") & "' or "
                        'Campo letra_curso
                        letras2 = letras2 & "letra_curso = '" & rs("let_cur") & "' or "
                        rs.MoveNext
                    Wend
                    Letras = "(" & Left(Letras, Len(Letras) - 4) & ")": letras2 = "(" & Left(letras2, Len(letras2) - 4) & ")"
                    RsAux.Open "select count(a.ci_alu) from alu_x_cur a, matriculas m where a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and m.fec_mat=a.fec_mat and a.cod_ens ='" & Codens & "' and a.num_gra = '" & Ngrado & "' and " & Letras & " and ucase(a.activo_alu)='SI' and a.fec_cam='1111-11-11' and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "'", conn: Alumnos = RsAux(0): RsAux.Close
                    RsAux.Open "select avg(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 1.0", conn: General = RsAux(0): RsAux.Close
                    RsAux.Open "select max(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 1.0", conn: Maximo = RsAux(0): RsAux.Close
                    RsAux.Open "select min(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and   p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 1.0", conn: minimo = RsAux(0): RsAux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 6.0 and p." & campo & " <= 7.0", conn: A6070 = RsAux(0): RsAux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 5.0 and p." & campo & " <= 5.9", conn: A5059 = RsAux(0): RsAux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 4.0 and p." & campo & " <= 4.9", conn: A4049 = RsAux(0): RsAux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 3.0 and p." & campo & " <= 3.9", conn: A3039 = RsAux(0): RsAux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 2.0 and p." & campo & " <= 2.9", conn: A2029 = RsAux(0): RsAux.Close
                    RsAux.Open "select count(" & campo & ") from promedios p, alu_x_cur a, matriculas m where p.ci_alu= a.ci_alu and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and ucase(a.activo_alu)='SI' and m.fec_mat=a.fec_mat and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "' and p.cod_ens=a.cod_ens and p.num_gra=a.num_gra and p.letra_curso=a.let_cur and p.cod_ens = '" & Codens & "' and p.num_gra = '" & Ngrado & "' and " & letras2 & " and cod_sec = '" & Codsec & "' and cod_asi = '" & Codasi & "' and p." & campo & " >= 1.0 and p." & campo & " <= 1.9", conn: A1019 = RsAux(0): RsAux.Close
                Else
                    Curpornivel = 0
                End If
                rs.Close
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 2) = Curpornivel
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 3) = Alumnos
                
                If Alumnos <> 0 And Curpornivel <> 0 Then
                    Prommat = CSng(Alumnos) / CSng(Curpornivel)
                    ' Preguntar si es decimal, de lo contrario no aplicar formato
                    Prommat = Round(Prommat, 1)
                    'Prommat = Format((Prommat), "#0.0")
                Else
                    Prommat = "-"
                End If
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 4) = Prommat
                If IsNull(General) Then
                    General = "-"
                Else
                    General = IIf(Len(CStr(General)) = 1, Format(General, ".0"), Mid(CStr(General), 1, 3))
                    Colorcel = IIf(General < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 5: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
                End If
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 5) = General
                If IsNull(Maximo) Then
                    Maximo = "-"
                Else
                    Maximo = IIf(Len(CStr(Maximo)) = 1, Format(Maximo, ".0"), Mid(CStr(Maximo), 1, 3))
                    Colorcel = IIf(Maximo < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 6: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
                End If
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 6) = Maximo
                If IsNull(minimo) Then
                    minimo = "-"
                Else
                    minimo = IIf(Len(CStr(minimo)) = 1, Format(minimo, ".0"), Mid(CStr(minimo), 1, 3))
                    Colorcel = IIf(minimo < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 7: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
                End If
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 7) = minimo
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 8) = A6070
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 9) = A5059
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 10) = A4049
                Form_Comparativo.Grd_compprofe.Col = 11: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
                Form_Comparativo.Grd_compprofe.Col = 12: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
                Form_Comparativo.Grd_compprofe.Col = 13: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
                Form_Comparativo.Grd_compprofe.Col = 15: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 11) = A3039
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 12) = A2029
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 13) = A1019
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 14) = Alumnos - (A1019 + A2029 + A3039 + A4049 + A5059 + A6070)
                Form_Comparativo.Grd_compprofe.TextMatrix(fila, 15) = A1019 + A2029 + A3039
                
                If Maximo >= SubMaximo Then SubMaximo = Maximo
                If Indica And minimo <> "-" Then
                    Subminimo = minimo
                    Indica = False
                End If
                If minimo < Subminimo And minimo <> "-" Then Subminimo = minimo
                SubCurpornivel = SubCurpornivel + Curpornivel
                SubAlumnos = SubAlumnos + Alumnos
                
                If General = "-" Then General = 0
                If A6070 = "-" Then A6070 = 0
                If A5059 = "-" Then A5059 = 0
                If A4049 = "-" Then A4049 = 0
                If A3039 = "-" Then A3039 = 0
                If A2029 = "-" Then A2029 = 0
                If A1019 = "-" Then A1019 = 0
                Subgeneral = Subgeneral + General ' Chequear el general cuando tiene "-"
                SubA6070 = SubA6070 + A6070
                SubA5059 = SubA5059 + A5059
                SubA4049 = SubA4049 + A4049
                SubA3039 = SubA3039 + A3039
                SubA2029 = SubA2029 + A2029
                SubA1019 = SubA1019 + A1019
                contador = contador + 1
                fila = fila + 1
                Form_Comparativo.Grd_compprofe.Rows = Form_Comparativo.Grd_compprofe.Rows + 1
                Hayniveles = True
            
            End If
            Abarra = Abarra + 1
            Form_Progress.ProgBar1.ShowProgress Abarra
            Form_Progress.SetFocus
            DoEvents
        Next t
        
        'Imprimir subtotales
        For te = 1 To Form_Comparativo.Grd_compprofe.Cols - 1
            Form_Comparativo.Grd_compprofe.Row = fila
            Form_Comparativo.Grd_compprofe.Col = te
            Form_Comparativo.Grd_compprofe.CellBackColor = &H8000000F
        Next te
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 0) = "Totales por profesor"
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 2) = SubCurpornivel
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 3) = SubAlumnos
        If SubAlumnos <> 0 And SubCurpornivel <> 0 Then
            SubPrommat = CSng(SubAlumnos) / CSng(SubCurpornivel)
            SubPrommat = Round(SubPrommat, 1)
        Else
            SubPrommat = "-"
        End If
        If Subgeneral > 0 And contador > 0 Then
            Subgeneral = Subgeneral / contador
            Subgeneral = IIf(Len(CStr(Subgeneral)) = 1, Format(Subgeneral, ".0"), Mid(CStr(Subgeneral), 1, 4))
            Colorcel = IIf(Subgeneral < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 5: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
        Else
            Subgeneral = "-"
        End If
        If SubMaximo <> "-" Then
            SubMaximo = IIf(Len(CStr(SubMaximo)) = 1, Format(SubMaximo, ".0"), Mid(CStr(SubMaximo), 1, 3))
            Colorcel = IIf(SubMaximo < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 6: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
         End If
         If Subminimo <> "-" Then
             Subminimo = IIf(Len(CStr(Subminimo)) = 1, Format(Subminimo, ".0"), Mid(CStr(Subminimo), 1, 3))
             Colorcel = IIf(Subminimo < 4#, &HFF&, &HFF0000): Form_Comparativo.Grd_compprofe.Col = 7: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = Colorcel
         End If
        
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 4) = SubPrommat
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 5) = Subgeneral
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 6) = SubMaximo
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 7) = Subminimo
        'Form_Comparativo.Grd_compprofe.TextMatrix(Fila, 7) = Minimo
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 8) = SubA6070
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 9) = SubA5059
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 10) = SubA4049
        Form_Comparativo.Grd_compprofe.Col = 11: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
        Form_Comparativo.Grd_compprofe.Col = 12: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
        Form_Comparativo.Grd_compprofe.Col = 13: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
        Form_Comparativo.Grd_compprofe.Col = 15: Form_Comparativo.Grd_compprofe.Row = fila: Form_Comparativo.Grd_compprofe.CellForeColor = &HFF&
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 11) = SubA3039
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 12) = SubA2029
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 13) = SubA1019
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 14) = SubAlumnos - (SubA1019 + SubA2029 + SubA3039 + SubA4049 + SubA5059 + SubA6070)
        Form_Comparativo.Grd_compprofe.TextMatrix(fila, 15) = SubA1019 + SubA2029 + SubA3039
                
        
        If c = largolista - 1 Then
            Form_Comparativo.Grd_compprofe.Rows = Form_Comparativo.Grd_compprofe.Rows + 1
        Else
            Form_Comparativo.Grd_compprofe.Rows = Form_Comparativo.Grd_compprofe.Rows + 2
            fila = fila + 2
        End If
        Abarra = Abarra + 1
        Form_Progress.ProgBar1.ShowProgress Abarra
        Form_Progress.SetFocus
        DoEvents
    Next c
End If
Form_Progress.ProgBar1.ShowProgress 0
Unload Form_Progress
End Sub

Private Sub Btn_limpiar_Compprofe_Click()
Me.cmb_per_Compprofe = ""
Call cmb_asig_Compprofe_Click
Me.cmb_asig_Compprofe.Text = ""
Me.cmb_asig_Compprofe.SetFocus
End Sub

Private Sub Btn_Quitaprofe_Click(Index As Integer)
Dim Rutasacar As String
If Me.lst_rut_seleccionados.ListCount > 0 Then
    If Me.Grd_profescomp.Row > Me.Grd_profescomp.RowSel Then
        iniCiclo = Me.Grd_profescomp.Row
        finCiclo = Me.Grd_profescomp.RowSel
    ElseIf Me.Grd_profescomp.RowSel > Me.Grd_profescomp.Row Then
        iniCiclo = Me.Grd_profescomp.RowSel
        finCiclo = Me.Grd_profescomp.Row
    Else
        iniCiclo = Me.Grd_profesdisp.Row
        finCiclo = Me.Grd_profesdisp.RowSel
    End If
    Avanzafila = 0
    For t = iniCiclo To finCiclo Step -1
        Rutasacar = Me.lst_rut_seleccionados.List(t - 1)
        fila = Buscavalorenlista(lst_rut_seleccionados, Rutasacar)
        If fila <> -1 Then
            'MsgBox (Me.lst_rut_seleccionados.List(Fila))
            Me.lst_rut_seleccionados.RemoveItem fila
            If Me.Grd_profescomp.Rows > 2 Then
                Me.Grd_profescomp.RemoveItem fila + 1
            Else
                Me.Grd_profescomp.TextMatrix(1, 0) = ""
                Me.Grd_profescomp.TextMatrix(1, 1) = ""
            End If
            Me.Grd_profescomp.Refresh
        End If
        Me.txt_cont_prof_comp.Text = Me.lst_rut_seleccionados.ListCount
        Call lst_niveles_Compprofe_Click
    Next t
End If
End Sub

Private Sub chk_todos_niveles_rendcurso_Click()
If Me.chk_todos_niveles_rendcurso.Value Then
    For t = 0 To Me.lst_niveles_Compprofe.ListCount - 1
        Me.lst_niveles_Compprofe.Selected(t) = True
    Next t
Else
    For t = 0 To Me.lst_niveles_Compprofe.ListCount - 1
        Me.lst_niveles_Compprofe.Selected(t) = False
        Me.lst_niveles_Compprofe.ListIndex = 0
    Next t
End If
End Sub

Private Sub cmb_asig_Compprofe_Click()
Me.txt_cont_prof_comp = 0
Me.txt_cont_prof_disp = 0
Me.cmb_mod_Compprofe.Clear
Me.lst_niveles_Compprofe.Clear
Call Grillaprofesdisp
Call Grillaprofescomp
Me.lst_rut_seleccionados.Clear
Codsector = Subsectoresi(Me.cmb_asig_Compprofe.ListIndex, 1)
Codasig = Subsectoresi(Me.cmb_asig_Compprofe.ListIndex, 2)
RsAux.CursorLocation = adUseClient
RsAux.Open "select distinct c.cod_ens, c.des_ens  from  codigos_ensenanza c, subsectores s  where s.cod_ens= c.cod_ens and s.cod_sec = '" & Codsector & "' and s.cod_asi = '" & Codasig & "' order by c.cod_ens asc"
c = 0
If RsAux.RecordCount > 0 Then
    ReDim ACodens(RsAux.RecordCount)
    While Not RsAux.EOF ' aqui lleno un array con los codigos de ensenanza
        ACodens(c) = RsAux("cod_ens")
        Me.cmb_mod_Compprofe.AddItem RsAux("des_ens")
        RsAux.MoveNext
        c = c + 1
    Wend
End If
RsAux.Close
End Sub

Private Sub cmb_asig_Compprofe_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

Private Sub cmb_mod_Compprofe_Click()
'if la modalidad que seleccione es la misma no borro las grillas, de lo contrario si
'If Me.cmb_mod_Compprofe.Text <> Codens Then
    Me.lst_niveles_Compprofe.Clear
    Call Grillaprofesdisp
    Call Grillaprofescomp
    Me.lst_rut_seleccionados.Clear
    Codens = ACodens(Me.cmb_mod_Compprofe.ListIndex)
    Codsector = Subsectoresi(Me.cmb_asig_Compprofe.ListIndex, 1)
    Codasi = Subsectoresi(Me.cmb_asig_Compprofe.ListIndex, 2)
'End If

RsAux.CursorLocation = adUseClient
RsAux.Open "Select distinct num_gra from subsectores where cod_ens = '" & Codens & "'and cod_sec = '" & Codsector & "' and cod_asi = '" & Codasi & "' order by num_gra", conn
If RsAux.RecordCount > 0 Then
    While Not RsAux.EOF
        Me.lst_niveles_Compprofe.AddItem RsAux("num_gra")
        RsAux.MoveNext
    Wend
End If
RsAux.Close
End Sub

Private Sub cmb_mod_Compprofe_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

Private Sub cmb_per_Compprofe_Click()
If Me.cmb_per_Compprofe.Text <> "" Then
    periodo = Me.cmb_per_Compprofe.Text
    For te = 0 To Me.Opt_Estilo.count - 1
        If Me.Opt_Estilo(te).Value = True Then
            t = te: Exit For
        End If
    Next te
    If Me.lst_rut_seleccionados.ListCount > 0 Then
        IndicePeriodo = Me.cmb_per_Compprofe.ListIndex
        'Form_Comparativo.Visible = False
        Form_Comparativo.Caption = "Tabla comparativo docente " & Me.Opt_Estilo(t).Caption
        Form_Comparativo.Visible = True
        Form_Comparativo.lbl_periodo.Caption = Me.cmb_per_Compprofe.Text & " " & Anno
        Form_Comparativo.Frame_Tablacomp.Caption = "Subsector : " & Me.cmb_asig_Compprofe.Text
        If UCase(Me.cmb_per_Compprofe.Text) = "ANUAL" Then
            IndicePeriodo = -1
        Else
            IndicePeriodo = Me.cmb_per_Compprofe.ListIndex
        End If
        Call btn_carga_grilla_comp_Click
    Else
        MsgBox ("No hay profesores seleccionados")
    End If
End If
End Sub

Private Sub cmb_per_Compprofe_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

Private Sub Form_Load()
If Menuinformes4 = "Comp" Then
    Set rs = New ADODB.Recordset
    Set RsAux = New ADODB.Recordset
    Call Form_main.hideframeimpresion4
    Me.Height = 6300
    Me.Width = 11100
    Me.Frame_Compprofe.Top = 10 '120
    Me.Frame_Compprofe.Left = 100 '129
    Me.Frame_Compprofe.Visible = True
    'Form_Comparativo.Visible = False
    ' esta consulta trae codigo asignatura, sector
    Ordenar = False
    'Me.Opt_orden(0).Value = True
    'Me.Opt_Estilo(0).Value = True
    Call Grillaprofesdisp
    Call Grillaprofescomp
    Me.Opt_Estilo(0).Value = True
    Me.cmb_asig_Compprofe.Clear
    RsAux.CursorLocation = adUseClient
    RsAux.Open "select distinct cod_sec, cod_asi from  subsectores order by cod_sec, cod_asi asc", conn
    ' No puedo traer de inmediato el nombre de la asignatura, porque si hay 2 asignaturas escritas distintas, siendo
    ' las mismas, me traerá las 2, y eso no me sirve.
    c = 0
    If RsAux.RecordCount > 0 Then
        ReDim Subsectoresi(RsAux.RecordCount, 2)
        While Not RsAux.EOF ' aqui lleno un array con los subsectores
            Subsectoresi(c, 1) = RsAux("cod_sec"): Subsectoresi(c, 2) = RsAux("cod_asi")
            Me.cmb_asig_Compprofe.AddItem devuelvecampo("subsectores", "", "nom_asi", "cod_sec = '" & RsAux("cod_sec") & "' and cod_asi = '" & RsAux("cod_asi") & "'", conn)
            RsAux.MoveNext
            c = c + 1
        Wend
    End If
    RsAux.Close
    'Me.Grd_rendimiento.FormatString = "               ;Tipo de enseñanza|Cursos que atiende|Matrícula|Promedio del Curso|Promedio más alto|Promedio más bajo|Distribución alumnos por rango|Entre 6,0 y 7,0|Entre 5,0 y 5,9|Entre 4,0 y 4,9|Entre 3,0 y 3,9|Entre 2,0 y 2,9|Entre 1,0 y 1,9|Total alumnos con promedio|Alumnos sin promedio|Total alumnos nota deficiente"
    
    'Call Grillainicial
    Call llenacombo(cmb_per_Compprofe, "periodos", "des_per", "", conn)
    If Me.cmb_per_Compprofe.ListCount > 0 Then
        Me.cmb_per_Compprofe.AddItem "ANUAL"
    End If
    CentrarForma Me
    Me.Show
    
End If
End Sub

Private Sub Grd_rendimiento_Click()

End Sub

Private Sub lst_niveles_Compprofe_Click()
Ordenar = True
'If Me.Opt_orden(0) Then
    Call Cargaprofesdisp   '
'ElseIf Me.Opt_orden(1) Then
'    Call Cargaprofesdisp(1)
'End If



End Sub

Private Sub Opt_orden_Click(Index As Integer)

Call Cargaprofesdisp
'Me.Grd_profesdisp.Sort = 7
'If Index = 1 Then
'    Me.Grd_profesdisp.RowSel = 1: Me.Grd_profesdisp.Row = 1
'    Me.Grd_profesdisp.Col = 0: Me.Grd_profesdisp.ColSel = 0
'Else
'    Me.Grd_profesdisp.RowSel = 1: Me.Grd_profesdisp.Row = 1
'    Me.Grd_profesdisp.Col = 1: Me.Grd_profesdisp.ColSel = 1
'End If


End Sub

Private Sub Opt_Estilo_Click(Index As Integer)
Me.cmb_per_Compprofe = ""
End Sub
