VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Begin VB.Form Form_Notas_Talleres 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Notas de los Talleres"
   ClientHeight    =   7485
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   17520
   Icon            =   "Form_Notas_Talleres.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7485
   ScaleWidth      =   17520
   Begin VB.TextBox Text1 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   1440
      TabIndex        =   28
      Text            =   "Text1"
      Top             =   360
      Visible         =   0   'False
      Width           =   615
   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          =   1035
      Left            =   120
      TabIndex        =   7
      Top             =   120
      Width           =   7635
      Begin VB.CheckBox Check_Letra 
         Caption         =   "Check1"
         Height          =   195
         Left            =   6360
         TabIndex        =   24
         Top             =   600
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   255
      End
      Begin MSComctlLib.ImageCombo IC_Agno 
         Height          =   345
         Left            =   2040
         TabIndex        =   23
         Top             =   240
         Width           =   3255
         _ExtentX        =   5741
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Text            =   "ImageCombo4"
      End
      Begin MSComctlLib.ImageCombo IC_Ensenanza 
         Height          =   345
         Left            =   2040
         TabIndex        =   22
         Top             =   600
         Width           =   3255
         _ExtentX        =   5741
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Text            =   "ImageCombo3"
      End
      Begin MSComctlLib.ImageCombo IC_Nivel 
         Height          =   345
         Left            =   6600
         TabIndex        =   21
         Top             =   240
         Width           =   855
         _ExtentX        =   1508
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Text            =   "ImageCombo2"
      End
      Begin MSComctlLib.ImageCombo IC_Letra 
         Height          =   345
         Left            =   6600
         TabIndex        =   20
         Top             =   600
         Width           =   855
         _ExtentX        =   1508
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Text            =   "ImageCombo1"
      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            =   5520
         TabIndex        =   11
         Top             =   600
         Width           =   1455
      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            =   5520
         TabIndex        =   10
         Top             =   240
         Width           =   615
      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            =   240
         TabIndex        =   9
         Top             =   720
         Width           =   1455
      End
      Begin VB.Label Label7 
         Caption         =   "Año Escolar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   8
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Taller"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1035
      Left            =   7920
      TabIndex        =   4
      Top             =   120
      Width           =   5175
      Begin VB.ComboBox cb_taller 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1440
         TabIndex        =   26
         Top             =   600
         Width           =   3495
      End
      Begin VB.ComboBox cb_tipo 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1440
         TabIndex        =   25
         Top             =   240
         Width           =   3495
      End
      Begin VB.Label Label3 
         Caption         =   "Tipo de Taller"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   240
         TabIndex        =   6
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label4 
         Caption         =   "Taller"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   240
         TabIndex        =   5
         Top             =   720
         Width           =   855
      End
   End
   Begin VB.CommandButton Btn_Ace_Not 
      Caption         =   "Guardar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   13560
      Picture         =   "Form_Notas_Talleres.frx":2A8B2
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   240
      Width           =   1155
   End
   Begin VB.CommandButton Btn_Can_Not 
      Caption         =   "Cancelar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   16200
      Picture         =   "Form_Notas_Talleres.frx":2AD61
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   240
      Width           =   1155
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   6015
      Left            =   120
      TabIndex        =   19
      Top             =   1320
      Width           =   17295
      _ExtentX        =   30506
      _ExtentY        =   10610
      _Version        =   393216
      Cols            =   3
      ForeColorSel    =   16777215
      Enabled         =   -1  'True
      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.CommandButton cmd_limpiar 
      Caption         =   "Limpiar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   14880
      Picture         =   "Form_Notas_Talleres.frx":2B0C9
      Style           =   1  'Graphical
      TabIndex        =   27
      Top             =   240
      Width           =   1155
   End
   Begin VB.ComboBox Cmd_Per 
      Height          =   315
      Left            =   1080
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   5160
      Visible         =   0   'False
      Width           =   2295
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   255
      Left            =   7920
      TabIndex        =   1
      Top             =   5160
      Visible         =   0   'False
      Width           =   1455
   End
   Begin VB.Label Label5 
      Caption         =   "Promedio más alto :"
      Height          =   255
      Left            =   5760
      TabIndex        =   18
      Top             =   5160
      Width           =   1455
   End
   Begin VB.Label Lb1 
      Caption         =   "Promedio más bajo :"
      Height          =   255
      Left            =   3480
      TabIndex        =   17
      Top             =   5160
      Width           =   1455
   End
   Begin VB.Label Lb2 
      Caption         =   "Promedio general :"
      Height          =   255
      Left            =   9600
      TabIndex        =   16
      Top             =   5160
      Width           =   1335
   End
   Begin VB.Label LbPromH 
      Caption         =   "0,0"
      Height          =   255
      Left            =   7200
      TabIndex        =   15
      Top             =   5160
      Width           =   375
   End
   Begin VB.Label LbPromL 
      Caption         =   "0,0"
      Height          =   255
      Left            =   5040
      TabIndex        =   14
      Top             =   5160
      Width           =   375
   End
   Begin VB.Label LbPromG 
      Caption         =   "0,0"
      Height          =   255
      Left            =   11040
      TabIndex        =   13
      Top             =   5160
      Width           =   375
   End
   Begin VB.Label Label6 
      Caption         =   "Período"
      Height          =   255
      Left            =   240
      TabIndex        =   12
      Top             =   5160
      Visible         =   0   'False
      Width           =   735
   End
End
Attribute VB_Name = "Form_Notas_Talleres"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Btn_Ace_Not_Click()
On Error GoTo Controlerror
    Dim i, j, p1, p2, nf As Integer
    Dim tipo_taller, cod_taller, notas1, notas2 As String
    Dim var_sql As String
    Dim tot_notas As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    'Dim var_sql As String
    
    var_sql = "SELECT notas_eva FROM EVALUACIONES ORDER BY COD_EVA"
    objRS.Open var_sql, conn
    tot_notas = objRS("notas_eva")
    objRS.Close
    
    var_sql = "SELECT * FROM tipo_talleres" _
            & " where desc_tipo = '" & cb_tipo.Text & "'"
    objRS.Open var_sql, conn
    tipo_taller = objRS("cod_tipo")
    objRS.Close
    
    var_sql = "SELECT * FROM talleres" _
            & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and nom_tall =  '" & cb_taller.Text & "' and num_gra = " & IC_Nivel.Text & " and tipo_tall = " & tipo_taller
    objRS.Open var_sql, conn
    cod_taller = objRS("cod_tall")
    objRS.Close
    
    For i = 1 To MSFlexGrid1.Rows - 1
    
        notas1 = ""
        For j = 3 To (tot_notas + 2)
            If Mid(MSFlexGrid1.TextMatrix(i, j), 3, 1) = "" Or MSFlexGrid1.TextMatrix(i, j) = "" Or Mid(MSFlexGrid1.TextMatrix(i, j), 1, 1) < 1 Or Mid(MSFlexGrid1.TextMatrix(i, j), 1, 1) > 7 Then
                notas1 = notas1 & "  "
            Else
                notas1 = notas1 & Mid(MSFlexGrid1.TextMatrix(i, j), 1, 1) & Mid(MSFlexGrid1.TextMatrix(i, j), 3, 1)
            End If
        Next j
        
        notas2 = ""
        For j = (5 + tot_notas) To ((tot_notas * 2) + 4)
            If Mid(MSFlexGrid1.TextMatrix(i, j), 3, 1) = "" Or MSFlexGrid1.TextMatrix(i, j) = "" Or Mid(MSFlexGrid1.TextMatrix(i, j), 1, 1) < 1 Or Mid(MSFlexGrid1.TextMatrix(i, j), 1, 1) > 7 Then
                notas2 = notas2 & "  "
            Else
                notas2 = notas2 & Mid(MSFlexGrid1.TextMatrix(i, j), 1, 1) & Mid(MSFlexGrid1.TextMatrix(i, j), 3, 1)
            End If
        Next j
        
        var_sql = "replace into notas_talleres(cod_ens,num_gra,let_cur,cod_tall,ci_alu,num_per," _
                & "nota,tipo_tall,agno)" _
                & " values('" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                & "'," & IC_Nivel.Text & ",'" & IC_Letra.Text _
                & "','" & cod_taller & "','" & MSFlexGrid1.TextMatrix(i, 0) & "',1,'" & notas1 & "','" & tipo_taller & "'," & IC_Agno.Text & ")"
        conn.Execute var_sql
        
        var_sql = "replace into notas_talleres(cod_ens,num_gra,let_cur,cod_tall,ci_alu,num_per," _
                & "nota,tipo_tall,agno)" _
                & " values('" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                & "'," & IC_Nivel.Text & ",'" & IC_Letra.Text _
                & "','" & cod_taller & "','" & MSFlexGrid1.TextMatrix(i, 0) & "',2,'" & notas2 & "','" & tipo_taller & "'," & IC_Agno.Text & ")"
        conn.Execute var_sql
        
        If MSFlexGrid1.TextMatrix(i, tot_notas + 3) <> "" And Mid(MSFlexGrid1.TextMatrix(i, tot_notas + 3), 1, 1) <> "" And Mid(MSFlexGrid1.TextMatrix(i, tot_notas + 3), 3, 1) <> "" Then
            p1 = CInt(Mid(MSFlexGrid1.TextMatrix(i, tot_notas + 3), 1, 1) & Mid(MSFlexGrid1.TextMatrix(i, tot_notas + 3), 3, 1))
        Else
            p1 = 0
        End If
        If MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 5) <> "" And Mid(MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 5), 1, 1) <> "" And Mid(MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 5), 3, 1) <> "" Then
            p2 = CInt(Mid(MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 5), 1, 1) & Mid(MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 5), 3, 1))
        Else
            p2 = 0
        End If
        If MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 6) <> "" And Mid(MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 6), 1, 1) <> "" And Mid(MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 6), 3, 1) <> "" Then
            p3 = CInt(Mid(MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 6), 1, 1) & Mid(MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 6), 3, 1))
        Else
            p3 = 0
        End If
        
        var_sql = "replace into promedios_talleres(ci_alu,cod_ens,num_gra,let_cur,cod_tall," _
                & "p1,p2,nf,tipo_tall,agno)" _
                & " values('" & MSFlexGrid1.TextMatrix(i, 0) & "','" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                & "'," & IC_Nivel.Text & ",'" & IC_Letra.Text & "','" & cod_taller _
                & "'," & p1 _
                & "," & p2 _
                & "," & p3 _
                & ",'" & tipo_taller & "'," & IC_Agno.Text & ")"
        conn.Execute var_sql
    Next i
    

    
    
Controlerror:
    If Err.Number = 0 Then
    Else
        If Err.Number = 3021 Then
            MsgBox "Faltan campos por seleccionar.", vbCritical, "Campos Vacios"
            Call cmd_limpiar_Click
        Else
            MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbCritical, "ALERTA DE ANOMALÍA"
        End If
    End If
End Sub

Private Sub Btn_Can_Not_Click()
    Unload Me
End Sub

Private Sub cb_taller_Click()
On Error GoTo Controlerror
    Dim cargo As String
    Dim tot_notas As Integer
    Dim cod_tall As String
    Dim var_sql As String
    Dim rut_prof As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
'    var_sql = "select * from alu_x_cur" _
'            & " where agno = " & IC_Agno.Text & " and cod_ens = '" _
'            & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "'" _
'            & " and let_cur = '" & IC_Letra.Text _
'            & "' and activo_alu = 'SI' and num_gra = " & IC_Nivel.Text

    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
    & Nom_usu_ses & "'"
    objRS.Open var_sql, conn
    rut_prof = objRS("rut_usu")
    cargo = objRS("cargo_usu")
    objRS.Close
        
    If cb_tipo.Text = "TALLERES CURRICULARES" Then
        var_sql = "select * from talleres" _
                & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                & "' and num_gra = " & IC_Nivel.Text _
                & " and tipo_tall = 1 and nom_tall = '" & cb_taller.Text & "'"
        objRS.Open var_sql, conn
        cod_tall = objRS("cod_tall")
        objRS.Close
        If cargo = "DOCENTE" Then
        var_sql = "select axc.ci_alu,concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as 'nombre'" _
                & " from alu_x_cur axc,postulantes p,tall_x_cur_prof tcp,matriculas m" _
                & " where axc.agno = m.anno_mat and axc.ci_alu = m.ci_alu and axc.activo_alu = m.activo_alu" _
                & " and axc.agno = " & IC_Agno.Text & " and axc.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "'" _
                & " and axc.let_cur = '" & IC_Letra.Text & "' and axc.activo_alu = 'SI' and axc.num_gra = " & IC_Nivel.Text _
                & " and axc.ci_alu = p.ci_alu" _
                & " and axc.cod_ens = tcp.cod_ens and axc.num_gra = tcp.num_gra and" _
                & " axc.let_cur = tcp.let_cur and axc.agno = tcp.agno and tcp.rut_prof = '" & rut_prof & "'" _
                & " and cod_tall = '" & cod_tall & "' and tipo_tall = 1" _
                & " order by m.orden_libro,axc.fec_ing_curso, m.num_mat, p.ape_pat_alu, p.ape_mat_alu, p.nom_alu"
        objRS.Open var_sql, conn
        Else
        var_sql = "select axc.ci_alu,concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as 'nombre'" _
                & " from alu_x_cur axc,postulantes p,matriculas m" _
                & " where axc.agno = m.anno_mat and axc.ci_alu = m.ci_alu and axc.activo_alu = m.activo_alu and axc.agno = " & IC_Agno.Text & " and axc.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "'" _
                & " and axc.let_cur = '" & IC_Letra.Text & "' and axc.activo_alu = 'SI' and axc.num_gra = " & IC_Nivel.Text _
                & " and axc.ci_alu = p.ci_alu" _
                & " order by m.orden_libro,axc.fec_ing_curso, m.num_mat, p.ape_pat_alu, p.ape_mat_alu, p.nom_alu"
        objRS.Open var_sql, conn
        End If
    Else
        var_sql = "select * from talleres" _
                & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                & "' and num_gra = " & IC_Nivel.Text _
                & " and tipo_tall = 2 and nom_tall = '" & cb_taller.Text & "'"
        objRS.Open var_sql, conn
        cod_tall = objRS("cod_tall")
        objRS.Close
        If cargo = "DOCENTE" Then
        var_sql = "select axc.ci_alu,concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as 'nombre'" _
                & " from alu_x_cur axc,postulantes p,alumnos_talleres at,tall_x_cur_prof tcp,matriculas m" _
                & " where axc.agno = m.anno_mat and axc.ci_alu = m.ci_alu and axc.activo_alu = m.activo_alu and axc.agno = " & IC_Agno.Text & " and axc.cod_ens = '" _
                & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' and axc.let_cur = '" _
                & IC_Letra.Text & "' and m.activo_alu = 'SI' and axc.num_gra = " & IC_Nivel.Text _
                & " and axc.ci_alu = p.ci_alu" _
                & " and axc.ci_alu = at.ci_alu and axc.cod_ens = at.cod_ens " _
                & " and axc.num_gra = at.numgra and axc.let_cur = at.let_cur and axc.agno = at.agno" _
                & " and at.cod_tall = '" & cod_tall & "' and tcp.tipo_tall = 2" _
                & " And axc.Cod_Ens = tcp.Cod_Ens And axc.Num_Gra = tcp.Num_Gra And" _
                & " axc.Let_Cur = tcp.Let_Cur" _
                & " and axc.agno = tcp.agno " _
                & " and tcp.cod_tall = '" & cod_tall & "' order by m.orden_libro,axc.fec_ing_curso, m.num_mat, p.ape_pat_alu, p.ape_mat_alu, p.nom_alu"
        objRS.Open var_sql, conn
        Else
        var_sql = "select axc.ci_alu,concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as 'nombre'" _
                & " from alu_x_cur axc,postulantes p,alumnos_talleres at,matriculas m" _
                & " where axc.agno = m.anno_mat and axc.ci_alu = m.ci_alu and axc.activo_alu = m.activo_alu and axc.agno = " & IC_Agno.Text & " and axc.cod_ens = '" _
                & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' and axc.let_cur = '" _
                & IC_Letra.Text & "' and m.activo_alu = 'SI' and axc.num_gra = " & IC_Nivel.Text _
                & " and axc.ci_alu = p.ci_alu" _
                & " and axc.ci_alu = at.ci_alu and axc.cod_ens = at.cod_ens " _
                & " and axc.num_gra = at.numgra and axc.let_cur = at.let_cur and axc.agno = at.agno" _
                & " and at.cod_tall = '" & cod_tall & "' and at.tipo_tall = 2" _
                & " order by m.orden_libro,axc.fec_ing_curso, m.num_mat, p.ape_pat_alu, p.ape_mat_alu, p.nom_alu"
        objRS.Open var_sql, conn
        End If
    End If
    
    MSFlexGrid1.Rows = 2
    MSFlexGrid1.Cols = 2
    MSFlexGrid1.ColWidth(1) = 4000
    MSFlexGrid1.ColWidth(0) = 0
    While Not objRS.EOF
        MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
        MSFlexGrid1.Col = 0
        MSFlexGrid1.Text = objRS("ci_alu")
        MSFlexGrid1.Col = 1
        MSFlexGrid1.Text = objRS("ci_alu") & " - " & objRS("nombre")
        MSFlexGrid1.CellAlignment = flexAlignLeftCenter
        objRS.MoveNext
        MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
    Wend
    MSFlexGrid1.Rows = MSFlexGrid1.Rows - 1
    objRS.Close
    var_sql = "SELECT notas_eva FROM EVALUACIONES ORDER BY COD_EVA"
    objRS.Open var_sql, conn
    tot_notas = objRS("notas_eva")
    objRS.Close
    'tot_notas = 12
    MSFlexGrid1.Cols = (tot_notas * 2) + 7
    MSFlexGrid1.ColWidth(2) = 100
    MSFlexGrid1.ColWidth(3 + tot_notas) = 650
    'MSFlexGrid1.ColWidth(4 + tot_notas) = 650
    MSFlexGrid1.ColWidth(4 + tot_notas) = 100
    MSFlexGrid1.ColWidth(5 + (tot_notas * 2)) = 650
    MSFlexGrid1.ColWidth(6 + (tot_notas * 2)) = 650
'    MSFlexGrid1.ColWidth(7 + (tot_notas * 2)) = 650
    MSFlexGrid1.Row = 0
    MSFlexGrid1.Col = 1
    MSFlexGrid1.Text = "Alumnos"
    MSFlexGrid1.Col = (3 + tot_notas)
    MSFlexGrid1.Text = "Prom."
'    MSFlexGrid1.Col = (4 + tot_notas)
'    MSFlexGrid1.Text = "P. Per."
    MSFlexGrid1.Col = (5 + (tot_notas * 2))
    MSFlexGrid1.Text = "Prom."
'    MSFlexGrid1.Col = (7 + (tot_notas * 2))
'    MSFlexGrid1.Text = "P. Per."
    MSFlexGrid1.Col = (6 + (tot_notas * 2))
    MSFlexGrid1.Text = "P. Gen."
    
    'MsgBox (3 + (tot_notas * 2))
    For i = 3 To (tot_notas + 2)
        MSFlexGrid1.Col = i
        MSFlexGrid1.Text = (i - 2)
        MSFlexGrid1.Col = (i + 2 + tot_notas)
        MSFlexGrid1.Text = (i - 2)
        MSFlexGrid1.ColWidth(i) = 450
        MSFlexGrid1.ColWidth(i + 2 + tot_notas) = 450
    Next i
    llena_notas
    Frame1.Enabled = False
    Frame2.Enabled = False
    'MSFlexGrid1_GotFocus
    
    'Calculo promedio en la carga de formulario primer semestre
    var_sql = "SELECT notas_eva FROM EVALUACIONES ORDER BY COD_EVA"
    objRS.Open var_sql, conn
    tot_notas = objRS("notas_eva")
    objRS.Close
    For j = 1 To MSFlexGrid1.Rows - 1
    suma = 0
    cont = 0
    For i = 3 To (3 + (tot_notas - 1))
      If val(MSFlexGrid1.TextMatrix(j, i)) <> 0 Then
        suma = suma + CInt(Mid(MSFlexGrid1.TextMatrix(j, i), 1, 1) & Mid(MSFlexGrid1.TextMatrix(j, i), 3, 1))
        cont = cont + 1
      End If
    Next i

    If cont <> 0 Then
        'MSFlexGrid1.TextMatrix(j, tot_notas + 3) = Left(suma / cont, 2)
        MSFlexGrid1.TextMatrix(j, tot_notas + 3) = Mid(Left(suma / cont, 2), 1, 1) & "." & Mid(Left(suma / cont, 2), 2, 1)
    End If
    Next j
    
    
    'Calculo promedio en la carga de formulario segundo semestre
    For j = 1 To MSFlexGrid1.Rows - 1
    suma = 0
    cont = 0
    For i = (tot_notas + 5) To (4 + (tot_notas * 2))
      If val(MSFlexGrid1.TextMatrix(j, i)) <> 0 Then
        suma = suma + CInt(Mid(MSFlexGrid1.TextMatrix(j, i), 1, 1) & Mid(MSFlexGrid1.TextMatrix(j, i), 3, 1))
        cont = cont + 1
      End If
    Next i

    If cont <> 0 Then
        'MSFlexGrid1.TextMatrix(j, tot_notas + 3) = Left(suma / cont, 2)
        MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 5) = Mid(Left(suma / cont, 2), 1, 1) & "." & Mid(Left(suma / cont, 2), 2, 1)
    End If
    Next j
    
    For j = 1 To MSFlexGrid1.Rows - 1
        If val(MSFlexGrid1.TextMatrix(j, tot_notas + 3)) <> 0 And val(MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 5)) <> 0 Then
            MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 6) = Replace(Format((val(MSFlexGrid1.TextMatrix(j, tot_notas + 3)) + val(MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 5))) / 2, "#0.0"), ",", ".")
        End If
        
        If val(MSFlexGrid1.TextMatrix(j, tot_notas + 3)) <> 0 And val(MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 5)) = 0 Then
            MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 6) = val(MSFlexGrid1.TextMatrix(j, tot_notas + 3))
        End If
        
        If val(MSFlexGrid1.TextMatrix(j, tot_notas + 3)) = 0 And val(MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 5)) <> 0 Then
            MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 6) = val(MSFlexGrid1.TextMatrix(j, (tot_notas * 2) + 5))
        End If
        
    Next j
    
           
    
Controlerror:
    If Err.Number = 0 Then
    Else
        If Err.Number = 3021 Then
            MsgBox "Faltan campos por seleccionar.", vbCritical, "Campos Vacios"
            Call cmd_limpiar_Click
        Else
            MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbCritical, "ALERTA DE ANOMALÍA"
        End If
    End If
    
End Sub

Private Sub cb_tipo_Click()
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    
    RutUsuario = DevuelveCampo("usuarios", "", "rut_usu", "aut_nombre_usuario='" & Nom_usu_ses & "'", conn)
    
    If CodPerfil = "#PJE#" Then
'    rs.Open "SELECT DISTINCT s.nom_sec, ap.cod_sec" _
'          & " FROM sectores s, asi_x_cur_prof ap, cursos c" _
'          & " WHERE S.COD_SEC = AP.COD_SEC AND AP.cod_ens = '" & CodModalidad _
'          & "' and AP.num_gra = '" & Me.Cmb_Grado & "' and AP.let_cur ='" _
'          & Me.Cmb_let_cur & "' and ap.agno = " & cmb_agno.Text _
'          & " and ap.agno = c.agno and ap.num_gra = c.num_gra and" _
'          & " ap.let_cur = c.let_cur and ap.cod_ens = c.cod_ens and" _
'          & " c.agno = " & cmb_agno.Text & " and c.rut_prof = '" & RutUsuario & "' union " _
'          & "SELECT DISTINCT s.NOM_SEC, ap.COD_SEC FROM SECTORES S, asi_x_cur_prof AP WHERE S.COD_SEC = AP.COD_SEC AND AP.cod_ens = '" & CodModalidad & "' and AP.num_gra = '" & Me.Cmb_Grado & "' and AP.let_cur ='" & Me.Cmb_let_cur & "' and AP.rut_prof ='" & RutUsuario & "' and ap.agno = " & cmb_agno.Text, conn

        var_sql = "SELECT rut_prof FROM cursos" _
                & " WHERE cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND num_gra = " & IC_Nivel.Text & " AND let_cur = '" & IC_Letra.Text & "' AND rut_prof = '" & RutUsuario & "' AND agno = " & IC_Agno.Text
        
        jefe = DevuelveCampo("cursos", "", "rut_prof", " cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND num_gra = " & IC_Nivel.Text & " AND let_cur = '" & IC_Letra.Text & "' AND rut_prof = '" & RutUsuario & "' AND agno = " & IC_Agno.Text, conn)
        If Len(jefe) > 6 Then
        var_sql = "SELECT nom_tall FROM talleres t,tall_x_cur_prof p" _
                & " WHERE t.cod_ens = p.cod_ens AND t.num_gra = p.num_gra AND t.cod_tall = p.cod_tall AND agno = " & IC_Agno.Text _
                & " AND t.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND t.num_gra = " & IC_Nivel.Text _
                & " AND let_cur = '" & IC_Letra.Text & "'" _
                & " AND t.tipo_tall = (SELECT cod_tipo FROM tipo_talleres WHERE desc_tipo = '" & cb_tipo.Text & "')"
        Else
            var_sql = "SELECT nom_tall FROM talleres t,tall_x_cur_prof p" _
                & " WHERE t.cod_ens = p.cod_ens AND t.num_gra = p.num_gra AND t.cod_tall = p.cod_tall AND agno = " & IC_Agno.Text _
                & " AND t.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND t.num_gra = " & IC_Nivel.Text _
                & " AND rut_prof = '" & RutUsuario & "' AND let_cur = '" & IC_Letra.Text & "'" _
                & " AND t.tipo_tall = (SELECT cod_tipo FROM tipo_talleres WHERE desc_tipo = '" & cb_tipo.Text & "')"
        End If
    Else
    
        If CodPerfil = "#UTP#" Or CodPerfil = "#ADM#" Or CodPerfil = "#GES03#" Then
                var_sql = "SELECT nom_tall" _
            & " From talleres" _
            & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " & IC_Nivel.Text & " and tipo_tall = (" _
            & "SELECT cod_tipo" _
            & " FROM tipo_talleres where desc_tipo = '" & cb_tipo.Text & "')"
'            rs.Open "SELECT DISTINCT s.nom_sec, ap.cod_sec FROM sectores s, asi_x_cur_prof ap WHERE S.COD_SEC = AP.COD_SEC AND AP.cod_ens = '" & CodModalidad & "' and AP.num_gra = '" & Me.Cmb_Grado & "' and AP.let_cur ='" & Me.Cmb_let_cur & "' and ap.agno = " & cmb_agno.Text, conn
        Else
            var_sql = "SELECT nom_tall FROM talleres t,tall_x_cur_prof p" _
                & " WHERE t.cod_ens = p.cod_ens AND t.num_gra = p.num_gra AND t.cod_tall = p.cod_tall AND agno = " & IC_Agno.Text _
                & " AND t.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND t.num_gra = " & IC_Nivel.Text _
                & " AND rut_prof = '" & RutUsuario & "' AND let_cur = '" & IC_Letra.Text & "'" _
                & " AND t.tipo_tall = (SELECT cod_tipo FROM tipo_talleres WHERE desc_tipo = '" & cb_tipo.Text & "')"
'            rs.Open "SELECT DISTINCT s.NOM_SEC, ap.COD_SEC FROM SECTORES S, asi_x_cur_prof AP WHERE S.COD_SEC = AP.COD_SEC AND AP.cod_ens = '" & CodModalidad & "' and AP.num_gra = '" & Me.Cmb_Grado & "' and AP.let_cur ='" & Me.Cmb_let_cur & "' and AP.rut_prof ='" & RutUsuario & "' and ap.agno = " & cmb_agno.Text, conn
        End If
    End If
    
    

    cb_taller.Clear
    objRS.Open var_sql, conn
    While Not objRS.EOF
        cb_taller.AddItem objRS("nom_tall")
        objRS.MoveNext
    Wend
    objRS.Close
End Sub

Private Sub cmd_limpiar_Click()
    Frame1.Enabled = True
    Frame2.Enabled = True
    MSFlexGrid1.Rows = 2
    MSFlexGrid1.Clear
    cb_taller.Text = ""
    cb_tipo.Text = ""
    Text1.Visible = False
End Sub

Private Sub Form_Load()
    Call Set_IC_Agno
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    var_sql = "select desc_tipo from tipo_talleres"
    objRS.Open var_sql, conn
    cb_tipo.Clear
    While Not objRS.EOF
        cb_tipo.AddItem objRS("desc_tipo")
        objRS.MoveNext
    Wend
    objRS.Close
End Sub

Private Sub IC_Agno_Click()
     IC_Ensenanza.Enabled = True
     Set_IC_Ensenanza
End Sub

Private Sub IC_Ensenanza_Click()
    IC_Nivel.Enabled = True
    Call Set_IC_Nivel
End Sub



Private Sub IC_Nivel_Click()
     IC_Letra.Enabled = True
    Call Set_IC_Letra
End Sub

Private Sub Set_IC_Agno()
    Dim agno As Integer
    
  '  agno = IIf(Year(Date) < 2005, 2005, Year(Date))
  '  IC_Agno.ComboItems.Clear
'    For i = 2005 To (Anno)
'        IC_Agno.ComboItems.Add i, , str(i + 2004)
'    Next i
'    Set IC_Agno.SelectedItem = IC_Agno.ComboItems.Item(i - 1)
'    ErrorStatus = False
    
    agno = IIf(Year(Date) < 2005, 2005, Year(Date))
    IC_Agno.ComboItems.Clear
    For i = 1 To (agno - 2004)
        IC_Agno.ComboItems.Add i, , str(i + 2004)
    Next i
    Set IC_Agno.SelectedItem = IC_Agno.ComboItems.Item(i - 1)
    ErrorStatus = False
    
    ' Llenar combo enseñanza
    IC_Ensenanza.Enabled = True
    IC_Nivel.Enabled = False
    IC_Letra.Enabled = False
    Call Set_IC_Ensenanza
End Sub

Private Sub Set_IC_Ensenanza()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    
    QRY = "SELECT DISTINCT m.cod_ens, ce.des_ens FROM matriculas as m, codigos_ensenanza as ce WHERE m.cod_ens=ce.cod_ens AND m.anno_mat=" & IC_Agno.SelectedItem.Text & " ORDER BY ce.ord_ens;"
    Set REC = New ADODB.Recordset
    REC.Open QRY, conn
    
    IC_Ensenanza.ComboItems.Clear
    If REC.RecordCount > 0 Then
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            IC_Ensenanza.ComboItems.Add i, "K" & Format(REC!Cod_Ens, "000"), REC!des_ens
            REC.MoveNext
        Next i
        Set IC_Ensenanza.SelectedItem = IC_Ensenanza.ComboItems.Item(1)
        ErrorStatus = False
        ' Llenar Siguiente Combo.
        IC_Nivel.Enabled = True
        IC_Letra.Enabled = False
        Call Set_IC_Nivel
    Else
        ErrorStatus = True
        IC_Ensenanza.Enabled = False
        IC_Nivel.Enabled = False
        IC_Letra.Enabled = False
    End If
    REC.Close
End Sub

Private Sub Set_IC_Letra()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    
    'If Check_Letra.Value = 1 Then
        IC_Letra.ComboItems.Clear
        IC_Letra.Text = ""
        QRY = "SELECT DISTINCT m.let_cur FROM alu_x_cur as m WHERE m.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND m.agno=" & Trim(IC_Agno.SelectedItem.Text) & " AND m.num_gra='" & Trim(IC_Nivel.SelectedItem.Text) & "' ORDER BY m.num_gra;"
        Set REC = New ADODB.Recordset
        REC.Open QRY, conn
        If REC.RecordCount > 0 Then
            REC.MoveFirst
            For i = 1 To REC.RecordCount
                IC_Letra.ComboItems.Add i, , REC!Let_Cur
                REC.MoveNext
            Next i
            Set IC_Letra.SelectedItem = IC_Letra.ComboItems.Item(1)
            ErrorStatus = False
            ' Llenar Siguiente Combo.
        Else
            ErrorStatus = True
            Check_Letra.Value = 0
            IC_Letra.Enabled = False
        End If
        REC.Close
'    Else
'        ErrorStatus = False
'        IC_Letra.Enabled = False
'    End If
End Sub

Private Sub Set_IC_Nivel()
    Dim REC As ADODB.Recordset
    Dim QRY As String

    QRY = "SELECT DISTINCT m.num_gra FROM matriculas as m WHERE m.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND m.anno_mat=" & IC_Agno.SelectedItem.Text & " ORDER BY m.num_gra;"
    Set REC = New ADODB.Recordset
    REC.Open QRY, conn
    
    IC_Nivel.ComboItems.Clear
    If REC.RecordCount > 0 Then
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            IC_Nivel.ComboItems.Add i, , str(REC!Num_Gra)
            REC.MoveNext
        Next i
        Set IC_Nivel.SelectedItem = IC_Nivel.ComboItems.Item(1)
        ErrorStatus = False
        ' Llenar Siguiente Combo.
        If Check_Letra.Value = 1 Then
            IC_Letra.Enabled = True
            Call Set_IC_Letra
        End If
    Else
        ErrorStatus = True
        IC_Nivel.Enabled = False
        IC_Letra.Enabled = False
    End If
    REC.Close
End Sub

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
  GridEdit KeyAscii
End Sub

Sub GridEdit(KeyAscii As Integer)
  'emplear la fuente correcta
  On Error Resume Next
  Text1.FontName = MSFlexGrid1.FontName
  Text1.FontSize = MSFlexGrid1.FontSize
  Select Case KeyAscii
    Case 0 To Asc(" ")
         Text1 = MSFlexGrid1.Text
         Text1.SelStart = 1000
    Case Else
         Text1 = Chr(KeyAscii)
         Text1.SelStart = 1
  End Select
  'posicionar el textbox
  Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
  Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
  Text1.Width = MSFlexGrid1.CellWidth
  Text1.Height = MSFlexGrid1.CellHeight
  Text1.Visible = True
  Text1.SetFocus
  
End Sub

Private Sub MSFlexGrid1_Click()
    Dim tot_notas As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    If MSFlexGrid1.Rows = 1 Then Exit Sub
    If MSFlexGrid1.Rows = 2 And MSFlexGrid1.TextMatrix(1, 1) = "" Then Exit Sub
    var_sql = "SELECT notas_eva FROM EVALUACIONES ORDER BY COD_EVA"
    objRS.Open var_sql, conn
    tot_notas = objRS("notas_eva")
    objRS.Close
    If MSFlexGrid1.Col < 3 Then Exit Sub
    If (MSFlexGrid1.Col > (tot_notas + 2)) And (MSFlexGrid1.Col < (tot_notas + 5)) Then Exit Sub
    If (MSFlexGrid1.Col > ((tot_notas * 2) + 4)) Then Exit Sub

    GridEdit Asc(" ")
End Sub

'agrega .0
Private Sub MSFlexGrid1_LeaveCell()

If Len(Text1.Text) = 1 Then
        Text1.Text = Text1.Text & ".0"
Else
  
  If Len(Text1.Text) = 2 And Text1.Text <> "  " Then
        n1 = Mid(Text1.Text, 1, 1)
        d1 = Mid(Text1.Text, 2, 1)
        
        If d1 = "." Or d1 = "," Then
            Text1.Text = n1 & "." & "0"
        
        Else
            Text1.Text = n1 & "." & d1
        End If
  Else
  
  If Len(Text1.Text) = 3 Then
        n1 = Mid(Text1.Text, 1, 1)
        d1 = Mid(Text1.Text, 2, 1)
        d2 = Mid(Text1.Text, 3, 1)
        
        If d1 = "." Or d1 = "," Then
            If d2 = "." Or d2 = "," Then
                Text1.Text = n1 & "." & "0"
            Else
                Text1.Text = n1 & "." & d2
            End If
        Else
             Text1.Text = n1 & "." & d1
        End If
  End If
  
 End If
End If
  
  If Text1.Visible Then
     MSFlexGrid1 = Text1
     Text1.Visible = False
     'valida_grilla
  End If
  
End Sub

Private Sub MSFlexGrid1_GotFocus()
  Dim suma, cont As Integer
  Dim i As Integer
  Dim tot_notas As Integer
  Dim objRS As ADODB.Recordset
  Set objRS = New ADODB.Recordset
  Dim var_sql As String
  If Len(Text1.Text) = 1 Then
        Text1.Text = Text1.Text & ".0"
  End If
  If Text1.Visible Then
    MSFlexGrid1 = Text1
    Text1.Visible = False
  End If
  var_sql = "SELECT notas_eva FROM EVALUACIONES ORDER BY COD_EVA"
  objRS.Open var_sql, conn
  tot_notas = objRS("notas_eva")
  objRS.Close
  suma = 0
  cont = 0
  For i = 3 To (3 + (tot_notas - 1))
      If val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, i)) <> 0 Then
        suma = suma + CInt(Mid(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, i), 1, 1) & Mid(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, i), 3, 1))
        cont = cont + 1
      End If
  Next i
  If cont <> 0 Then
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, tot_notas + 3) = Left(suma / cont, 2)
  End If
End Sub



Private Sub MSFlexGrid1_Scroll()
    Text1.Visible = False
End Sub

Private Sub Text1_Change()
    Dim texto As String
    texto = Text1.Text
    
    If Len(texto) = 0 Then Exit Sub
    
    'si es = a 4 no deja ingresar mas numeros
    If Len(texto) = 4 Then
        Text1.Text = Mid(texto, 1, Len(texto) - 1)
        Text1.SelStart = Len(Text1.Text)
        Exit Sub
    End If
    
    'pregunta por numeros 0-9 o .
    If (Asc(Mid(texto, Len(texto), Len(texto))) > 47 And Asc(Mid(texto, Len(texto), Len(texto))) < 58) Then
    
        If Len(texto) = 1 Then
            If (Asc(Mid(texto, Len(texto), Len(texto))) < 49 Or Asc(Mid(texto, Len(texto), Len(texto))) > 57) Then
                MsgBox "La nota no puede ser menor a 7"
                Text1.Text = ""
                Text1.SelStart = 1
            Else
                If CInt(Mid(texto, 1, 1)) > 7 Then 'pregunta por mayor 7
                    MsgBox "La notas no puede ser mayor a 7"
                    Text1.Text = ""
                End If
            End If
        End If
        
        If Len(texto) = 3 Then
            If (Asc(Mid(texto, Len(texto), Len(texto))) < 48 Or Asc(Mid(texto, Len(texto), Len(texto))) > 57) Then
                MsgBox "La nota no es valida" 'preguntaultimo digito es numero
                Text1.Text = Mid(texto, 1, Len(texto) - 1)
                Text1.SelStart = Len(Text1.Text)
            Else
                If (CInt(val(Mid(texto, 1, 1))) = 7 And CInt(val(Mid(texto, 3, 1))) <> 0) Then
                    MsgBox "La nota no es valida" 'valida nota mayor a 7
                    Text1.Text = Mid(texto, 1, Len(texto) - 1) & "0"
                    Text1.SelStart = Len(Text1.Text)
                End If
            End If
        End If
        
    Else
        If Len(texto) = 1 Then
            GridEdit Asc(" ")
        Else
            Text1.Text = Mid(texto, 1, Len(texto) - 1)
            Text1.SelStart = Len(Text1.Text)
        End If
    End If
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
  Select Case KeyCode
    Case vbKeyEscape
      Text1.Visible = False
      MSFlexGrid1.SetFocus
    Case vbKeyReturn
      MSFlexGrid1.SetFocus
    Case vbKeyDown
      MSFlexGrid1.SetFocus
      DoEvents
      If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then
         MSFlexGrid1.Row = MSFlexGrid1.Row + 1
      End If
    Case vbKeyUp
      MSFlexGrid1.SetFocus
      DoEvents
      If MSFlexGrid1.Row > MSFlexGrid1.FixedRows Then
         MSFlexGrid1.Row = MSFlexGrid1.Row - 1
      End If
  End Select
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
  'suppresión del beep
  'If KeyAscii = vbKeyReturn Then KeyAscii = 0
  
  If KeyAscii = 13 Then
    'Call Text1_LostFocus
    Call MSFlexGrid1_LeaveCell
  Else
    If KeyAscii = vbKeyReturn Then KeyAscii = 0
  End If
  
End Sub

Private Sub Text1_LostFocus()
On Error GoTo Controlerror

  Dim suma, suma1, suma2, cont As Integer
  Dim i, X As Integer
  Dim tot_notas As Integer
  Dim objRS As ADODB.Recordset
  Set objRS = New ADODB.Recordset
  Dim var_sql As String
  
'  If Len(Text1.Text) = 1 Then
'        Text1.Text = Text1.Text & ".0"
'  End If
'  If Text1.Visible Then
'    MSFlexGrid1 = Text1
'    Text1.Visible = False
'  End If

  var_sql = "SELECT notas_eva FROM EVALUACIONES ORDER BY COD_EVA"
  objRS.Open var_sql, conn
  tot_notas = objRS("notas_eva")
  objRS.Close
  For X = 1 To (MSFlexGrid1.Rows - 1)
    suma = 0
    cont = 0
    For i = 3 To (3 + (tot_notas - 1))
        If val(MSFlexGrid1.TextMatrix(X, i)) <> 0 Then
            suma = suma + (CInt(Mid(MSFlexGrid1.TextMatrix(X, i), 1, 1)) * 10) + CInt(Mid(MSFlexGrid1.TextMatrix(X, i), 3, 1))
            cont = cont + 1
        End If
    Next i
    If cont <> 0 Then
        MSFlexGrid1.TextMatrix(X, tot_notas + 3) = Mid(Left(suma / cont, 2), 1, 1) & "." & val(Mid(Left(suma / cont, 2), 2, 1))
    Else
        MSFlexGrid1.TextMatrix(X, tot_notas + 3) = ""
    End If
    
    suma = 0
    cont = 0
    For i = (tot_notas + 5) To (5 + ((tot_notas * 2) - 1))
        If val(MSFlexGrid1.TextMatrix(X, i)) <> 0 Then
            suma = suma + (CInt(Mid(MSFlexGrid1.TextMatrix(X, i), 1, 1)) * 10) + CInt(Mid(MSFlexGrid1.TextMatrix(X, i), 3, 1))
            cont = cont + 1
        End If
    Next i
    If cont <> 0 Then
        MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 5) = Mid(Left(suma / cont, 2), 1, 1) & "." & val(Mid(Left(suma / cont, 2), 2, 1))
    Else
        MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 5) = ""
    End If
    suma1 = 0
    suma2 = 0
    If val(MSFlexGrid1.TextMatrix(X, tot_notas + 3)) <> 0 Then
        suma1 = CInt(Mid(MSFlexGrid1.TextMatrix(X, tot_notas + 3), 1, 1) & Mid(MSFlexGrid1.TextMatrix(X, tot_notas + 3), 3, 1))
    End If
    If val(MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 5)) <> 0 Then
        suma2 = CInt(Mid(MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 5), 1, 1) & Mid(MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 5), 3, 1))
    End If
    If suma1 > 0 And suma2 = 0 Then
        MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 6) = Mid(suma1, 1, 1) & "." & Mid(suma1, 2, 1)
    End If
    If suma1 = 0 And suma2 > 0 Then
        MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 6) = Mid(suma2, 1, 1) & "." & Mid(suma2, 2, 1)
    End If
    If suma1 = 0 And suma2 = 0 Then
        MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 6) = ""
    End If
    If suma1 > 0 And suma2 > 0 Then
        MSFlexGrid1.TextMatrix(X, (tot_notas * 2) + 6) = Mid((suma1 + suma2) / 2, 1, 1) & "." & Mid((suma1 + suma2) / 2, 2, 1)
    End If
  Next X
  
Controlerror:
    If Err.Number = 0 Then
    Else
        If Err.Number = 13 Then
            MsgBox "Hay notas no válidas en la grilla. Revise y agregue los decimales que correspondan para continuar.", vbCritical, "Faltan Decimales"
        Else
            MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbCritical, "ALERTA DE ANOMALÍA"
        End If
    End If
End Sub

Private Sub llena_notas()
On Error GoTo Controlerror
    Dim i, j, tot_notas As Integer
    Dim tipo_taller, cod_taller As String
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    var_sql = "SELECT notas_eva FROM EVALUACIONES ORDER BY COD_EVA"
    objRS.Open var_sql, conn
    tot_notas = objRS("notas_eva")
    objRS.Close
    
    var_sql = "SELECT * FROM tipo_talleres" _
            & " where desc_tipo = '" & cb_tipo.Text & "'"
    objRS.Open var_sql, conn
    tipo_taller = objRS("cod_tipo")
    objRS.Close
    
    var_sql = "SELECT * FROM talleres" _
            & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and nom_tall =  '" & cb_taller.Text & "' and num_gra = " & IC_Nivel.Text & " and tipo_tall = " & tipo_taller
    objRS.Open var_sql, conn
    cod_taller = objRS("cod_tall")
    objRS.Close
    
    var_sql = "select * from notas_talleres" _
            & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " & IC_Nivel.Text _
            & " and let_cur = '" & IC_Letra.Text & "' and cod_tall = '" & cod_taller & "'" _
            & " and num_per = 1 and tipo_tall = " & tipo_taller & " and agno = " & IC_Agno.Text
    objRS.Open var_sql, conn
    While Not objRS.EOF
        For i = 1 To MSFlexGrid1.Rows - 1
            If objRS("ci_alu") = MSFlexGrid1.TextMatrix(i, 0) Then
                For j = 1 To tot_notas
                    If val(Mid(objRS("nota"), (j * 2) - 1, 2)) <> 0 Then
                        MSFlexGrid1.TextMatrix(i, j + 2) = Mid(objRS("nota"), (j * 2) - 1, 1) & "." & Mid(objRS("nota"), (j * 2), 1)
                    End If
                    'MsgBox Mid(objRS("nota"), (j * 2) - 1, j * 2) & j
                Next j
                Exit For
            End If
        Next i
        objRS.MoveNext
    Wend
    objRS.Close
    
    var_sql = "select * from notas_talleres" _
            & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " & IC_Nivel.Text _
            & " and let_cur = '" & IC_Letra.Text & "' and cod_tall = '" & cod_taller & "'" _
            & " and num_per = 2 and tipo_tall = " & tipo_taller & " and agno = " & IC_Agno.Text
    objRS.Open var_sql, conn
    While Not objRS.EOF
        For i = 1 To MSFlexGrid1.Rows - 1
            If objRS("ci_alu") = MSFlexGrid1.TextMatrix(i, 0) Then
                For j = 1 To tot_notas
                    If val(Mid(objRS("nota"), (j * 2) - 1, 2)) <> 0 Then
                        MSFlexGrid1.TextMatrix(i, j + (tot_notas + 4)) = Mid(objRS("nota"), (j * 2) - 1, 1) & "." & Mid(objRS("nota"), (j * 2), 1)
                    End If
                    'MsgBox Mid(objRS("nota"), (j * 2) - 1, j * 2) & j
                Next j
                Exit For
            End If
        Next i
        objRS.MoveNext
    Wend
    objRS.Close
    
    var_sql = "select * from promedios_talleres" _
            & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " & IC_Nivel.Text & " and let_cur = '" & IC_Letra.Text _
            & "' and cod_tall = '" & cod_taller & "' and tipo_tall = '" & tipo_taller & "' and agno = " & IC_Agno.Text
    objRS.Open var_sql, conn
    While Not objRS.EOF
        For i = 1 To MSFlexGrid1.Rows - 1
            If objRS("ci_alu") = MSFlexGrid1.TextMatrix(i, 0) Then
                If val(objRS("p1")) <> 0 Then
                    MSFlexGrid1.TextMatrix(i, tot_notas + 3) = Mid(objRS("p1"), 1, 1) & "." & Mid(objRS("p1"), 2, 1)
                End If
                If val(objRS("p2")) <> 0 Then
                    MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 5) = Mid(objRS("p2"), 1, 1) & "." & Mid(objRS("p2"), 2, 1)
                End If
                If val(objRS("nf")) <> 0 Then
                    MSFlexGrid1.TextMatrix(i, (tot_notas * 2) + 6) = Mid(objRS("nf"), 1, 1) & "." & Mid(objRS("nf"), 2, 1)
                End If
                Exit For
            End If
        Next i
        objRS.MoveNext
    Wend
    objRS.Close
    
Controlerror:
    If Err.Number = 0 Then
    Else
        If Err.Number = 3021 Then
            MsgBox "Faltan campos por seleccionar.", vbCritical, "Campos Vacios"
            Call cmd_limpiar_Click
        Else
            MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbCritical, "ALERTA DE ANOMALÍA"
        End If
    End If
    
End Sub

