VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form_Estpnivel 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Estadisticas de Prueba de Nivel"
   ClientHeight    =   7365
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11820
   Icon            =   "Form_estpnivel.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   Moveable        =   0   'False
   ScaleHeight     =   7365
   ScaleWidth      =   11820
   Begin VB.Frame Frame_Rendcurso 
      ForeColor       =   &H00FF0000&
      Height          =   7095
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   11535
      Begin VB.Frame Frame5 
         Caption         =   "Informe Análisis"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1215
         Left            =   7560
         TabIndex        =   23
         Top             =   1080
         Width           =   1935
         Begin VB.OptionButton Option3 
            Caption         =   "Por Cursos"
            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        =   26
            Top             =   840
            Width           =   1695
         End
         Begin VB.OptionButton Option2 
            Caption         =   "Por Subsector"
            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        =   25
            Top             =   600
            Width           =   1695
         End
         Begin VB.OptionButton Option1 
            Caption         =   "Prom. Generales"
            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        =   24
            Top             =   360
            Value           =   -1  'True
            Width           =   1695
         End
      End
      Begin VB.Frame Frame4 
         Caption         =   "Estadísticas de"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   975
         Left            =   7560
         TabIndex        =   18
         Top             =   120
         Width           =   1935
         Begin VB.OptionButton Option_PIB 
            Caption         =   "P.I.B."
            Enabled         =   0   'False
            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        =   20
            Top             =   600
            Width           =   855
         End
         Begin VB.OptionButton Option_PN 
            Caption         =   "Prueba de Nivel"
            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        =   19
            Top             =   360
            Value           =   -1  'True
            Width           =   1695
         End
      End
      Begin VB.Frame Frame2 
         ForeColor       =   &H00FF0000&
         Height          =   2175
         Left            =   120
         TabIndex        =   1
         Top             =   120
         Width           =   7335
         Begin VB.ComboBox Combo_agno 
            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
            Style           =   2  'Dropdown List
            TabIndex        =   21
            Top             =   1080
            Width           =   1335
         End
         Begin VB.Frame Frame1 
            Caption         =   "Destino"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   615
            Left            =   4680
            TabIndex        =   15
            Top             =   1080
            Width           =   2535
            Begin VB.OptionButton Opt_destino_rendcurso 
               Caption         =   "Impresora"
               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            =   1320
               TabIndex        =   17
               Top             =   240
               Width           =   1095
            End
            Begin VB.OptionButton Opt_destino_rendcurso 
               Caption         =   "Pantalla"
               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            =   240
               TabIndex        =   16
               Top             =   240
               Value           =   -1  'True
               Width           =   1335
            End
         End
         Begin VB.CommandButton btn_carga_grilla_oculta_rendcurso 
            Caption         =   "Carga oculta"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   480
            TabIndex        =   14
            Top             =   1560
            Visible         =   0   'False
            Width           =   2295
         End
         Begin VB.ComboBox cmb_per_rendcurso 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   4680
            TabIndex        =   9
            Top             =   480
            Width           =   2535
         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            =   1560
            TabIndex        =   8
            Top             =   1080
            Width           =   1695
         End
         Begin VB.ListBox lst_niveles_rendcurso 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   1500
            Left            =   3360
            Style           =   1  'Checkbox
            TabIndex        =   7
            Top             =   480
            Width           =   1095
         End
         Begin VB.ComboBox cmb_mod_rendcurso 
            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           =   3135
         End
         Begin VB.Label Label6 
            Caption         =   "Año"
            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        =   22
            Top             =   840
            Width           =   1095
         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            =   4680
            TabIndex        =   10
            Top             =   240
            Width           =   855
         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            =   3360
            TabIndex        =   4
            Top             =   240
            Width           =   855
         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            =   120
            TabIndex        =   3
            Top             =   240
            Width           =   1575
         End
      End
      Begin VB.CommandButton Btn_limpiar_Rendcurso 
         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            =   9720
         TabIndex        =   13
         Top             =   1080
         Width           =   1575
      End
      Begin VB.CommandButton Btn_gen_Rep_Rendcurso 
         Caption         =   "Generar Informe"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   9720
         TabIndex        =   12
         Top             =   600
         Width           =   1575
      End
      Begin VB.CommandButton Btn_can_Rep_Rendcurso 
         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            =   9720
         TabIndex        =   11
         Top             =   1560
         Width           =   1575
      End
      Begin VB.Frame Frame3 
         ForeColor       =   &H00FF0000&
         Height          =   4695
         Left            =   120
         TabIndex        =   5
         Top             =   2280
         Width           =   11295
         Begin MSFlexGridLib.MSFlexGrid grd_rendcurso 
            Height          =   4335
            Left            =   120
            TabIndex        =   6
            Top             =   240
            Width           =   11055
            _ExtentX        =   19500
            _ExtentY        =   7646
            _Version        =   393216
            Rows            =   1
            Cols            =   1
            FixedRows       =   0
            FixedCols       =   0
            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
      End
   End
End
Attribute VB_Name = "Form_Estpnivel"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Subsectoresi() As String, Codsec As String, Codasi As String, Subsector As String
Dim Cursosimpartidos() As String, Totalcursos As Integer
Dim RutProfe As String, Busqueda As String, Profesor As String
Dim Codperiodo As String, IndicePeriodo As String, periodo As String
Dim Subsectorescurso() As String ' Rendimientos de curso
Dim Nsubsectores As Integer
Dim Cursosrend() As String
Dim rs As ADODB.Recordset
Dim RsAux As ADODB.Recordset

Sub Grillainicial2()
Me.grd_rendcurso.Clear
Me.grd_rendcurso.Rows = 2
Me.grd_rendcurso.Cols = 10
Me.grd_rendcurso.FixedCols = 2
Me.grd_rendcurso.FixedRows = 1
Me.grd_rendcurso.MergeCells = 2
Me.grd_rendcurso.MergeCol(0) = True
'Me.grd_rendcurso.FormatString = "                      |^  Cursos  |^ Matrícula|^ 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 Nota|^ Deficientes"
Me.grd_rendcurso.FormatString = "                      |^  Cursos  |^ Matrícula|^ |^ |^ |^ |^ |^ |^ |^ |^ |^ |^ "
'Me.grd_rendcurso.FormatString = "                      |^  Cursos  |^ Matrícula|^ |^ |^ "
End Sub

Private Sub Btn_can_Rep_Rendcurso_Click()
    Form_Estpnivel.Hide
    Unload Form_Estpnivel
End Sub

Private Sub btn_carga_grilla_oculta_rendcurso_Click()
Dim colegio As String
Dim var_sql As String
Dim objRS As ADODB.Recordset
Set objRS = New ADODB.Recordset
var_sql = "select valor from cfg where param = 'CODBC'"
objRS.Open var_sql, conn
colegio = objRS("valor")
objRS.Close

Dim porc_eva As String
Dim Indica As Boolean, Indica1 As Boolean, Indica2 As Boolean
Dim Spasig() As Single, Pasig() As Single
Dim FechaFinPer As Date, Finperiodo As Date
Dim SumProm, DivSumProm, Num_notas As Integer
modalidad = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens ='" & Me.cmb_mod_rendcurso.Text & "'", conn)

Finperiodo = devuelvecampo("periodos", "", "fec_ter_per", "fec_ter_per <> '' order by fec_ter_per desc", conn)
'Finperiodo = "30-11-" & Anno ' Parametrizar esta fecha
If UCase(Me.cmb_per_rendcurso.Text) = "ANUAL" Then
    campo = "PG"
    FechaFinPer = Finperiodo
Else
    FechaFinPer = devuelvecampo("periodos", "", "fec_ter_per", "num_per= '" & cmb_per_rendcurso.ListIndex & "'", conn)
    If FechaFinPer >= Finperiodo Then
        FechaFinPer = Finperiodo
    End If
    If cmb_per_rendcurso.ListIndex = 0 Then
        campo = "P1"
    ElseIf cmb_per_rendcurso.ListIndex = 1 Then
        campo = "P2"
    ElseIf cmb_per_rendcurso.ListIndex = 2 Then
        campo = "P3"
    End If
End If

Con = 0
Fila = 1
SelCursos = ""
    If Me.lst_niveles_rendcurso.SelCount >= 0 Then
        For t = 0 To Me.lst_niveles_rendcurso.ListCount - 1
            If Me.lst_niveles_rendcurso.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_rendcurso.ListCount - 1
            If Me.lst_niveles_rendcurso.Selected(t) Then
                If t = Con Then
                    SelCursos = SelCursos & "num_gra = '" & Me.lst_niveles_rendcurso.List(t) & "'"
                    Niveles = Niveles & t + 1
                Else
                    SelCursos = SelCursos & "num_gra = '" & Me.lst_niveles_rendcurso.List(t) & "' or "
                    Niveles = Niveles & t + 1 & "-"
                End If '{}
            End If
        Next
        SelCursos = "(" & SelCursos & ")"
   'End If
Nsubsectores = 0
rs.CursorLocation = adUseClient
a = "select distinct cod_asi, nom_asi from subsectores where cod_ens = '" & modalidad & "' and " & SelCursos & " and ord_asi > 0 and pn =1 order by ord_asi"

rs.Open a, conn
Nsubsectores = rs.RecordCount

cs = 1
Me.grd_rendcurso.Cols = Me.grd_rendcurso.Cols + Nsubsectores

If rs.RecordCount > 0 Then
    ReDim Subsectorescurso(rs.RecordCount, 2)
    While Not rs.EOF
        Subsectorescurso(cs, 1) = rs("cod_asi") 'Lleno un arreglo con los encabezados
        Subsectorescurso(cs, 2) = rs("nom_asi") 'Lleno un arreglo con los encabezados
        Me.grd_rendcurso.ColWidth(cs + 2) = 2000
        Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 2: Me.grd_rendcurso.CellAlignment = 1
        Me.grd_rendcurso.TextMatrix(0, cs + 2) = rs("nom_asi")
        rs.MoveNext
        cs = cs + 1
    Wend
End If

rs.Close
Me.grd_rendcurso.ColWidth(cs + 2) = 800: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 2: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 2) = "General"
Me.grd_rendcurso.ColWidth(cs + 3) = 800:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 3: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 3) = "Más alto"
Me.grd_rendcurso.ColWidth(cs + 4) = 800:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 4: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 4) = "Más bajo"
Me.grd_rendcurso.ColWidth(cs + 5) = 800:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 5: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 5) = "6,0 y 7,0"
Me.grd_rendcurso.ColWidth(cs + 6) = 800:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 6: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 6) = "5,0 y 5,9"
Me.grd_rendcurso.ColWidth(cs + 7) = 800:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 7: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 7) = "4,0 y 4,9"
Me.grd_rendcurso.ColWidth(cs + 8) = 800:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 8: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 8) = "3,0 y 3,9"
Me.grd_rendcurso.ColWidth(cs + 9) = 800:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 9: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 9) = "2,0 y 2,9"
Me.grd_rendcurso.ColWidth(cs + 10) = 800:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 10: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 10) = "1,0 y 1,9"
Me.grd_rendcurso.ColWidth(cs + 11) = 1000:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 11: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 11) = "Sin promedio"
Me.grd_rendcurso.ColWidth(cs + 12) = 1000:: Me.grd_rendcurso.Row = 0: Me.grd_rendcurso.Col = cs + 12: Me.grd_rendcurso.CellAlignment = 4
Me.grd_rendcurso.TextMatrix(0, cs + 12) = "Deficientes"
'**********************        ******************



'************* Oculta columnas inecesarias
For k = 3 + Nsubsectores To Me.grd_rendcurso.Cols - 1
    Me.grd_rendcurso.ColWidth(k) = 0
Next k

'*************


c = 1
rs.CursorLocation = adUseClient
rs.Open "select num_gra, let_cur from cursos where agno=" & val(Combo_agno.Text) & " and cod_ens ='" & modalidad & "' and " & SelCursos & " order by num_gra, let_cur", conn
        Indica1 = True
        If rs.RecordCount > 0 Then
            ReDim Cursosrend(rs.RecordCount, 3)
            While Not rs.EOF
                Cursosrend(c, 1) = rs("num_gra")
                Cursosrend(c, 2) = rs("let_cur")
                '***Inicio de detección de cambio de nivel***
                If Indica1 Then '
                    Ngrado = rs("num_gra")
                    Indica1 = False
                End If
                If rs("num_gra") <> Ngrado Then
                    Cursosrend(c - 1, 3) = "SI"
                    Ngrado = rs("num_gra")
                End If
                '***Fin detección de cambio de nivel***
                c = c + 1
                rs.MoveNext
            Wend
            Cursosrend(c - 1, 3) = "SI" ' Asigno este valor para poder tener un subtotal en el último nivel
        End If
        Ncursos = rs.RecordCount
        rs.Close
        Form_Progress.Label1.Caption = "Cargando ..."
        Form_Progress.ProgBar1.MaxValue = Ncursos
        Form_Progress.Show
              
        ' Variable de Totales a Cero
        Tcursos = 0: Tmat = 0: Pgral = 0: Divpgral = 0: Pmasalto = 0: Pmasbajo = 0: T6070 = 0: T5059 = 0: T4049 = 0: T3039 = 0: T2029 = 0: T1019 = 0: Tsinprom = 0: Tdefic = 0
        Pmasaltogral = 0: Pmasbajogral = 0:  Indica3 = True
        ' Variable de Subtotales a Cero
        ReDim Spasig(Nsubsectores, 2): ReDim Pasig(Nsubsectores, 2): Spasigxnivel = 0: Spgralxnivel = 0
        Stcursos = 0: Stmat = 0: Spgral = 0: Divspgral = 0: Spmasalto = 0: Spmasbajo = 0: St6070 = 0: St5059 = 0: St4049 = 0: St3039 = 0: St2029 = 0: St1019 = 0: Stsinprom = 0: Stdefic = 0
        Spgcurso = 0: Dpgcurso = 0
        Promediocurso = 0: Pmasaltonivel = 0: Pmasbajonivel = 0: Indica2 = True
        curso = 1
        'Me.grd_rendcurso.ColWidth(0) = 2000
        For t = 1 To Ncursos
            Spgcurso = 0: Dpgcurso = 0: Promediocurso = 0: Pgcurso = 0
            nivel = Cursosrend(t, 1)
            Letra = Cursosrend(t, 2)
            cambio = Cursosrend(t, 3)
            Me.grd_rendcurso.TextMatrix(Fila, 0) = " "
            Me.grd_rendcurso.TextMatrix(Fila, 1) = nivel & " " & Letra
            'rs.CursorLocation = adUseClient: rs.Open "select count(ci_alu) from alu_x_cur where cod_ens='" & modalidad & "' and num_gra = '" & Nivel & "' and let_cur = '" & Letra & "' and ucase(activo_alu) ='SI'and fec_cam='1111-11-11'", conn
            rs.CursorLocation = adUseClient: rs.Open "select count(a.ci_alu) from alu_x_cur a, matriculas m where a.agno=" & val(Combo_agno.Text) & " and a.ci_alu=m.ci_alu and m.activo_alu=a.activo_alu and m.fec_mat=a.fec_mat and a.cod_ens ='" & modalidad & "' and a.num_gra = '" & nivel & "' and a.let_cur ='" & Letra & "' and ucase(a.activo_alu)='SI' and a.fec_cam='1111-11-11' and m.fec_mat <= '" & Format(FechaFinPer, "yyyy-mm-dd") & "'", conn
            Stmat = Stmat + rs(0)
            Me.grd_rendcurso.TextMatrix(Fila, 2) = rs(0): rs.Close
            '******* PROMEDIO DE LAS PRUEBA DE NIVEL O LA PRUEBA INSTITUCIONAL BOSTONIANA************
                     
            Num_notas = val(devuelvecampo("evaluaciones", "", "notas_eva", "porcentaje_eva= 60", conn))
            porc_eva = val(devuelvecampo("evaluaciones", "", "porcentaje_eva", "porcentaje_eva= 60", conn))
            If Num_notas = 0 Then
                Num_notas = val(devuelvecampo("evaluaciones", "", "notas_eva", "porcentaje_eva=100", conn))
                porc_eva = val(devuelvecampo("evaluaciones", "", "porcentaje_eva", "des_eva='aprendizaje'", conn))
            End If
            Num_notas = 12
            
            For s = 1 To Nsubsectores
                SumProm = 0
                RsAux.CursorLocation = adUseClient
                    '******* PRUEBA DE NIVEL ********
                If Option_PN.Value Then
                    
                    If colegio = "PUD001" And cmb_per_rendcurso.Text = "SEGUNDO SEMESTRE" Then
                        a = "select avg(mid(n.nota," & 23 & ", 2)), n.cod_ens, n.num_gra, n.letra_curso, n.nota, e.porcentaje_eva from notas n, evaluaciones e where n.agno=" & val(Combo_agno.Text) & " and e.cod_eva = n.cod_eva and n.cod_ens = '" & modalidad & "' and n.num_gra = '" & nivel & "' and n.letra_curso ='" & Letra & "' and cod_asi = '" & Subsectorescurso(s, 1) & "' and porcentaje_eva ='" & porc_eva & "' and n.num_per='" & cmb_per_rendcurso.ListIndex & "' and  mid(n.nota," & 23 & ", 2) <>0 group by  n.letra_curso"
                    Else
                        If colegio = "PUD001" And cmb_per_rendcurso.Text = "ANUAL" Then
                            a = "select avg(mid(n.nota," & 23 & ", 2)), n.cod_ens, n.num_gra, n.letra_curso, n.nota, e.porcentaje_eva from notas n, evaluaciones e where n.agno=" & val(Combo_agno.Text) & " and e.cod_eva = n.cod_eva and n.cod_ens = '" & modalidad & "' and n.num_gra = '" & nivel & "' and n.letra_curso ='" & Letra & "' and cod_asi = '" & Subsectorescurso(s, 1) & "' and porcentaje_eva ='" & porc_eva & "' and n.num_per='" & cmb_per_rendcurso.ListIndex & "' and  mid(n.nota," & 23 & ", 2) <>0 group by  n.letra_curso"
                        Else
                            a = "select avg(mid(n.nota," & Num_notas * 2 - 3 & ", 2)), n.cod_ens, n.num_gra, n.letra_curso, n.nota, e.porcentaje_eva from notas n, evaluaciones e where n.agno=" & val(Combo_agno.Text) & " and e.cod_eva = n.cod_eva and n.cod_ens = '" & modalidad & "' and n.num_gra = '" & nivel & "' and n.letra_curso ='" & Letra & "' and cod_asi = '" & Subsectorescurso(s, 1) & "' and porcentaje_eva ='" & porc_eva & "' and n.num_per='" & cmb_per_rendcurso.ListIndex & "' and  mid(n.nota," & Num_notas * 2 - 3 & ", 2) <>0 group by  n.letra_curso"
                        End If
                    End If
                ElseIf Option_PIB.Value Then
                    '******* PRUEBA INSTITUCIONAL BOSTONIANA *******
                    a = "select avg(mid(n.nota," & Num_notas * 2 - 1 & ", 2)), n.cod_ens, n.num_gra, n.letra_curso, n.nota, e.porcentaje_eva from notas n, evaluaciones e where n.agno=" & val(Combo_agno.Text) & " and e.cod_eva = n.cod_eva and n.cod_ens = '" & modalidad & "' and n.num_gra = '" & nivel & "' and n.letra_curso ='" & Letra & "' and cod_asi = '" & Subsectorescurso(s, 1) & "' and porcentaje_eva ='" & porc_eva & "' and n.num_per='" & cmb_per_rendcurso.ListIndex & "' and  mid(n.nota," & Num_notas * 2 - 1 & ", 2) <>0 group by  n.letra_curso"
                Else
                    MsgBox "Error"
                    Exit Sub
                End If
                RsAux.Open a, conn
                                
                If RsAux.RecordCount > 0 Then
                    prom = Format(Int(Round((RsAux(0)) * 10, 1)) / 100, "0.0")
                    'Prom = rsaux(0)
                    If Len(CStr(prom)) < 3 And val(Trim(prom)) > 0 Then
                        Promediocurso = Format(val(prom), "#.0") 'Format(Int((SumPro / Divisor) * 10) / 10, ".0")
                    Else
                        Promediocurso = prom
                    End If
                    '*********
                        Promediocurso = IIf(Len(CStr(Promediocurso)) = 1, Format(Promediocurso, ".0"), Mid(CStr(Promediocurso), 1, 3))
                        Spasig(s, 1) = Spasig(s, 1) + Promediocurso
                        Spasig(s, 2) = Spasig(s, 2) + 1
                        If Trim(Subsectorescurso(s, 1)) <> "13" Then
                        Spgcurso = Spgcurso + Promediocurso
                        Dpgcurso = Dpgcurso + 1
                    End If
                    Colorcel = IIf(Promediocurso < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 2: Me.grd_rendcurso.CellForeColor = Colorcel
                    '*********
                    
                    
                    
                Else
                    Promediocurso = "-"
                End If
                
                RsAux.Close
                
                Me.grd_rendcurso.TextMatrix(Fila, s + 2) = Promediocurso
                
                Me.grd_rendcurso.Refresh
            Next s
            '******* FIN PROMEDIO DE LAS PRUEBA DE NIVEL ************
            
            If Spgcurso > 0 And Dpgcurso > 0 Then
                Pgcurso = Spgcurso / Dpgcurso
                Pgcurso = IIf(Len(CStr(Pgcurso)) = 1, Format(Pgcurso, ".0"), Mid(CStr(Pgcurso), 1, 3))
                Colorcel = IIf(Pgcurso < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Col = s + 2: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellForeColor = Colorcel
                Spgral = Spgral + Pgcurso
                Divspgral = Divspgral + 1
            Else
                Pgcurso = "-"
            End If
            Me.grd_rendcurso.Col = s + 2: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4
            Me.grd_rendcurso.TextMatrix(Fila, s + 2) = Pgcurso '''''''
            
            If IsNull(Pmasalto) Or Pmasalto = 0 Then
                Pmasalto = "-"
            Else
                Pmasalto = IIf(Len(CStr(Pmasalto)) = 1, Format(Pmasalto, ".0"), Mid(CStr(Pmasalto), 1, 3))
                Colorcel = IIf(Pmasalto < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 3: Me.grd_rendcurso.CellForeColor = Colorcel
            End If
            If IsNull(Pmasbajo) Or Pmasbajo = 0 Then
                Pmasbajo = "-"
            Else
                Pmasbajo = IIf(Len(CStr(Pmasbajo)) = 1, Format(Pmasbajo, ".0"), Mid(CStr(Pmasbajo), 1, 3))
                Colorcel = IIf(Pmasbajo < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 4: Me.grd_rendcurso.CellForeColor = Colorcel
            End If
            Me.grd_rendcurso.Col = s + 3: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 3) = Pmasalto ''''''
            Me.grd_rendcurso.Col = s + 4: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 4) = Pmasbajo ''''''
            If Pmasalto >= Pmasaltonivel Then Pmasaltonivel = Pmasalto
            If Indica2 And Pmasbajo <> "-" Then
                Pmasbajonivel = Pmasbajo
                Indica2 = False
            End If
            If Pmasbajo < Pmasbajonivel And Pmasbajo <> "-" Then Pmasbajonivel = Pmasbajo
           
            Me.grd_rendcurso.Col = s + 5: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 5) = A6070 '''''''
            Me.grd_rendcurso.Col = s + 6: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 6) = A5059 '''''''
            Me.grd_rendcurso.Col = s + 7: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 7) = A4049 '''''''
            Me.grd_rendcurso.Col = s + 8: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.CellForeColor = &HFF&: Me.grd_rendcurso.TextMatrix(Fila, s + 8) = A3039 '''''''
            Me.grd_rendcurso.Col = s + 9: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.CellForeColor = &HFF&: Me.grd_rendcurso.TextMatrix(Fila, s + 9) = A2029 '''''''
            Me.grd_rendcurso.Col = s + 10: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.CellForeColor = &HFF&: Me.grd_rendcurso.TextMatrix(Fila, s + 10) = A1019 '''''''
            Sinprom = val(Me.grd_rendcurso.TextMatrix(Fila, 2)) - (val(Me.grd_rendcurso.TextMatrix(Fila, s + 5)) + val(Me.grd_rendcurso.TextMatrix(Fila, s + 6)) + val(Me.grd_rendcurso.TextMatrix(Fila, s + 7)) + val(Me.grd_rendcurso.TextMatrix(Fila, s + 8)) + val(Me.grd_rendcurso.TextMatrix(Fila, s + 9)) + val(Me.grd_rendcurso.TextMatrix(Fila, s + 10)))
            Stsinprom = Stsinprom + Sinprom
            Defic = val(Me.grd_rendcurso.TextMatrix(Fila, s + 8)) + val(Me.grd_rendcurso.TextMatrix(Fila, s + 9)) + val(Me.grd_rendcurso.TextMatrix(Fila, s + 10))
            Stdefic = Stdefic + Defic
            Me.grd_rendcurso.Col = s + 11: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 11) = Sinprom
            Me.grd_rendcurso.Col = s + 12: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.CellForeColor = &HFF&: Me.grd_rendcurso.TextMatrix(Fila, s + 12) = Defic
           
            Me.grd_rendcurso.Rows = Me.grd_rendcurso.Rows + 1
            Fila = Fila + 1
            If cambio = "SI" Then
                Me.grd_rendcurso.TextMatrix(Fila, 0) = "Total nivel"
                Me.grd_rendcurso.TextMatrix(Fila, 1) = curso
                Me.grd_rendcurso.TextMatrix(Fila, 2) = Stmat: Tmat = Tmat + Stmat
                For j = 1 To Nsubsectores
                    If Spasig(j, 1) > 0 And Spasig(j, 2) > 0 Then
                        Spasigxnivel = Spasig(j, 1) / Spasig(j, 2)
                        Spasigxnivel = IIf(Len(CStr(Spasigxnivel)) = 1, Format(Spasigxnivel, ".0"), Mid(CStr(Spasigxnivel), 1, 4))
                        Colorcel = IIf(Spasigxnivel < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Col = 2 + j: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellForeColor = Colorcel
                        Pasig(j, 1) = Pasig(j, 1) + Spasigxnivel
                        Pasig(j, 2) = Pasig(j, 2) + 1
                    Else
                        Spasigxnivel = "-"
                    End If
                    Me.grd_rendcurso.Col = 2 + j: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4
                    Me.grd_rendcurso.TextMatrix(Fila, 2 + j) = Spasigxnivel
                Next j
                If Spgral > 0 And Divspgral > 0 Then
                    Spgralxnivel = Spgral / Divspgral
                    Spgralxnivel = IIf(Len(CStr(Spgralxnivel)) = 1, Format(Spgralxnivel, ".0"), Mid(CStr(Spgralxnivel), 1, 4))
                    Colorcel = IIf(Spgralxnivel < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Col = s + 2: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellForeColor = Colorcel
                    Pgral = Pgral + Spgralxnivel
                    Divpgral = Divpgral + 1
               Else
                    Spgralxnivel = "-"
                End If
           
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 2: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 2) = Spgralxnivel
           
                If IsNull(Pmasaltonivel) Or Pmasaltonivel = 0 Then
                    Pmasaltonivel = "-"
                Else
                    Pmasaltonivel = IIf(Len(CStr(Pmasaltonivel)) = 1, Format(Pmasaltonivel, ".0"), Mid(CStr(Pmasaltonivel), 1, 3))
                    Colorcel = IIf(Pmasaltonivel < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 3: Me.grd_rendcurso.CellForeColor = Colorcel
                End If
           
                If IsNull(Pmasbajonivel) Or Pmasbajonivel = 0 Then
                    Pmasbajonivel = "-"
                Else
                    Pmasbajonivel = IIf(Len(CStr(Pmasbajonivel)) = 1, Format(Pmasbajonivel, ".0"), Mid(CStr(Pmasbajonivel), 1, 3))
                    Colorcel = IIf(Pmasbajonivel < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 4: Me.grd_rendcurso.CellForeColor = Colorcel
                End If
           
                If Pmasaltonivel >= Pmasaltogral Then Pmasaltogral = Pmasaltonivel
           
                If Indica3 And Pmasbajonivel <> "-" Then
                    Pmasbajogral = Pmasbajonivel
                    Indica3 = False
                End If
                If Pmasbajonivel < Pmasbajogral And Pmasbajonivel <> "-" Then Pmasbajogral = Pmasbajonivel
           
           
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 3: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 3) = Pmasaltonivel
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 4: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 4) = Pmasbajonivel
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 5: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 5) = St6070: T6070 = T6070 + St6070
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 6: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 6) = St5059: T5059 = T5059 + St5059
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 7: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 7) = St4049: T4049 = T4049 + St4049
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 8: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 8) = St3039: T3039 = T3039 + St3039
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 9: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 9) = St2029: T2029 = T2029 + St2029
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 10: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 10) = St1019: T1019 = T1019 + St1019
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 11: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 11) = Stsinprom: Tsinprom = Tsinprom + Stsinprom
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 12: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 12) = Stdefic: Tdefic = Tdefic + Stdefic
           
                ReDim Spasig(Nsubsectores, 2)
                Spasigxnivel = 0: Spgralxnivel = 0
                Stcursos = 0: Stmat = 0: Spgral = 0: Divspgral = 0: Spmasalto = 0: Spmasbajo = 0: St6070 = 0: St5059 = 0: St4049 = 0: St3039 = 0: St2029 = 0: St1019 = 0: Stsinprom = 0: Stdefic = 0
                Spgcurso = 0: Dpgcurso = 0: Pmasaltonivel = 0: Pmasbajonivel = 0: Indica2 = True
                curso = 0
           
               Me.grd_rendcurso.Rows = Me.grd_rendcurso.Rows + 2
                For p = 2 To Me.grd_rendcurso.Cols - 1
                    Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = p: Me.grd_rendcurso.CellBackColor = &H8000000F
                Next p
                Fila = Fila + 2
            End If
        Form_Progress.ProgBar1.ShowProgress t
        Form_Progress.SetFocus
        DoEvents
        curso = curso + 1
        Next t
                ' Aquí van los totales
        For p = 2 To Me.grd_rendcurso.Cols - 1
               Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = p: Me.grd_rendcurso.CellBackColor = &H8000000F
            Next p
            Me.grd_rendcurso.TextMatrix(Fila, 0) = "Total colegio"
            Me.grd_rendcurso.TextMatrix(Fila, 1) = Ncursos ' aqui van la cantidad de cursos del nivel.
            Me.grd_rendcurso.TextMatrix(Fila, 2) = Tmat ' aqui van la totalidad de los cursos del informe
            For j = 1 To Nsubsectores
                If Pasig(j, 1) > 0 And Pasig(j, 2) > 0 Then
                    Pasigxnivel = Pasig(j, 1) / Pasig(j, 2)
                    Pasigxnivel = IIf(Len(CStr(Pasigxnivel)) = 1, Format(Pasigxnivel, ".0"), Mid(CStr(Pasigxnivel), 1, 4))
                    Colorcel = IIf(Pasigxnivel < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Col = 2 + j: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellForeColor = Colorcel
                Else
                    Pasigxnivel = "-"
                End If
                Me.grd_rendcurso.Col = 2 + j: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4
                Me.grd_rendcurso.TextMatrix(Fila, 2 + j) = Pasigxnivel
            Next j
                If Pgral > 0 And Divpgral > 0 Then
                    Pgralxnivel = Pgral / Divpgral
                    Pgralxnivel = IIf(Len(CStr(Pgralxnivel)) = 1, Format(Pgralxnivel, ".0"), Mid(CStr(Pgralxnivel), 1, 4))
                    Colorcel = IIf(Pgralxnivel < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Col = s + 2: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellForeColor = Colorcel
                Else
                    Pgralxnivel = "-"
                End If
                Me.grd_rendcurso.Col = s + 2: Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.CellAlignment = 4
                Me.grd_rendcurso.TextMatrix(Fila, s + 2) = Pgralxnivel
                
                If IsNull(Pmasaltogral) Or Pmasaltogral = 0 Then
                    Pmasaltogral = "-"
                Else
                    Pmasaltogral = IIf(Len(CStr(Pmasaltogral)) = 1, Format(Pmasaltogral, ".0"), Mid(CStr(Pmasaltogral), 1, 3))
                    Colorcel = IIf(Pmasaltogral < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 3: Me.grd_rendcurso.CellForeColor = Colorcel
                End If
                
                If IsNull(Pmasbajogral) Or Pmasbajogral = 0 Then
                    Pmasbajogral = "-"
                Else
                    Pmasbajogral = IIf(Len(CStr(Pmasbajogral)) = 1, Format(Pmasbajogral, ".0"), Mid(CStr(Pmasbajogral), 1, 3))
                    Colorcel = IIf(Pmasbajogral < 4#, &HFF&, &HFF0000): Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 4: Me.grd_rendcurso.CellForeColor = Colorcel
                End If
                                
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 3: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 3) = Pmasaltogral
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 4: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 4) = Pmasbajogral
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 5: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 5) = T6070
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 6: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 6) = T5059
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 7: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 7) = T4049
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 8: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 8) = T3039
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 9: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 9) = T2029
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 10: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 10) = T1019
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 11: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 11) = Tsinprom
                Me.grd_rendcurso.Row = Fila: Me.grd_rendcurso.Col = s + 12: Me.grd_rendcurso.CellAlignment = 4: Me.grd_rendcurso.TextMatrix(Fila, s + 12) = Tdefic
End If


Form_Progress.ProgBar1.ShowProgress 0
Unload Form_Progress
End Sub

Private Sub ActualizaTablaPdN()
    Dim sql As String
    Dim NNt As Integer
    Dim porc As Integer
    
    'Numero de NoTas evaluadas en un periodo
    NNt = val(RetornaCampo("evaluaciones", "notas_eva", "des_eva='APRENDIZAJE'", conn))
    
    porc = val(RetornaCampo("evaluaciones", "porcentaje_eva", "des_eva='APRENDIZAJE'", conn))
    
    NNt = IIf((NNt > 0), NNt, 1)
    'Actualiza las Estadisticas para el año.
    sql = "REPLACE INTO informe_PdN(colegio, cod_asi, num_per, agno, prom_PdN, stddev_PdN, max_PdN, min_PdN, mediana_PdN, equilibrio_PdN, 70_a_60, 59_a_50, 49_a_40, 39_a_30, 29_a_20, 19_a_10, num_alu, cod_ens, num_gra, letra_curso, porcentaje_eva)"
    sql = sql & "Select '" & RetornaCampo("CFG", "valor", "param='CODBC'", conn) & "' AS colegio, n.cod_asi, n.num_per, n.agno,avg(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10) as 'prom_PdN', stddev(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10) as 'stddev_PdN', max(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10) as 'max_PdN', min(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10) as 'min_PdN', "
    sql = sql & "((max(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10) + min(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10))/2) as 'mediana_PdN', (sqrt(abs( (avg(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10)) - ((max(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10) + min(mid(n.nota, (" & NNt & " * 2) - 3 , 2)/10))/2))) / count(n.cod_asi)) * 100  as 'equilibrio_PdN', "
    sql = sql & "sum((if ( (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)>=60 and (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)<=70,1,0))) as '70_a_60', sum((if ( (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)>=50 and (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)<=59,1,0))) as '59_a_50', sum((if ( (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)>=40 and (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)<=49,1,0))) as '49_a_40', "
    sql = sql & "sum((if ( (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)>=30 and (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)<=39,1,0))) as '39_a_30', sum((if ( (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)>=20 and (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)<=29,1,0))) as '29_a_20', sum((if ( (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)>=10 and (mid(n.nota, (" & NNt & " * 2) - 3, 2)+0)<=19,1,0))) as '19_a_10', "
    sql = sql & "count(Distinct n.ci_alu) as 'num_alu', n.cod_ens, n.num_gra, n.letra_curso, e.porcentaje_eva from notas n, evaluaciones e WHERE e.cod_eva = n.cod_eva and e.porcentaje_eva ='" & porc & "' and  mid(n.nota, (" & NNt & " * 2) - 3, 2)+0 <>0 and n.agno=" & Trim(Combo_agno.Text) & " "
    sql = sql & "GROUP BY  colegio, n.agno, n.num_per, n.cod_ens, n.num_gra, n.letra_curso, n.cod_asi ORDER BY colegio, n.agno DESC, n.num_per, n.cod_ens, n.num_gra, n.letra_curso, n.cod_asi;"
    
    conn.Execute sql
End Sub

Private Function SelectNiveles() As String
    SelectNiveles = ""
    For i = 0 To lst_niveles_rendcurso.ListCount - 1
        If lst_niveles_rendcurso.Selected(i) Then
            If SelectNiveles = "" Then
                SelectNiveles = SelectNiveles & "({informe_pdn.num_gra}='" & i + 1 & "'"
            Else
                SelectNiveles = SelectNiveles & " or {informe_pdn.num_gra}='" & i + 1 & "'"
            End If
        End If
    Next i
    SelectNiveles = IIf((SelectNiveles = ""), "", " and " & SelectNiveles & ")")
    '{informe_pdn.agno}=2006 and {informe_pdn.cod_ens}='310' and ({informe_pdn.num_gra}='1' or {informe_pdn.num_gra}='2')
End Function

Private Sub Btn_gen_Rep_Rendcurso_Click()
'On Error GoTo Errorimpresion
    
If Option2.Value Then 'Por subsector
    Call LimpiaFormulas(Form_main.CrystalReport, 30)
    ActualizaTablaPdN
        Form_main.CrystalReport.WindowTitle = "Pruebas de  Nivel - Subsetores"
        Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\informe_pdn_subsec_graf.rpt"
        Form_main.CrystalReport.ReplaceSelectionFormula ("{informe_pdn.agno}=" & Trim(Combo_agno.Text) & " and {informe_pdn.num_per}='" & cmb_per_rendcurso.ListIndex & "' and {informe_pdn.cod_ens}='" & RetornaCampo("codigos_ensenanza", "cod_ens", "DES_ENS='" & cmb_mod_rendcurso.Text & "'", conn) & "'" & SelectNiveles())
        Form_main.CrystalReport.WindowState = crptMaximized
        Form_main.CrystalReport.Action = 1
        Form_main.CrystalReport.ReplaceSelectionFormula ("")
    Call LimpiaFormulas(Form_main.CrystalReport, 30)
ElseIf Option3.Value Then 'Por Curso
    Call LimpiaFormulas(Form_main.CrystalReport, 30)
    ActualizaTablaPdN
        Form_main.CrystalReport.WindowTitle = "Pruebas de  Nivel - Subsetores"
        Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\informe_pdn_curso_graf.rpt"
        Form_main.CrystalReport.ReplaceSelectionFormula ("{informe_pdn.agno}=" & Trim(Combo_agno.Text) & " and {informe_pdn.num_per}='" & cmb_per_rendcurso.ListIndex & "' and {informe_pdn.cod_ens}='" & RetornaCampo("codigos_ensenanza", "cod_ens", "DES_ENS='" & cmb_mod_rendcurso.Text & "'", conn) & "'" & SelectNiveles())
        Form_main.CrystalReport.WindowState = crptMaximized
        Form_main.CrystalReport.Action = 1
        Form_main.CrystalReport.ReplaceSelectionFormula ("")
    Call LimpiaFormulas(Form_main.CrystalReport, 30)
ElseIf Option1.Value Then
    Call CreaBD(DirAplicacion & "\GesTemp.mdb")
    Set Rendcurso = DBEngine.Workspaces(0).OpenDatabase(DirAplicacion & "\GesTemp.mdb")
    Call CreaTabla(DirAplicacion & "\GesTemp.mdb", "Pan_cur1", "30,10")
    Call CreaTabla(DirAplicacion & "\GesTemp.mdb", "Pan_cur2", "25,10")
    infoprimera = Nsubsectores + 2
    detal = "": ins = ""
    For c = 3 To infoprimera
        If Me.grd_rendcurso.TextMatrix(0, c) = "" Then
            detal = detal & "Null , "
        Else
            detal = detal & "'" & Me.grd_rendcurso.TextMatrix(0, c) & "' , "
        End If
        ins = ins & "C" & CStr(c - 2) & ", "
    Next c
    ins = Left(ins, Len(ins) - 2): ins = "(" & ins & ")"
    detal = Left(detal, Len(detal) - 2): detal = "(" & detal & ")"
    a = "insert into Pan_cur2 " & ins & " values " & detal
    Rendcurso.Execute a
    
    For R = 1 To Me.grd_rendcurso.Rows - 1
        detal = "": ins = "": horiz = ""
        For t = 0 To 1
            If Me.grd_rendcurso.TextMatrix(R, t) = "" Then
                detal = detal & "Null , "
            Else
                detal = detal & "'" & Me.grd_rendcurso.TextMatrix(R, t) & "' , "
            End If
            ins = ins & "C" & CStr(t + 1) & ", "
        Next t
        For t = 2 To infoprimera
            If Me.grd_rendcurso.TextMatrix(R, t) = "" Then
                detal = detal & "Null , "
            Else
                detal = detal & "'" & Me.grd_rendcurso.TextMatrix(R, t) & "' , "
            End If
            ins = ins & "C" & CStr(t + 1) & ", "
        Next t
        Columna = infoprimera + 1
        
        For te = t + 1 To 19 '+1
            detal = detal & "Null , "
            ins = ins & "C" & CStr(te) & ", "
        Next te
            
        For t = te To 30
            'If Me.grd_rendcurso.TextMatrix(R, Columna) = "-" Or
            If Me.grd_rendcurso.TextMatrix(R, Columna) = "" Then
                detal = detal & "Null , "
            Else
                detal = detal & "'" & Me.grd_rendcurso.TextMatrix(R, Columna) & "' , "
            End If
            ins = ins & "C" & CStr(t) & ", "
            Columna = Columna + 1
        Next t
        ins = Left(ins, Len(ins) - 2): ins = "(" & ins & ")"
        detal = Left(detal, Len(detal) - 2): detal = "(" & detal & ")"
        a = "insert into Pan_cur1 " & ins & " values " & detal
        Rendcurso.Execute a
    Next R
    Rendcurso.Close
        If Option_PN.Value Then
            '****** PRUEBA DE NIVEL ********
            Titulo = "ANALISIS PRUEBA DE NIVEL" & Me.cmb_per_rendcurso.Text & " PERÍODO ESCOLAR " & val(Combo_agno.Text)
        ElseIf Option_PIB.Value Then
            '****** PRUEBA INSTITUCIONAL BOSTONIANA *******
            Titulo = "ANALISIS P.I.B. " & Me.cmb_per_rendcurso.Text & " PERÍODO ESCOLAR " & val(Combo_agno.Text)
        Else
            MsgBox "Error, no esta seleccionado el tipo de prueba."
            Exit Sub
        End If
        Nombrecol = devuelvecampo("establecimientos", "", "nom_est", "nom_est <> ''", conn)
        Direccol = devuelvecampo("establecimientos", "", "dir_est", "dir_est <> ''", conn)
        ComunaCol = devuelvecampo("establecimientos", "", "localidad_est", "localidad_est <> ''", conn)
        Form_main.CrystalReport.WindowTitle = Titulo
        Form_main.CrystalReport.Formulas(0) = "Nomcol = '" & Nombrecol & "'"
        Form_main.CrystalReport.Formulas(1) = "Dircol = '" & Direccol & "'"
        Form_main.CrystalReport.Formulas(2) = "Comunacol = '" & ComunaCol & "'"
        Form_main.CrystalReport.Formulas(3) = "Titulo= '" & Titulo & "'"
        Form_main.CrystalReport.Formulas(4) = "Hora = '" & Time & "'"
        Form_main.CrystalReport.Formulas(5) = "Tipens= '" & Me.cmb_mod_rendcurso.Text & "'"
        Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\estpnivel.rpt"
        Form_main.CrystalReport.DataFiles(0) = DirAplicacion & "\GesTemp.mdb"
        Form_main.CrystalReport.WindowState = crptMaximized
        Form_main.CrystalReport.Action = 1
        Form_main.CrystalReport.ReplaceSelectionFormula ("")
        Call LimpiaFormulas(Form_main.CrystalReport, 30)
        Kill (DirAplicacion & "\GesTemp.mdb")
    End If
Exit Sub
Errorimpresion:
If Err.Number = 20513 Then
    MsgBox "Hubo problemas al imprimir"
Else
    MsgBox Err.Source & vbCrLf & vbCrLf & Err.Description, vbCritical + vbOKOnly, Err.Number
    'Resume
End If
End Sub



Private Sub Btn_limpiar_Rendcurso_Click()
Me.Btn_gen_Rep_Rendcurso.Enabled = False
Me.cmb_mod_rendcurso.Text = ""
Me.lst_niveles_rendcurso.Clear
Me.cmb_per_rendcurso.Text = ""
Call Grillainicial2
End Sub

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

End Sub

Private Sub cmb_mod_rendcurso_Click()
Me.chk_todos_niveles_rendcurso.Enabled = True
Me.chk_todos_niveles_rendcurso.Value = 0
modalidad = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.cmb_mod_rendcurso.Text & "'", conn)
rs.CursorLocation = adUseClient
rs.Open "SELECT * FROM codigos_ensenanza where cod_ens ='" & modalidad & "'", conn
If rs.RecordCount > 0 Then
    Me.lst_niveles_rendcurso.Clear
    For t = 1 To val(rs("num_gra_max"))
        lst_niveles_rendcurso.AddItem t
    Next t
    Me.chk_todos_niveles_rendcurso.Enabled = True
Else
    Me.chk_todos_niveles_rendcurso.Enabled = False
End If
rs.Close
Me.cmb_per_rendcurso.Text = ""
Call Grillainicial2
Me.Btn_gen_Rep_Rendcurso.Enabled = False
End Sub


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

Private Sub cmb_per_rendcurso_Click()
If Me.cmb_mod_rendcurso <> "" And Me.lst_niveles_rendcurso.SelCount > 0 And cmb_per_rendcurso.Text <> "" Then
    Call Grillainicial2
    Me.Btn_gen_Rep_Rendcurso.Enabled = False
    Call btn_carga_grilla_oculta_rendcurso_Click
    Me.Btn_gen_Rep_Rendcurso.Enabled = True
Else
    'MsgBox ("Faltan opciones importantes por seleccionar")
End If

End Sub

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

Private Sub Combo_agno_Click()
    cmb_per_rendcurso_Click
End Sub

Private Sub Form_Load()
If Menuinformes3 = "rendimientocurso" Then
    Set rs = New ADODB.Recordset
    Set RsAux = New ADODB.Recordset
    Me.Height = 7700
    Me.Width = 11865
    Me.Frame_Rendcurso.Top = 120
    Me.Frame_Rendcurso.Left = 129
    Me.Frame_Rendcurso.Visible = True
    Call llenacombo(cmb_mod_rendcurso, "codigos_ensenanza", "des_ens", "order by ord_ens", conn)
    Call llenacombo(cmb_per_rendcurso, "periodos", "des_per", "", conn)
    Call llenacombo(Combo_agno, "alu_x_cur", "distinct agno", "order by agno DESC", conn)
    If Combo_agno.ListCount > 0 Then
        Combo_agno.ListIndex = 0
    End If
    If Me.cmb_per_rendcurso.ListCount > 0 Then
        Me.cmb_per_rendcurso.AddItem "ANUAL"
    End If
    Call Grillainicial2
    CentrarForma Me
    Me.Show
    Me.chk_todos_niveles_rendcurso.Enabled = False
    Me.Opt_destino_rendcurso(0).Value = True
    Me.Btn_gen_Rep_Rendcurso.Enabled = False
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Form_Estpnivel.Hide
    Unload Form_Estpnivel
End Sub

Private Sub lst_niveles_rendcurso_Click()
Me.cmb_per_rendcurso.Text = ""
Me.Btn_gen_Rep_Rendcurso.Enabled = False
End Sub

Private Sub Opt_destino_rendcurso_Click(Index As Integer)
If Index = 0 Then
    Form_main.CrystalReport.Destination = crptToWindow
ElseIf Index = 1 Then
    Form_main.CrystalReport.Destination = crptToPrinter
End If
End Sub

Private Sub Option_PIB_Click()
    cmb_per_rendcurso_Click
End Sub

Private Sub Option_PN_Click()
    cmb_per_rendcurso_Click
End Sub


