viernes, julio 28, 2006

Cálculos y manejo de cadenas

Function CambiaMes(intMes As Integer) As String
  If intMes = 1 Then CambiaMes = "Ene"
  If intMes = 2 Then CambiaMes = "Feb"
  If intMes = 3 Then CambiaMes = "Mar"
  If intMes = 4 Then CambiaMes = "Abr"
  If intMes = 5 Then CambiaMes = "May"
  If intMes = 6 Then CambiaMes = "Jun"
  If intMes = 7 Then CambiaMes = "Jul"
  If intMes = 8 Then CambiaMes = "Ago"
  If intMes = 9 Then CambiaMes = "Sep"
  If intMes =10 Then CambiaMes = "Oct"
  If intMes =11 Then CambiaMes = "Nov"
  If intMes =12 Then CambiaMes = "Dic"
End Function


La siguiente función calcula la edad dependiendo de la fecha proporcionada.
Function CalculaEdad(ByVal dtFechaNac As Date) As Integer
  Dim Edad As Integer = DateTime.Today.Year - dtFechaNac.Year
  If DateTime.Today.Month > dtFechaNac.Month Then Edad -= 1
  If dtFechaNac.Month = DateTime.Today.Month Then
    If DateTime.Today.Day > dtFechaNac.Day Then Edad -= 1
  End If
  Return Edad
End Function


Function DateToDisplay(ByVal dtFecha As Date, ByVal StrFormato As String) As String
Dim StrFechaDia, StrFechaMes, StrFechaAno As String

StrFechaDia = dtFecha.Day
StrFechaMes = dtFecha.Month
If dtFecha.Day > 0 And dtFecha.Day < 10 Then StrFechaDia = "0" & dtFecha.Day
If dtFecha.Month > 0 And dtFecha.Month < 10 Then StrFechaMes = "0" & dtFecha.Month
StrFechaAno = dtFecha.Year

If StrFormato = "0" Then
Return StrFechaDia & "/" & StrFechaMes & "/" & StrFechaAno
ElseIf StrFormato = "A" Then
Return StrFechaDia & "-" & CambiaMes(dtFecha.Month) & "-" & StrFechaAno
End If
End Function

No hay comentarios.: