SOMAR HORAS
Boas estou com um problema na soma das horas qaundo soma o valor da errado . Estou utilizando esta funcao :
Alguem me ajuda ?
Dim i As Integer
Dim TotalMinutos As Integer
Dim HM() As String
Dim SomaHoras As String
[ô] primeiro convertemos tudo para minutos para efetuarmos uma soma correta
TotalMinutos = 0
With gridRelat
For i = 1 To gridRelat.Rows - 1
HM = Split(.TextMatrix(i, 4), [Ô]:[Ô])
TotalMinutos = TotalMinutos + (CInt(HM(0) * 60) + CInt(HM(1)))
Next i
[ô]
Dim Hrs As Integer
Dim Min As Integer
Min = TotalMinutos Mod 60 [ô]retorna o resto de total de minutos dividido por 60
Hrs = (TotalMinutos - Minutos) / 60
SomaHoras = Hrs & [Ô]:[Ô] & Format(Min, [Ô]00[Ô])
Tothor.Text = SomaHoras
End With
End Sub
Alguem me ajuda ?
Dim i As Integer
Dim TotalMinutos As Integer
Dim HM() As String
Dim SomaHoras As String
[ô] primeiro convertemos tudo para minutos para efetuarmos uma soma correta
TotalMinutos = 0
With gridRelat
For i = 1 To gridRelat.Rows - 1
HM = Split(.TextMatrix(i, 4), [Ô]:[Ô])
TotalMinutos = TotalMinutos + (CInt(HM(0) * 60) + CInt(HM(1)))
Next i
[ô]
Dim Hrs As Integer
Dim Min As Integer
Min = TotalMinutos Mod 60 [ô]retorna o resto de total de minutos dividido por 60
Hrs = (TotalMinutos - Minutos) / 60
SomaHoras = Hrs & [Ô]:[Ô] & Format(Min, [Ô]00[Ô])
Tothor.Text = SomaHoras
End With
End Sub
Ao invés de converter em minutos, poque não soma somente as horas, depois somente os minutos?
Dim cHora1 as string,cHora2 as string,cHora3 as string
Dim cTot as string
cHora1 = [Ô]02:00[Ô]
cHora2 = [Ô]05:00[Ô]
cHora3 = [Ô]02:30[Ô]
cTot = Format(CDate(Label1) + CDate(Label2) + CDate(Label3), [Ô]Short Time[Ô])
msgbox cTot
Dim cTot as string
cHora1 = [Ô]02:00[Ô]
cHora2 = [Ô]05:00[Ô]
cHora3 = [Ô]02:30[Ô]
cTot = Format(CDate(Label1) + CDate(Label2) + CDate(Label3), [Ô]Short Time[Ô])
msgbox cTot
Faça um teste com isto.
Dim totalhours As Long, totalminutes As Long, total As Long
Dim days As Long, hours As Long, minutes As Long
Dim interval As Variant, i As Integer
Conexao
ReabreRst Rs
[ô]total = 1
Rs.Open [Ô]select * from tblFinanca[Ô], Cnn
Set Grid1.DataSource = Rs
interval = #12:00:00 AM#
For i = 1 To Grid1.Rows - 1
interval = interval + CDate(Grid1.TextMatrix(i, 11))
MsgBox [Ô]1[Ô]
Next
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
minutes = totalminutes Mod 60
hours = totalhours Mod 24
MsgBox (totalhours & [Ô]:[Ô] & minutes)
Dim totalhours As Long, totalminutes As Long, total As Long
Dim days As Long, hours As Long, minutes As Long
Dim interval As Variant, i As Integer
Conexao
ReabreRst Rs
[ô]total = 1
Rs.Open [Ô]select * from tblFinanca[Ô], Cnn
Set Grid1.DataSource = Rs
interval = #12:00:00 AM#
For i = 1 To Grid1.Rows - 1
interval = interval + CDate(Grid1.TextMatrix(i, 11))
MsgBox [Ô]1[Ô]
Next
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
minutes = totalminutes Mod 60
hours = totalhours Mod 24
MsgBox (totalhours & [Ô]:[Ô] & minutes)
Tópico encerrado , respostas não são mais permitidas