Visual Basic - Sumar horas variable

Life is soft - evento anual de software empresarial
 
Vista:
Imágen de perfil de Cristian
Val: 4
Ha aumentado 1 puesto en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Sumar horas variable

Publicado por Cristian (34 intervenciones) el 18/12/2012 15:06:08
Hola a todos...

Necesito acumular horas:

por ejemplo:
tengo 01:20 y 02:00 y necesito que me guarde en una variable 03:20.

En realidad lo que necesito es sumar todas las horas trabajadas de una persona.

Espero me puedan ayudar.

Saludos y gracias
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

Sumar horas variable

Publicado por jcmg (518 intervenciones) el 19/12/2012 08:24:40
hola Cristian prueba este codigo
para probarlo necesitas 1 command1,7 labels, 2 textbox(en cada text vas a poner una fecha)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Sub contar()
    Dim a As Integer
    Dim b As Integer
    Dim c As String
    Dim d As String
    Dim e As Integer
    Dim f As Integer
    Dim g As Integer
    Dim h As Integer
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim l As Integer
    Dim m As Integer
    Dim n As Integer
 
    'text1
    a = Left(Text1, 1)
    b = Left(Text1, 2)
    c = Left(Text1, 2)
 
    If a = 0 Then
        Label1 = a & b
    ElseIf a <> 0 Then
        Label1 = c
    End If
 
    If a = 0 Then
        Label1 = a & b
    ElseIf a <> 0 Then
        Label1 = c
    End If
 
    d = Right(Text1, 2)
    e = Right(Text1, 1)
    f = Right(Text1, 2)
 
    If d = 0 Then
        Label2 = d & e
    ElseIf d <> 0 Then
        Label2 = f
    End If
 
    If d = 0 Then
        Label2 = d & e
    ElseIf d <> 0 Then
        Label2 = f
    End If
 
    'text2
    g = Left(Text2, 1)
    h = Left(Text2, 2)
    i = Left(Text2, 2)
 
    If g = 0 Then
        Label3 = g & h
    ElseIf g <> 0 Then
        Label3 = i
    End If
 
    If g = 0 Then
        Label3 = g & h
    ElseIf g <> 0 Then
        Label3 = i
    End If
 
    j = Right(Text2, 2)
    k = Right(Text2, 1)
    l = Right(Text2, 2)
 
    If j = 0 Then
        Label4 = j & k
    ElseIf j <> 0 Then
        Label4 = l
    End If
 
    If j = 0 Then
        Label4 = j & k
    ElseIf j <> 0 Then
        Label4 = l
    End If
 
 
    Label5 = c + i
    Label6 = f + l
 
    If Len(Label5) = 1 Then
        m = "0" & Label5
    ElseIf Len(Label5) = 2 Then
        m = Label5
    End If
 
    If Len(Label6) = 1 Then
        n = "0" & Label6
    ElseIf Len(Label6) = 2 Then
        n = Label6
    End If
 
    Label7 = m & ":" & n
 
End Sub
 
Private Sub Command1_Click()
contar
End Sub
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
Imágen de perfil de Cristian
Val: 4
Ha aumentado 1 puesto en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Sumar horas variable

Publicado por Cristian (34 intervenciones) el 19/12/2012 15:43:19
Gracias jcmg... lo voy a probar

Saludos
Cristian
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
sin imagen de perfil
Val: 119
Ha disminuido 1 puesto en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Sumar horas variable

Publicado por Christian (713 intervenciones) el 22/12/2012 22:12:33
Fijate las funciones de VB, como dateadd y datepart , etc

pero bien podrias hacer algo asi

Dim hora1 As Date
Dim hora2 As Date

hora1 = "01:20:00"
hora2 = "02:00:00"

MsgBox hora1 + hora2


saludos
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
sin imagen de perfil

Sumar horas variable

Publicado por José Humberto (4 intervenciones) el 05/01/2013 22:20:20
Hola Cristian !!!!

tambien te recomiendo que uses variables que contengan convertidores de tipos como CDate()

Prueba este ejemplo simple y me comentas

Var = CDate("4:35:47 PM") + CDate("5:35:47 PM")

MsgBox Format(Var, "hh:mm")

Saludos !!!
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