Visual Basic para Aplicaciones - Dias Habiles

Life is soft - evento anual de software empresarial
   
Vista:

Dias Habiles

Publicado por Quique (2 intervenciones) el 01/10/2010 20:19:31
HOla quiero obtener un array de los dias habiles ()Lunes a Viernes) de un mes

POr ejemplo yo le dijo al programa
MES= Enero
y me regresa en el arrey los dias que son laborales por ejemplo

L1
M2
M3
J4
V5
L8
M9
M10
J11
V12
L15
M16
M17
J18
V19
L22
M23
M24
J25
V26
L29
M30
M31

Saludos desde la ciudad mas peligrosa del mundo CD Juarez Chihuahua
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Dias Habiles

Publicado por Antoni Masana (12 intervenciones) el 29/10/2010 12:17:30
En Excel existe la funcion DiaSem()

En Visual Basic 6 hechale un vistazo a esto:

Option Explicit

Dim intYr As Integer
Dim intMo As Integer
Dim intDay As Integer

Public Function DayOfTheWeek_S(ByVal TheDate As Date) As String
Select Case DayOfTheWeek_I(TheDate)
Case 0
DayOfTheWeek_S = "Sunday"
Case 1
DayOfTheWeek_S = "Monday"
Case 2
DayOfTheWeek_S = "Tuesday"
Case 3
DayOfTheWeek_S = "Wednesday"
Case 4
DayOfTheWeek_S = "Thursday"
Case 5
DayOfTheWeek_S = "Friday"
Case 6
DayOfTheWeek_S = "Saturday"
Case Else
DayOfTheWeek_S = "HOLY ****!"
End Select
End Function

Public Function DayOfTheWeek_I(TheDate As Date) As Integer
intYr = Year(TheDate)
intMo = Month(TheDate)
intDay = Day(TheDate)

'Debug.Print intYr; "intYr"
'Debug.Print intMo; "intMo"
'Debug.Print intDay; "intDay"
' W = D + Y + Year + M + C
' | | | | | ^Century Offset Number (see Century_Offset Function)
' | | | | Month Offset Number (see MonthOffset Function)
' | | | Present Year sans Century (i.e. if it's 2008, this number would be "8")
' | | 'YearOffset...
' | Day of the Month (i.e. if the Date is Janueary 1st, this number would be a "1")
' Day of the Week! (More or less;)

DayOfTheWeek_I = intDay + YearOffset + IntYear + MonthOffset + CenturyOffset
DayOfTheWeek_I = DayOfTheWeek_I Mod 7
End Function

Private Function MonthOffset() As Integer
Select Case intMo
Case 1
MonthOffset = 0
If LeapYear = True Then MonthOffset = 6
Case 2
MonthOffset = 3
If LeapYear = True Then MonthOffset = MonthOffset - 1
Case 3
MonthOffset = 3
Case 4
MonthOffset = 6
Case 5
MonthOffset = 1
Case 6
MonthOffset = 4
Case 7
MonthOffset = 6
Case 8
MonthOffset = 2
Case 9
MonthOffset = 5
Case 10
MonthOffset = 0
Case 11
MonthOffset = 3
Case 12
MonthOffset = 5
End Select
'Debug.Print MonthOffset; "MonthOffset"
End Function

Private Function LeapYear() As Boolean
If IntYear = 0 Then 'Century!
If Century / 400 = Century \ 400 Then LeapYear = True
If Century / 4000 = Century \ 4000 Then LeapYear = False
Else 'not round century...
If (Century Mod 4) = 0 Then LeapYear = True
End If
'Debug.Print LeapYear; "LeapYear"
End Function

Private Function IntYear() As Integer
IntYear = intYr - (IntCentury * 100)
'Debug.Print IntYear; "IntYear"
End Function

Private Function IntCentury() As Integer
IntCentury = intYr \ 100
'Debug.Print IntCentury; "IntCentury"
End Function

Private Function CenturyOffset() As Integer
CenturyOffset = 2 * (3 - (IntCentury Mod 4))
'Debug.Print CenturyOffset; "CenturyOffset"
End Function

Private Function YearOffset() As Integer
YearOffset = IntYear \ 4
'Debug.Print YearOffset; "YearOffset"
End FunctionI'm sure this could be optim
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar