VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{F39CBE5C-2D1B-11D6-8D4A-0050043A2E60}#2.0#0"; "ProgBarProzent.ocx"
Begin VB.Form Form_InfoNotas 
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   6915
   ClientLeft      =   825
   ClientTop       =   1785
   ClientWidth     =   11595
   Icon            =   "Form_InfoNotas.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   Moveable        =   0   'False
   ScaleHeight     =   6915
   ScaleWidth      =   11595
   Begin VB.CommandButton cmd_exportar_excel 
      Caption         =   "Exportar Excel"
      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          =   375
      Left            =   8400
      TabIndex        =   24
      Top             =   1200
      Width           =   1335
   End
   Begin VB.ComboBox cb_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            =   6000
      TabIndex        =   21
      Text            =   "Combo1"
      Top             =   360
      Width           =   2055
   End
   Begin VB.ComboBox Cmd_Per 
      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          =   330
      Left            =   6000
      Style           =   2  'Dropdown List
      TabIndex        =   20
      Top             =   840
      Width           =   2055
   End
   Begin ProgBarProzent.ProgBar ProgBar2 
      Height          =   375
      Left            =   120
      TabIndex        =   19
      Top             =   6360
      Width           =   11295
      _ExtentX        =   19923
      _ExtentY        =   661
   End
   Begin MSComDlg.CommonDialog CmDialog1 
      Left            =   960
      Top             =   1200
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton BtnConfImp 
      Caption         =   "Conf. Impresora"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   9960
      TabIndex        =   18
      Top             =   720
      Width           =   1455
   End
   Begin VB.CommandButton BrnCanPanCur 
      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            =   9960
      TabIndex        =   17
      Top             =   1200
      Width           =   1455
   End
   Begin VB.Frame Frame3 
      Caption         =   "Destino"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   8400
      TabIndex        =   14
      Top             =   0
      Width           =   1335
      Begin VB.OptionButton OptDesPan 
         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
         Left            =   120
         TabIndex        =   16
         Top             =   360
         Width           =   975
      End
      Begin VB.OptionButton OptDesImp 
         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
         Left            =   120
         TabIndex        =   15
         Top             =   720
         Width           =   1095
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Opciones "
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   8400
      TabIndex        =   11
      Top             =   0
      Visible         =   0   'False
      Width           =   1335
      Begin VB.OptionButton OptOptTod 
         Caption         =   "Todos"
         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        =   13
         Top             =   720
         Width           =   975
      End
      Begin VB.OptionButton OptOptUno 
         Caption         =   "Un Curso"
         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        =   12
         Top             =   360
         Value           =   -1  'True
         Width           =   1095
      End
   End
   Begin ProgBarProzent.ProgBar ProgBar1 
      Height          =   375
      Left            =   120
      TabIndex        =   10
      Top             =   5880
      Width           =   11295
      _ExtentX        =   19923
      _ExtentY        =   661
   End
   Begin VB.CommandButton BtnGenRep 
      Caption         =   "Generar Reportes"
      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          =   375
      Left            =   9960
      TabIndex        =   9
      Top             =   240
      Width           =   1455
   End
   Begin VB.CommandButton BtnGrabaMatriz 
      Caption         =   "Guarda Matriz"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   8400
      TabIndex        =   8
      Top             =   1200
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.Frame Frame1 
      Caption         =   "Curso"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1575
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   4695
      Begin VB.ComboBox Cmb_Cod_ens 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1920
         Style           =   2  'Dropdown List
         TabIndex        =   3
         Top             =   360
         Width           =   2475
      End
      Begin VB.ComboBox Cmb_Grado 
         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          =   330
         Left            =   1920
         Style           =   2  'Dropdown List
         TabIndex        =   2
         Top             =   720
         Width           =   615
      End
      Begin VB.ComboBox Cmb_Let_Cur 
         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          =   330
         Left            =   1920
         Style           =   2  'Dropdown List
         TabIndex        =   1
         Top             =   1080
         Width           =   615
      End
      Begin VB.Label Label2 
         Caption         =   "Letra Curso"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   360
         TabIndex        =   6
         Top             =   1080
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "Grado"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   360
         TabIndex        =   5
         Top             =   720
         Width           =   495
      End
      Begin VB.Label Tipo 
         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          =   195
         Left            =   360
         TabIndex        =   4
         Top             =   360
         Width           =   1455
      End
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   3975
      Left            =   120
      TabIndex        =   7
      Top             =   1800
      Width           =   11355
      _ExtentX        =   20029
      _ExtentY        =   7011
      _Version        =   393216
      Cols            =   3
      ForeColorSel    =   16777215
      Enabled         =   0   'False
      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 Label4 
      Caption         =   "Periodo"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   5040
      TabIndex        =   23
      Top             =   840
      Width           =   735
   End
   Begin VB.Label Label3 
      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            =   5040
      TabIndex        =   22
      Top             =   360
      Width           =   735
   End
End
Attribute VB_Name = "Form_InfoNotas"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim CodModalidad As String

Private Sub BrnCanPanCur_Click()
Unload Me
End Sub

Private Sub BtnConfImp_Click()
CmDialog1.CancelError = False
CmDialog1.PrinterDefault = True
CmDialog1.Flags = cdlPDPrintSetup
CmDialog1.ShowPrinter
End Sub

Private Sub BtnGenRep_Click()

If Cmd_Per.Text = "Seleccione Período" Then
    MsgBox "Debe seleccionar un Período", vbExclamation + vbOKOnly
    Cmd_Per.SetFocus
End If


If Me.OptOptUno.Value = True Then
    Call GenRep
Else

    n = 0
    For a = 0 To Me.Cmb_Cod_ens.ListCount - 1
        If a = 0 Then a = 1
        If a = 3 Then Exit For
        Cmb_Cod_ens.ListIndex = a
        For b = 0 To Me.Cmb_Grado.ListCount - 1
            Cmb_Grado.ListIndex = b
            For c = 0 To Me.Cmb_Let_Cur.ListCount - 1
                Cmb_Let_Cur.ListIndex = c
                        n = n + 1
                   Call GenRep
            Next c
        Next b
    Next a

End If

End Sub

Private Sub BtnGrabaMatriz_Click()
'***********************************************************************
'* Guarda matriz en base de datos temporal GesTem.mdb en el directorio *
'* de la aplicacion                                                    *
'***********************************************************************

Call CreaBD(DirAplicacion & "\GesTemp.mdb")
Call CreaTabla(DirAplicacion & "\GesTemp.mdb", "PAN_CUR1", "1,10-45,6")
Call CreaTabla(DirAplicacion & "\GesTemp.mdb", "PAN_CUR2", "45,10")
Dim dbsTemp As Database
Dim rsTemp As Recordset
Dim CamposInsert, ValoresInsert As String
Set dbsTemp = OpenDatabase(DirAplicacion & "\GesTemp.mdb")
Set rsTemp = dbsTemp.OpenRecordset("PAN_CUR1", dbOpenDynaset)

MSFlexGrid1.TextMatrix(0, 0) = "               "
MSFlexGrid1.Col = 0
MSFlexGrid1.Row = 0
MSFlexGrid1.CellAlignment = 4

ValoresInsert = ""
CamposInsert = ""
For I = 0 To Me.MSFlexGrid1.Cols - 2
    CamposInsert = CamposInsert & "C" & I + 1 & ", "
    ValoresInsert = ValoresInsert & "'" & Me.MSFlexGrid1.TextMatrix(0, I) & "', "
Next I
For nul = 1 To 18 - I - 1
    CamposInsert = CamposInsert & "C" & I + nul & ", "
    contenido = "Null" & ", "
    ValoresInsert = ValoresInsert & contenido
Next nul
CamposInsert = CamposInsert & "C" & I + nul & ", "
contenido = "'" & Me.MSFlexGrid1.TextMatrix(f, I) & "', "
ValoresInsert = ValoresInsert & contenido


CamposInsert = "(" & Mid(CamposInsert, 1, Len(CamposInsert) - 2) & ")"
ValoresInsert = "(" & Mid(ValoresInsert, 1, Len(ValoresInsert) - 2) & ")"
dbsTemp.Execute "INSERT INTO PAN_CUR2" & CamposInsert & "values" & ValoresInsert
        
     
ValoresInsert = ""
For f = 1 To Me.MSFlexGrid1.Rows - 1
        ValoresInsert = ""
        '***********
        For I = 1 To Me.MSFlexGrid1.Cols - 2
            If val(Me.MSFlexGrid1.TextMatrix(f, I)) = 0 Then
                contenido = "Null" & ", "
            Else
                contenido = "'" & Me.MSFlexGrid1.TextMatrix(f, I) & "', "
            End If
            ValoresInsert = ValoresInsert & contenido
        Next I
        
        For nul = 1 To 18 - I - 1
            contenido = "Null" & ", "
            ValoresInsert = ValoresInsert & contenido
        Next nul
           
        contenido = "'" & Me.MSFlexGrid1.TextMatrix(f, I) & "', "
        ValoresInsert = ValoresInsert & contenido
        nombre = Trim(Mid(Me.MSFlexGrid1.TextMatrix(f, 0), 11, Len(Me.MSFlexGrid1.TextMatrix(f, 0))))
        If nombre <> "" Then
            Pos = InStr(1, nombre, "'")
            If Pos <> 0 Then
                nombre1 = Mid(nombre, 1, Pos) & "'" & Mid(nombre, Pos + 1, Len(nombre))
                nombre = nombre1
            End If
        End If

        
        ValoresInsert = "'" & nombre & "', " & ValoresInsert
        ValoresInsert = "(" & Mid(ValoresInsert, 1, Len(ValoresInsert) - 2) & ")"
        
     
        dbsTemp.Execute "INSERT INTO PAN_CUR1" & CamposInsert & " values" & Trim(ValoresInsert)

Next f
Set dbsTemp = Nothing
End Sub




Private Sub cb_agno_Click()
    'Cmd_Per.Text = "Seleccione Período"
    MSFlexGrid1.Clear
    Cmd_Per.ListIndex = 0
End Sub

Private Sub Cmb_Cod_ens_Click()
If Len(Me.Cmb_Cod_ens) <> 0 Then
 CodModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.Cmb_Cod_ens.Text & "'", conn)
 Cmb_Grado.Enabled = True
 Cmb_Grado.Clear

rut = val(DevuelveCampo("usuarios", "", "rut_usu", "aut_nombre_usuario = '" & Nom_usu_ses & "'", conn))

If CodPerfil = "#UTP#" Or CodPerfil = "#ADM#" Or CodPerfil = "#GES03#" Or CodPerfil = "#PJE#" Then
    If Len(Me.Cmb_Cod_ens.Text) <> 0 Then
        nivel = DevuelveCampo("codigos_ensenanza", "des_ens", "num_gra_max", "des_ens = " & "'" & Me.Cmb_Cod_ens.Text & "'", conn)
        Me.Cmb_Grado.Enabled = True
        Me.Cmb_Grado.Clear
    For t = 1 To val(nivel)
        Me.Cmb_Grado.AddItem t
    Next t
 End If

Else
    Call LlenaCombo(Form_InfoNotas.Cmb_Grado, "asi_x_cur_prof AP", "DISTINCT AP.NUM_GRA", "where AP.cod_ens = '" & CodModalidad & "' and MID(rut_prof,1,(LENGTH(ap.rut_prof)-2)) ='" & rut & "'", conn)
End If

 
 Cmb_Let_Cur.Clear

End If
Me.MSFlexGrid1.Clear
End Sub

Private Sub Cmb_Grado_Click()
Ngrado = Me.Cmb_Grado.Text
Cmb_Let_Cur.Clear

rut = val(DevuelveCampo("usuarios", "", "rut_usu", "aut_nombre_usuario = '" & Nom_usu_ses & "'", conn))

If CodPerfil = "#UTP#" Or CodPerfil = "#ADM#" Or CodPerfil = "#GES03#" Or CodPerfil = "#PJE#" Then
    Call LlenaCombo(Me.Cmb_Let_Cur, "cursos", "distinct let_cur", "where cod_ens = '" & CodModalidad & "' and agno=" & cb_agno.Text & " and num_gra = '" & Ngrado & "'", conn)
Else
    'Call llenacombo(Form_Notas.Cmb_Cod_ens, "codigos_ensenanza ce, asi_x_cur_prof ap", "distinct ce.des_ens", "where ce.cod_ens = ap.cod_ens and ap.rut_prof ='" & Rutglobal & "'")
    Call LlenaCombo(Cmb_Let_Cur, "asi_x_cur_prof ap", "distinct ap.let_cur", "where ap.cod_ens = '" & CodModalidad & "' and ap.num_gra = '" & Ngrado & "' and ap.agno=" & cb_agno.Text & " and MID(rut_prof,1,(LENGTH(ap.rut_prof)-2)) ='" & rut & "'", conn)
End If
Me.Cmb_Let_Cur.Enabled = True

'btn_carga_asignaturas_Click

'Cmb_Asi.Clear
'If Me.Cmb_Sector <> "" Then
'    Call llenacombo(Form_InfoNotas.Cmb_Asi, "subsectores ss, sectores s", "NOM_ASI", "where ss.cod_sec = s.cod_sec and ss.cod_ens ='" & CodModalidad & "' and num_gra ='" & Ngrado & "' and ss.cod_sec ='" & CodSec & "'")
'End If
Me.MSFlexGrid1.Clear
End Sub
Private Sub Cmb_let_cur_Click()
Cmd_Per.Enabled = True
Cmd_Per.ListIndex = 0
MSFlexGrid1.Clear
'Cmd_Per_Click
End Sub


Private Sub cmd_exportar_excel_Click()
    Dim ApExcel As Variant
    Set ApExcel = CreateObject("Excel.application")
    ApExcel.Workbooks.Add
          
    For I = 1 To Me.MSFlexGrid1.Cols - 1
        ApExcel.Cells(1, I + 1).Font.Size = 12
        ApExcel.Cells(1, I + 1).Font.Bold = True
        ApExcel.Cells(1, I + 1).Formula = Me.MSFlexGrid1.TextMatrix(0, I)
    Next I
    ProgBar2.MinValue = 1
    ProgBar2.MaxValue = MSFlexGrid1.Rows
    ProgBar2.ShowProgress ProgBar2.MinValue
    For I = 1 To MSFlexGrid1.Rows - 1

         For j = 0 To MSFlexGrid1.Cols - 1
            ApExcel.Cells((I + 1), (j + 1)).Formula = IIf(MSFlexGrid1.TextMatrix(I, j) = "Null", "", MSFlexGrid1.TextMatrix(I, j))
        
         ProgBar2.ShowProgress I
        Next j
    Next I
    ProgBar2.ShowProgress ProgBar2.MaxValue
            
    ApExcel.Visible = True
    'ApExcel.Range("a1:x1").Borders.color = RGB(255, 0, 0)
    Set ApExcel = Nothing
End Sub

Private Sub Cmd_Per_Click()
Dim var_sql As String
Dim objRS As ADODB.Recordset
Set objRS = New ADODB.Recordset

On Error GoTo Controlerror
If Cmd_Per.Text = "Seleccione Período" Then MsgBox "Debe seleccionar un Período", vbExclamation + vbOKOnly: Cmd_Per.SetFocus: Exit Sub

'###################### Cambio de estado Botones ##################
Me.BtnConfImp.Enabled = False
Me.BrnCanPanCur.Enabled = False
Me.BtnGenRep.Enabled = False
'##################################################################

Dim OrdAsi()
Dim Divisor As Integer
Dim suma, Rs3 As Single
Dim suma_natu As Single
Dim cont_natu As Integer
Dim Per As String
Rs3 = 0
cole = DevuelveCampo("cfg", "", "valor", "param = 'codbc'", conn)
If cole = "FLO001" And cb_agno = 2021 Then
    Select Case Cmd_Per.ListIndex
        Case 1: Per = "p1"
        Case 2: Per = "p2"
        Case 3: Per = "p3"
        Case 4: Per = "nf"
    End Select
Else
    Select Case Cmd_Per.ListIndex
        Case 1: Per = "p1"
        Case 2: Per = "p2"
        Case 3: Per = "nf"
    End Select
End If

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient

'***********************************************************************
'* Establece tamaño de la grilla                                       *
'***********************************************************************
Me.MSFlexGrid1.Clear
a = "select  ap.cod_ens, ss.nom_asi,  ap.num_gra, ap.let_cur, ap.cod_sec, ap.cod_asi  from  asi_x_cur_prof ap, subsectores ss, sectores s where not isnull(ss.ord_asi) and ss.ord_asi<>'0' and s.cod_sec = ss.cod_sec and ss.cod_sec = ap.cod_sec and ss.cod_asi = ap.cod_asi and ss.cod_ens = ap.cod_ens and ap.agno=" & cb_agno.Text & " and ss.num_gra = ap.num_gra and ap.cod_ens ='" & CodModalidad & "' and ap.num_gra='" & Me.Cmb_Grado & "' and ap.let_cur ='" & Me.Cmb_Let_Cur & "' order by ss.ord_asi"
rs.Open a, conn
  If rs.RecordCount > 0 Then
Me.MSFlexGrid1.Cols = rs.RecordCount + 1 + 1
End If
rs.Close
'**************************************************************************

'******* ENCABEZADO ASIGNATURAS Y MATRIZ ********
a = "select  ap.cod_ens, ss.nom_asi,  ap.num_gra, ap.let_cur, ap.cod_sec, ap.cod_asi  from  asi_x_cur_prof ap, subsectores ss, sectores s where not isnull(ss.ord_asi) and ss.ord_asi<>'0' and s.cod_sec = ss.cod_sec and ss.cod_sec = ap.cod_sec and ss.cod_asi = ap.cod_asi and ss.cod_ens = ap.cod_ens and ap.agno=" & cb_agno.Text & " and ss.num_gra = ap.num_gra and ap.cod_ens ='" & CodModalidad & "' and ap.num_gra='" & Me.Cmb_Grado & "' and ap.let_cur ='" & Me.Cmb_Let_Cur & "' order by ss.ord_asi"
rs.CursorLocation = adUseClient
rs.Open a, conn
If rs.RecordCount > 0 Then
    While Not rs.EOF
        ''''''''''Ciencias Naturales
'''''''        If (CStr(rs(1)) = "BIOLOGIA" Or CStr(rs(1)) = "FISICA" Or CStr(rs(1)) = "QUIMICA") And Me.Cmb_Grado = 1 And CodModalidad = "310" Then
'''''''        Else
            X = MSFlexGrid1.Cols
            c = c + 1
            MSFlexGrid1.TextMatrix(0, c) = rs(1)
            MSFlexGrid1.ColWidth(c) = 2000
'''''''        End If
        rs.MoveNext
    Wend
    MSFlexGrid1.TextMatrix(0, c + 1) = "Prom."
rs.Close

End If
'**************************************************

alumno = 0

a = "select p.ape_pat_alu, p.ape_mat_alu, p.nom_alu, p.ci_alu from  postulantes p, alu_x_cur a where a.agno=" & cb_agno.Text & " and p.ci_alu = a.ci_alu and a.activo_alu='SI' and a.cod_ens = '" & CodModalidad & " ' and a.num_gra = '" & Me.Cmb_Grado & "' and a.let_cur ='" & Me.Cmb_Let_Cur & "' order by ape_pat_alu, ape_mat_alu, nom_alu"
    MSFlexGrid1.Enabled = True

rs.CursorLocation = adUseClient
rs.Open a, conn

If rs.RecordCount > 0 Then
    MSFlexGrid1.Rows = rs.RecordCount + 1

    For alumno = 1 To rs.RecordCount
        MSFlexGrid1.Col = 0
        MSFlexGrid1.Row = alumno
        MSFlexGrid1.CellAlignment = 1

        MSFlexGrid1.TextMatrix(alumno, 0) = rs(3) & "  " & rs(0) & " " & rs(1) & " " & rs(2)
        rs.MoveNext
    Next alumno
End If
rs.Close
'***********************************************************************
'* inicializa la barra de progreso                                     *
'***********************************************************************
nmax = MSFlexGrid1.Rows
  With ProgBar1
    .MaxValue = nmax
    .Richtung = mDir
    .ProgressStyle = mStyle
    .ShowProzent = 1
    .Zusatztext = "%"
    .ShowProgress 0
  End With
'***********************************************************************

cole = DevuelveCampo("cfg", "", "valor", "param = 'codbc'", conn)
'****************** LLENA ASIGNATURAS ********************
For f = 1 To Me.MSFlexGrid1.Rows - 1
        a = "select p.ci_alu, ss.ord_asi, ss.nom_asi, p." & Per & " from promedios p, subsectores ss where tipo_eva = 0 and p.agno=" & cb_agno.Text & " and p.cod_ens=ss.cod_ens and p.num_gra=ss.num_gra and p.ci_alu ='" & Left(Me.MSFlexGrid1.TextMatrix(f, 0), 10) & "' and p.cod_sec=ss.cod_sec and p.cod_asi=ss.cod_asi and p.cod_ens='" & CodModalidad & "' and p.num_gra='" & Me.Cmb_Grado & "' and p.letra_curso='" & Me.Cmb_Let_Cur & "' order by p.ci_alu, ord_asi"
        On Error GoTo 0
        rs.CursorLocation = adUseClient
        rs.Open a, conn
        
        If rs.RecordCount > 0 Then
        

            c = 0
            Divisor = 0
            suma = 0
            While Not rs.EOF
            If IsNull(rs(3)) Then
                Rs3 = 0
            Else
                '''''Ciencias naturales
                If CStr(rs(2)) = "CIENCIAS NATURALES" And Me.Cmb_Grado = 1 And CodModalidad = "310" And cole <> "HUE001" And cole <> "SNB001" And cole <> "PUD001" Then
                    
                    '''''Primer Semestre
                    var_sql = "SELECT MID(nota,1,2) AS n1,MID(nota,3,2) AS n2,MID(nota,5,2) AS n3,MID(nota,7,2) AS n4,MID(nota,9,2) AS n5,MID(nota,11,2) AS n6," _
                            & "MID(nota,13,2) AS n7,MID(nota,15,2) AS n8,MID(nota,17,2) AS n9,MID(nota,19,2) AS n10,MID(nota,21,2) AS n11,MID(nota,23,2) AS n12" _
                            & " From notas" _
                            & " WHERE tipo_eva = 0 and cod_ens = '310' AND num_gra = 1 AND (cod_asi = 3 OR cod_asi = 7 OR cod_asi = 8) AND ci_alu = '" & rs(0) & "' AND num_per = 0 AND cod_sec = '0011' AND agno = " & cb_agno.Text
                    objRS.Open var_sql, conn
                    suma_natu = 0
                    cont_natu = 0
                    While Not objRS.EOF
                        suma_natu = suma_natu + val(objRS(0)) + val(objRS(1)) + val(objRS(2)) + val(objRS(3)) + val(objRS(4)) + val(objRS(5)) + val(objRS(6)) + val(objRS(7)) + val(objRS(8)) + val(objRS(9)) + val(objRS(10)) + val(objRS(11)) + val(objRS(10))
                        cont_natu = cont_natu + IIf(objRS(0) = "  " Or objRS(0) = "", 0, 1) + IIf(objRS(1) = "  " Or objRS(1) = "", 0, 1) + IIf(objRS(2) = "  " Or objRS(2) = "", 0, 1) + IIf(objRS(3) = "  " Or objRS(3) = "", 0, 1) + IIf(objRS(4) = "  " Or objRS(4) = "", 0, 1)
                        cont_natu = cont_natu + IIf(objRS(5) = "  " Or objRS(5) = "", 0, 1) + IIf(objRS(6) = "  " Or objRS(6) = "", 0, 1) + IIf(objRS(7) = "  " Or objRS(7) = "", 0, 1) + IIf(objRS(8) = "  " Or objRS(8) = "", 0, 1) + IIf(objRS(9) = "  " Or objRS(9) = "", 0, 1)
                        cont_natu = cont_natu + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1) + IIf(objRS(11) = "  " Or objRS(11) = "", 0, 1) + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1)
                        objRS.MoveNext
                    Wend
                    objRS.Close
                    '''''Segundo Semestre
                    var_sql = "SELECT MID(nota,1,2) AS n1,MID(nota,3,2) AS n2,MID(nota,5,2) AS n3,MID(nota,7,2) AS n4,MID(nota,9,2) AS n5,MID(nota,11,2) AS n6," _
                            & "MID(nota,13,2) AS n7,MID(nota,15,2) AS n8,MID(nota,17,2) AS n9,MID(nota,19,2) AS n10,MID(nota,21,2) AS n11,MID(nota,23,2) AS n12" _
                            & " From notas" _
                            & " WHERE tipo_eva = 0 and cod_ens = '310' AND num_gra = 1 AND (cod_asi = 3 OR cod_asi = 7 OR cod_asi = 8) AND ci_alu = '" & rs(0) & "' AND num_per = 1 AND cod_sec = '0011' AND agno = " & cb_agno.Text
                    objRS.Open var_sql, conn
                    suma_natu2 = 0
                    cont_natu2 = 0
                    While Not objRS.EOF
                        suma_natu2 = suma_natu2 + val(objRS(0)) + val(objRS(1)) + val(objRS(2)) + val(objRS(3)) + val(objRS(4)) + val(objRS(5)) + val(objRS(6)) + val(objRS(7)) + val(objRS(8)) + val(objRS(9)) + val(objRS(10)) + val(objRS(11)) + val(objRS(10))
                        cont_natu2 = cont_natu2 + IIf(objRS(0) = "  " Or objRS(0) = "", 0, 1) + IIf(objRS(1) = "  " Or objRS(1) = "", 0, 1) + IIf(objRS(2) = "  " Or objRS(2) = "", 0, 1) + IIf(objRS(3) = "  " Or objRS(3) = "", 0, 1) + IIf(objRS(4) = "  " Or objRS(4) = "", 0, 1)
                        cont_natu2 = cont_natu2 + IIf(objRS(5) = "  " Or objRS(5) = "", 0, 1) + IIf(objRS(6) = "  " Or objRS(6) = "", 0, 1) + IIf(objRS(7) = "  " Or objRS(7) = "", 0, 1) + IIf(objRS(8) = "  " Or objRS(8) = "", 0, 1) + IIf(objRS(9) = "  " Or objRS(9) = "", 0, 1)
                        cont_natu2 = cont_natu2 + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1) + IIf(objRS(11) = "  " Or objRS(11) = "", 0, 1) + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1)
                        objRS.MoveNext
                    Wend
                    objRS.Close
                    '''''Tercer Semestre
                    If cole = "FLO001" And cb_agno = 2021 Then
                        var_sql = "SELECT MID(nota,1,2) AS n1,MID(nota,3,2) AS n2,MID(nota,5,2) AS n3,MID(nota,7,2) AS n4,MID(nota,9,2) AS n5,MID(nota,11,2) AS n6," _
                                & "MID(nota,13,2) AS n7,MID(nota,15,2) AS n8,MID(nota,17,2) AS n9,MID(nota,19,2) AS n10,MID(nota,21,2) AS n11,MID(nota,23,2) AS n12" _
                                & " From notas" _
                                & " WHERE tipo_eva = 0 and cod_ens = '310' AND num_gra = 1 AND (cod_asi = 3 OR cod_asi = 7 OR cod_asi = 8) AND ci_alu = '" & rs(0) & "' AND num_per = 2 AND cod_sec = '0011' AND agno = " & cb_agno.Text
                        objRS.Open var_sql, conn
                        suma_natu3 = 0
                        cont_natu3 = 0
                        While Not objRS.EOF
                            suma_natu3 = suma_natu3 + val(objRS(0)) + val(objRS(1)) + val(objRS(2)) + val(objRS(3)) + val(objRS(4)) + val(objRS(5)) + val(objRS(6)) + val(objRS(7)) + val(objRS(8)) + val(objRS(9)) + val(objRS(10)) + val(objRS(11)) + val(objRS(10))
                            cont_natu3 = cont_natu3 + IIf(objRS(0) = "  " Or objRS(0) = "", 0, 1) + IIf(objRS(1) = "  " Or objRS(1) = "", 0, 1) + IIf(objRS(2) = "  " Or objRS(2) = "", 0, 1) + IIf(objRS(3) = "  " Or objRS(3) = "", 0, 1) + IIf(objRS(4) = "  " Or objRS(4) = "", 0, 1)
                            cont_natu3 = cont_natu3 + IIf(objRS(5) = "  " Or objRS(5) = "", 0, 1) + IIf(objRS(6) = "  " Or objRS(6) = "", 0, 1) + IIf(objRS(7) = "  " Or objRS(7) = "", 0, 1) + IIf(objRS(8) = "  " Or objRS(8) = "", 0, 1) + IIf(objRS(9) = "  " Or objRS(9) = "", 0, 1)
                            cont_natu3 = cont_natu3 + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1) + IIf(objRS(11) = "  " Or objRS(11) = "", 0, 1) + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1)
                            objRS.MoveNext
                        Wend
                        objRS.Close
                    End If
                    If suma_natu <> 0 Then
                        If Per = "p1" Then Rs3 = Mid((suma_natu / cont_natu) / 10, 1, 3)
                    End If
                    If suma_natu2 <> 0 Then
                        If Per = "p2" Then Rs3 = Mid((suma_natu2 / cont_natu2) / 10, 1, 3)
                    End If
                    If cole = "FLO001" And cb_agno = 2021 Then
                        If suma_natu3 <> 0 Then
                            If Per = "p3" Then Rs3 = Mid((suma_natu3 / cont_natu3) / 10, 1, 3)
                        End If
                        If suma_natu > 0 And suma_natu2 > 0 And suma_natu3 > 0 Then
                            If Per = "nf" Then Rs3 = Format(CSng(CSng(Mid((suma_natu / cont_natu) / 10, 1, 3)) + CSng(Mid((suma_natu2 / cont_natu2) / 10, 1, 3)) + CSng(Mid((suma_natu3 / cont_natu3) / 10, 1, 3))) / 3, "0.0")
                        End If
                    Else
                        If suma_natu > 0 And suma_natu2 > 0 Then
                            If Per = "nf" Then Rs3 = Format((CSng(CSng(Mid((suma_natu / cont_natu) / 10, 1, 3)) + CSng(Mid((suma_natu2 / cont_natu2) / 10, 1, 3))) / 2) + 0.05, "0.0")
                        End If
                    End If
                    
                    'Rs3 = Mid((suma_natu / cont_natu) / 10, 1, 3)
                Else
                    If CStr(rs(2)) = "CIENCIAS NATURALES" And Me.Cmb_Grado = 2 And CodModalidad = "310" And (cole = "LON001" Or cole = "FLO001" Or cole = "SNM001") Then
                    
                    '''''Primer Semestre
                    var_sql = "SELECT MID(nota,1,2) AS n1,MID(nota,3,2) AS n2,MID(nota,5,2) AS n3,MID(nota,7,2) AS n4,MID(nota,9,2) AS n5,MID(nota,11,2) AS n6," _
                            & "MID(nota,13,2) AS n7,MID(nota,15,2) AS n8,MID(nota,17,2) AS n9,MID(nota,19,2) AS n10,MID(nota,21,2) AS n11,MID(nota,23,2) AS n12" _
                            & " From notas" _
                            & " WHERE tipo_eva = 0 and cod_ens = '310' AND num_gra = 2 AND (cod_asi = 3 OR cod_asi = 7 OR cod_asi = 8) AND ci_alu = '" & rs(0) & "' AND num_per = 0 AND cod_sec = '0011' AND agno = " & cb_agno.Text
                    objRS.Open var_sql, conn
                    suma_natu = 0
                    cont_natu = 0
                    While Not objRS.EOF
                        suma_natu = suma_natu + val(objRS(0)) + val(objRS(1)) + val(objRS(2)) + val(objRS(3)) + val(objRS(4)) + val(objRS(5)) + val(objRS(6)) + val(objRS(7)) + val(objRS(8)) + val(objRS(9)) + val(objRS(10)) + val(objRS(11)) + val(objRS(10))
                        cont_natu = cont_natu + IIf(objRS(0) = "  " Or objRS(0) = "", 0, 1) + IIf(objRS(1) = "  " Or objRS(1) = "", 0, 1) + IIf(objRS(2) = "  " Or objRS(2) = "", 0, 1) + IIf(objRS(3) = "  " Or objRS(3) = "", 0, 1) + IIf(objRS(4) = "  " Or objRS(4) = "", 0, 1)
                        cont_natu = cont_natu + IIf(objRS(5) = "  " Or objRS(5) = "", 0, 1) + IIf(objRS(6) = "  " Or objRS(6) = "", 0, 1) + IIf(objRS(7) = "  " Or objRS(7) = "", 0, 1) + IIf(objRS(8) = "  " Or objRS(8) = "", 0, 1) + IIf(objRS(9) = "  " Or objRS(9) = "", 0, 1)
                        cont_natu = cont_natu + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1) + IIf(objRS(11) = "  " Or objRS(11) = "", 0, 1) + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1)
                        objRS.MoveNext
                    Wend
                    objRS.Close
                    '''''Segundo Semestre
                    var_sql = "SELECT MID(nota,1,2) AS n1,MID(nota,3,2) AS n2,MID(nota,5,2) AS n3,MID(nota,7,2) AS n4,MID(nota,9,2) AS n5,MID(nota,11,2) AS n6," _
                            & "MID(nota,13,2) AS n7,MID(nota,15,2) AS n8,MID(nota,17,2) AS n9,MID(nota,19,2) AS n10,MID(nota,21,2) AS n11,MID(nota,23,2) AS n12" _
                            & " From notas" _
                            & " WHERE tipo_eva = 0 and cod_ens = '310' AND num_gra = 2 AND (cod_asi = 3 OR cod_asi = 7 OR cod_asi = 8) AND ci_alu = '" & rs(0) & "' AND num_per = 1 AND cod_sec = '0011' AND agno = " & cb_agno.Text
                    objRS.Open var_sql, conn
                    suma_natu2 = 0
                    cont_natu2 = 0
                    While Not objRS.EOF
                        suma_natu2 = suma_natu2 + val(objRS(0)) + val(objRS(1)) + val(objRS(2)) + val(objRS(3)) + val(objRS(4)) + val(objRS(5)) + val(objRS(6)) + val(objRS(7)) + val(objRS(8)) + val(objRS(9)) + val(objRS(10)) + val(objRS(11)) + val(objRS(10))
                        cont_natu2 = cont_natu2 + IIf(objRS(0) = "  " Or objRS(0) = "", 0, 1) + IIf(objRS(1) = "  " Or objRS(1) = "", 0, 1) + IIf(objRS(2) = "  " Or objRS(2) = "", 0, 1) + IIf(objRS(3) = "  " Or objRS(3) = "", 0, 1) + IIf(objRS(4) = "  " Or objRS(4) = "", 0, 1)
                        cont_natu2 = cont_natu2 + IIf(objRS(5) = "  " Or objRS(5) = "", 0, 1) + IIf(objRS(6) = "  " Or objRS(6) = "", 0, 1) + IIf(objRS(7) = "  " Or objRS(7) = "", 0, 1) + IIf(objRS(8) = "  " Or objRS(8) = "", 0, 1) + IIf(objRS(9) = "  " Or objRS(9) = "", 0, 1)
                        cont_natu2 = cont_natu2 + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1) + IIf(objRS(11) = "  " Or objRS(11) = "", 0, 1) + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1)
                        objRS.MoveNext
                    Wend
                    objRS.Close
''''''''''                    If Per = "p1" Then Rs3 = Mid((suma_natu / cont_natu) / 10, 1, 3)
''''''''''                    If Per = "p2" And suma_natu2 > 0 Then Rs3 = Mid((suma_natu2 / cont_natu2) / 10, 1, 3)
''''''''''                    If Per = "nf" Then Rs3 = Format(CSng(CSng(Mid((suma_natu / cont_natu) / 10, 1, 3)) + CSng(Mid((suma_natu2 / cont_natu2) / 10, 1, 3))) / 2, "0.0")
                     '''''Tercer Semestre
                    If cole = "FLO001" And cb_agno = 2021 Then
                        var_sql = "SELECT MID(nota,1,2) AS n1,MID(nota,3,2) AS n2,MID(nota,5,2) AS n3,MID(nota,7,2) AS n4,MID(nota,9,2) AS n5,MID(nota,11,2) AS n6," _
                                & "MID(nota,13,2) AS n7,MID(nota,15,2) AS n8,MID(nota,17,2) AS n9,MID(nota,19,2) AS n10,MID(nota,21,2) AS n11,MID(nota,23,2) AS n12" _
                                & " From notas" _
                                & " WHERE tipo_eva = 0 and cod_ens = '310' AND num_gra = 2 AND (cod_asi = 3 OR cod_asi = 7 OR cod_asi = 8) AND ci_alu = '" & rs(0) & "' AND num_per = 2 AND cod_sec = '0011' AND agno = " & cb_agno.Text
                        objRS.Open var_sql, conn
                        suma_natu3 = 0
                        cont_natu3 = 0
                        While Not objRS.EOF
                            suma_natu3 = suma_natu3 + val(objRS(0)) + val(objRS(1)) + val(objRS(2)) + val(objRS(3)) + val(objRS(4)) + val(objRS(5)) + val(objRS(6)) + val(objRS(7)) + val(objRS(8)) + val(objRS(9)) + val(objRS(10)) + val(objRS(11)) + val(objRS(10))
                            cont_natu3 = cont_natu3 + IIf(objRS(0) = "  " Or objRS(0) = "", 0, 1) + IIf(objRS(1) = "  " Or objRS(1) = "", 0, 1) + IIf(objRS(2) = "  " Or objRS(2) = "", 0, 1) + IIf(objRS(3) = "  " Or objRS(3) = "", 0, 1) + IIf(objRS(4) = "  " Or objRS(4) = "", 0, 1)
                            cont_natu3 = cont_natu3 + IIf(objRS(5) = "  " Or objRS(5) = "", 0, 1) + IIf(objRS(6) = "  " Or objRS(6) = "", 0, 1) + IIf(objRS(7) = "  " Or objRS(7) = "", 0, 1) + IIf(objRS(8) = "  " Or objRS(8) = "", 0, 1) + IIf(objRS(9) = "  " Or objRS(9) = "", 0, 1)
                            cont_natu3 = cont_natu3 + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1) + IIf(objRS(11) = "  " Or objRS(11) = "", 0, 1) + IIf(objRS(10) = "  " Or objRS(10) = "", 0, 1)
                            objRS.MoveNext
                        Wend
                        objRS.Close
                    End If
                    
'''                    If rs(0) = "21846060-7" Then
'''                        a = 1
'''                    End If
                    
                    If Per = "p1" And suma_natu > 0 Then Rs3 = Mid(Round(suma_natu / cont_natu) / 10, 1, 3)
                    If Per = "p2" And suma_natu2 > 0 Then Rs3 = Mid(Round(suma_natu2 / cont_natu2) / 10, 1, 3)
                    If cole = "FLO001" And cb_agno = 2021 Then
                        If Per = "p3" And suma_natu3 > 0 Then Rs3 = Mid((suma_natu3 / cont_natu3) / 10, 1, 3)
                        If suma_natu > 0 And suma_natu2 > 0 And suma_natu3 > 0 Then
                            If Per = "nf" Then Rs3 = Format(CSng(CSng(Mid((suma_natu / cont_natu) / 10, 1, 3)) + CSng(Mid((suma_natu2 / cont_natu2) / 10, 1, 3)) + CSng(Mid((suma_natu3 / cont_natu3) / 10, 1, 3))) / 3, "0.0")
                        End If
                        If suma_natu > 0 And suma_natu2 > 0 Then
                            If Per = "nf" Then Rs3 = Format(CSng(CSng(Mid((suma_natu / cont_natu) / 10, 1, 3)) + CSng(Mid((suma_natu2 / cont_natu2) / 10, 1, 3))) / 2, "0.0")
                        End If
                        If suma_natu > 0 And suma_natu3 > 0 Then
                            If Per = "nf" Then Rs3 = Format(CSng(CSng(Mid((suma_natu / cont_natu) / 10, 1, 3)) + CSng(Mid((suma_natu3 / cont_natu3) / 10, 1, 3))) / 2, "0.0")
                        End If
                    Else
                        If suma_natu > 0 And suma_natu2 > 0 Then
                            If Per = "nf" Then Rs3 = Format(CSng(CSng(Mid(Round(suma_natu / cont_natu) / 10, 1, 3)) + CSng(Mid(Round(suma_natu2 / cont_natu2) / 10, 1, 3))) / 2, "0.0")
                        End If
                        If suma_natu > 0 And suma_natu2 = 0 Then
                            If Per = "nf" Then Rs3 = Format(CSng(CSng(Mid(Round(suma_natu / cont_natu) / 10, 1, 3))), "0.0")
                        End If
                        If suma_natu = 0 And suma_natu2 > 0 Then
                            If Per = "nf" Then Rs3 = Format(CSng(CSng(Mid(Round(suma_natu2 / cont_natu2) / 10, 1, 3))) / 2, "0.0")
                        End If
                    End If
                    
                    
                    'Rs3 = Mid((suma_natu / cont_natu) / 10, 1, 3)
                    Else
                    Rs3 = CDbl(rs(3))
                    End If
                End If
                
                
            End If

                For I = 1 To Me.MSFlexGrid1.Cols - 1
                    
                    MSFlexGrid1.Col = I
                    MSFlexGrid1.Row = f
                    MSFlexGrid1.CellAlignment = 4
                    
                    If Me.MSFlexGrid1.TextMatrix(0, I) = rs(2) And Not (CStr(rs(2)) = CStr("RELIGION") Or CStr(rs(2)) = CStr("RELIGIÓN") Or CStr(rs(2)) = CStr("ORIENTACION") Or CStr(rs(2)) = CStr("ORIENTACIÓN")) Then
                        '''''Ciencias Naturales
                        If (CStr(rs(2)) = "BIOLOGIA" Or CStr(rs(2)) = "FISICA" Or CStr(rs(2)) = "QUIMICA") And Me.Cmb_Grado = 1 And CodModalidad = "310" And cole <> "HUE001" And cole <> "SNB001" Then
                        Else
                            If (CStr(rs(2)) = "BIOLOGIA" Or CStr(rs(2)) = "FISICA" Or CStr(rs(2)) = "QUIMICA") And Me.Cmb_Grado = 2 And CodModalidad = "310" And (cole = "LON001" Or cole = "FLO001" Or cole = "SNM001") Then
                            Else
                            c = c + 1
                            suma = suma + CDbl(Rs3)
                            End If
                        End If
                    End If
                
                    If Me.MSFlexGrid1.TextMatrix(0, I) = rs(2) Then
                        ''''''''Ciencia Naturales
                        If (CStr(rs(2)) = "BIOLOGIA" Or CStr(rs(2)) = "FISICA" Or CStr(rs(2)) = "QUIMICA") And Me.Cmb_Grado = 1 And CodModalidad = "310" And cole <> "HUE001" And cole <> "SNB001" Then
                        Else
                        If (CStr(rs(2)) = "BIOLOGIA" Or CStr(rs(2)) = "FISICA" Or CStr(rs(2)) = "QUIMICA") And Me.Cmb_Grado = 2 And CodModalidad = "310" And (cole = "LON001" Or cole = "FLO001" Or cole = "SNM001") Then
                        Else
                        If Len(str(Rs3)) < 3 And val(Trim(Rs3)) > 0 Then

                            '************ Rojos o Azules ***************
                            
                            If CDec(Rs3) < 4 Then
                                MSFlexGrid1.CellForeColor = &HFF&
                            Else
                                MSFlexGrid1.CellForeColor = &HFF0000
                            End If
                            '************ FIN Rojos o Azules ***************
                            
                            MSFlexGrid1.TextMatrix(f, I) = Format(val(Rs3), "#.0")
                            If Me.MSFlexGrid1.TextMatrix(0, I) = rs(2) And Not (rs(2) = "RELIGION" Or rs(2) = "RELIGIÓN" Or rs(2) = "ORIENTACION" Or rs(2) = "ORIENTACIÓN") Then Divisor = Divisor + 1
                        
                        Else
                           '************ Rojos o Azules ***************
                            If val(Trim(Rs3)) > 0 Then
                                If CDec(Rs3) < 4 Then
                                    MSFlexGrid1.CellForeColor = &HFF&
                                Else
                                    MSFlexGrid1.CellForeColor = &HFF0000
                                End If
                                '************ FIN Rojos o Azules ***************
                                MSFlexGrid1.TextMatrix(f, I) = Rs3
                                If Me.MSFlexGrid1.TextMatrix(0, I) = rs(2) And Not (rs(2) = "RELIGION" Or rs(2) = "RELIGIÓN" Or rs(2) = "ORIENTACION" Or rs(2) = "ORIENTACIÓN") Then Divisor = Divisor + 1
                            Else
                                MSFlexGrid1.TextMatrix(f, I) = ""
                            End If
                        End If
                        End If
                        End If
                    End If
                Next I
                rs.MoveNext
                Rs3 = 0
            Wend
        End If
        rs.Close
        If Divisor <> 0 Then
           '************ Rojos o Azules ***************
            
            If val(suma / Divisor) > 0 Then
                If CDec(suma / Divisor) < 4 Then
                    MSFlexGrid1.CellForeColor = &HFF&
                Else
                    MSFlexGrid1.CellForeColor = &HFF0000
                End If
            End If
           '************ FIN Rojos o Azules ***************
'''            If Per = "nf" Then
'''                'MSFlexGrid1.TextMatrix(f, MSFlexGrid1.Cols - 1) = Format(Int(Round((suma / Divisor) * 10, 0.05)) / 10, "0.0")
''''''''                If Me.Cmb_Grado = 1 And CodModalidad = "310" Then
''''''''                    MSFlexGrid1.TextMatrix(f, MSFlexGrid1.Cols - 4) = Format(Int(Round(((suma / Divisor) * 10) + 0.05)) / 10, "0.0")
''''''''                Else
'''                    MSFlexGrid1.TextMatrix(f, MSFlexGrid1.Cols - 1) = Format(Int(Round(((suma / Divisor) * 10) + 0.05)) / 10, "0.0")
'''''''                End If                                          'prom = Format(Int(Round(((SumPro / Divisor) * 10) + 0.05)) / 10, "0.0")
'''            Else
''''''''''                If Me.Cmb_Grado = 1 And CodModalidad = "310" Then
'''''''                    MSFlexGrid1.TextMatrix(f, MSFlexGrid1.Cols - 4) = Format(Int(Round((suma / Divisor) * 10, 1)) / 10, "0.0")
'''''''                Else
                    If cole = "FLO001" Then
                        MSFlexGrid1.TextMatrix(f, MSFlexGrid1.Cols - 1) = Format(Int(Round(((suma / Divisor) * 10) + 0.05)) / 10, "0.0")
                    Else
                        If Per = "p1" Or Per = "p2" Then
                            MSFlexGrid1.TextMatrix(f, MSFlexGrid1.Cols - 1) = Format(Int(Round((suma / Divisor) * 10, 1)) / 10, "0.0")
                        Else
                            MSFlexGrid1.TextMatrix(f, MSFlexGrid1.Cols - 1) = Format(Int(Round(((suma / Divisor) * 10) + 0.05)) / 10, "0.0")
                        End If
                    End If
'''''''                End If
'''''            End If
            'prom = Format(Int(Round(((SumPro / Divisor) * 10) + 0.05)) / 10, "0.0")
            
        End If
       ProgBar1.ShowProgress f
       DoEvents
Next f
'**********************************************************



Call BtnGrabaMatriz_Click
ProgBar1.ShowProgress 100
'###################### Cambio de estado Botones ##################
Me.BtnConfImp.Enabled = True
Me.BtnGenRep.Enabled = True
Me.BrnCanPanCur.Enabled = True
Me.cmd_exportar_excel.Enabled = True
'##################################################################
'Cmd_Per.Enabled = False
'Cmd_Per.ListIndex = 0

Exit Sub
Controlerror:
If Err.Number = 3705 Then
    rs.Close
    Resume
Else
    MsgBox "Error :" & Err.Number & Chr(13) & Err.Description
    'Resume
End If

End Sub






Private Sub Form_Load()
CentrarForma Me
llena_combo_anno
Me.OptOptUno.Value = True
Me.OptDesPan.Value = True
'###################### GRILLA #########################
MSFlexGrid1.ColWidth(0) = 4000
'###################### GRILLA #########################

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient

'********* Llena combos ****************
Me.Cmd_Per.Clear
Me.Cmd_Per.AddItem "Seleccione Período"
'Call LlenaCombo(Me.Cmd_Per, "periodos p", "distinct p.des_per, p.num_per", "order by p.num_per", conn)
cole = DevuelveCampo("cfg", "", "valor", "param = 'codbc'", conn)
If cole = "FLO001" And cb_agno = 2021 Then
    Me.Cmd_Per.AddItem "PRIMER TRIMESTRE"
    Me.Cmd_Per.AddItem "SEGUNDO TRIMESTRE"
    Me.Cmd_Per.AddItem "TERCER TRIMESTRE"
Else
    Me.Cmd_Per.AddItem "PRIMER SEMESTRE"
    Me.Cmd_Per.AddItem "SEGUNDO SEMESTRE"
End If
Me.Cmd_Per.AddItem "ANUAL"

rut = val(DevuelveCampo("usuarios", "", "rut_usu", "aut_nombre_usuario = '" & Nom_usu_ses & "'", conn))

If CodPerfil = "#UTP#" Or CodPerfil = "#ADM#" Or CodPerfil = "#GES#" Or CodPerfil = "#PJE#" Then
    Call LlenaCombo(Form_InfoNotas.Cmb_Cod_ens, "codigos_ensenanza ce", "distinct ce.des_ens", "order by ce.ord_ens", conn)
Else
    Call LlenaCombo(Form_InfoNotas.Cmb_Cod_ens, "codigos_ensenanza ce, asi_x_cur_prof ap", "distinct ce.des_ens", "where ce.cod_ens = ap.cod_ens and MID(rut_prof,1,(LENGTH(ap.rut_prof)-2)) ='" & rut & "' order by ce.ord_ens", conn)
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call menuhabilitado(True)
End Sub




Private Sub OptDesImp_Click()
If Me.OptDesImp.Value = True Then Form_main.CrystalReport.Destination = crptToPrinter
End Sub

Private Sub OptDesImp_GotFocus()
If Me.OptDesImp.Value = True Then Form_main.CrystalReport.Destination = crptToPrinter
End Sub


Private Sub OptDesPan_Click()
If Me.OptDesPan.Value = True Then Form_main.CrystalReport.Destination = crptToWindow
End Sub

Private Sub OptDesPan_GotFocus()
If Me.OptDesPan.Value = True Then Form_main.CrystalReport.Destination = crptToWindow
End Sub


Private Sub OptOptTod_Click()
If Me.OptOptTod.Value = True Then Me.Frame1.Enabled = False
End Sub

Private Sub OptOptTod_GotFocus()
If Me.OptOptTod.Value = True Then Me.Frame1.Enabled = False
End Sub


Private Sub OptOptUno_Click()
If Me.OptOptUno.Value = True Then Me.Frame1.Enabled = True
End Sub

Private Sub OptOptUno_GotFocus()
If Me.OptOptUno.Value = True Then Me.Frame1.Enabled = True
End Sub

Public Sub GenRep()
On Error GoTo controler
'**************************************
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
a = "select nom_est, dir_est, localidad_est from establecimientos"
rs.Open a, conn
If rs.RecordCount > 0 Then
Form_main.CrystalReport.Formulas(0) = "NomCol = '" & rs(0) & "'"
Form_main.CrystalReport.Formulas(1) = "DirCol = '" & rs(1) & "'"
Form_main.CrystalReport.Formulas(2) = "ComunaCol = '" & rs(2) & "'"
End If
rs.Close
a = "select p.ape1_prof, p.ape2_prof, p.noms_prof from profesores p, cursos c where p.rut_prof = c.rut_prof and c.cod_ens='" & CodModalidad & "' and c.num_gra ='" & Me.Cmb_Grado & "' and c.let_cur ='" & Me.Cmb_Let_Cur & "' and c.agno=" & cb_agno.Text & ";"
rs.CursorLocation = adUseClient
rs.Open a, conn
If rs.RecordCount > 0 Then
Form_main.CrystalReport.Formulas(6) = "ProJef = '" & rs(0) & " " & rs(1) & " " & rs(2) & "'"
End If
rs.Close

Form_main.CrystalReport.WindowTitle = "Panorama de Curso - " & cb_agno.Text
Form_main.CrystalReport.Formulas(2) = "Titulo = 'PANORAMA DE CURSO " & Cmd_Per.Text & " " & val(cb_agno.Text) & "'"
Form_main.CrystalReport.Formulas(3) = "Curso = '" & Me.Cmb_Grado & " " & Me.Cmb_Let_Cur & "'"
Form_main.CrystalReport.Formulas(4) = "TipEns = '" & Me.Cmb_Cod_ens & "'"
Form_main.CrystalReport.Formulas(5) = "Hora = '" & Time() & "'"
Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\pan_cur.rpt"
Form_main.CrystalReport.DataFiles(0) = DirAplicacion & "\GesTemp.mdb"
Form_main.CrystalReport.Action = 1
Call LimpiaFormulas(Form_main.CrystalReport, 30)
'******************************************
Exit Sub
controler:
    MsgBox Err.Description & vbCrLf & Err.Source, vbCritical, "ERROR " & Err.Number
End Sub

Public Sub llena_combo_anno()
    Dim I As Integer
    For I = 2004 To Year(Date)
        cb_agno.AddItem I
    Next I
    cb_agno.Text = Year(Date)
End Sub
