Demo entry 6700371

VB

   

Submitted by Yesid on Jan 26, 2018 at 19:45
Language: C++. Code size: 4.1 kB.

Function CONTAR_DiaSem(FInicial As Variant, FFinal As Variant, FDS As Byte, Optional Festivos As Range)

'**********************************************************************************************************************************
'***                                                                                                                            ***
'***    DiaLabSig(FInicial;FFinal;FDS;Festivos)                                                                                 ***
'***                                                                                                                            ***
'***        Finicial:=  Fecha de inicio para el calculo                                                                         ***
'***        FFinal:=    Fecha en donde finaliza el calculo                                                                      ***
'***        FDS         := [0, 1, 2] Tipo de fin de semana                                                                      ***
'***                    0 = Conteo de Festivos                                                                                  ***
'***                    1 = Conteo de Sábados                                                                                   ***
'***                    2 = conteo de Domingos                                                                                  ***
'***        Festivos:= Rango de celdas en donde se encuentran las fechas festivas u otros días no hábiles                       ***
'***                                                                                                                            ***
'**********************************************************************************************************************************

' Convierte fecha en un numero entero
FIni = Application.WorksheetFunction.RoundDown(FInicial, 0)
FFin = Application.WorksheetFunction.RoundDown(FFinal, 0)
 
QD = 0
QR = 0

' **** (0) **************************
If FDS = 0 Then
ConteoFestivos:
        Val_Fest = Application.WorksheetFunction.CountIf(Festivos, FIni + QD) ' Valida si el dia es festivo
        If Val_Fest > 0 Then
            QR = QR + 1
            QD = QD + 1
            If FIni + QD > FFin Then
                GoTo FinalizaConteo:
            Else
                GoTo ConteoFestivos:
            End If
        
        Else
            QD = QD + 1
            If FIni + QD > FFin Then
                GoTo FinalizaConteo:
            Else
                GoTo ConteoFestivos:
            End If
        End If
End If
' **** (1) **************************
If FDS = 1 Then
ConteoSabados:
        Val_FDS = Application.WorksheetFunction.Text(FIni + QD, "DDD") ' Identifica que dia es
        If Val_FDS = "Sat" Then
            QR = QR + 1
            QD = QD + 1
            If FIni + QD > FFin Then
                GoTo FinalizaConteo:
            Else
                GoTo ConteoSabados:
            End If
        
        Else
            QD = QD + 1
            If FIni + QD > FFin Then
                GoTo FinalizaConteo:
            Else
                GoTo ConteoSabados:
            End If
        End If
End If
        
' **** (2) **************************
If FDS = 2 Then
ConteoDomingos:
        Val_FDS = Application.WorksheetFunction.Text(FIni + QD, "DDD") ' Identifica que dia es
        If Val_FDS = "Sun" Then
            QR = QR + 1
            QD = QD + 1
            If FIni + QD > FFin Then
                GoTo FinalizaConteo:
            Else
                GoTo ConteoDomingos:
            End If
        
        Else
            QD = QD + 1
            If FIni + QD > FFin Then
                GoTo FinalizaConteo:
            Else
                GoTo ConteoDomingos:
            End If
        End If
End If

'=========================================================================================================

FinalizaConteo:

CONTAR_DiaSem = QR

End Function

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).