Sv Community El Salvador
Soporte y Tecnología => Programación => VB => Topic started by: shakringan on November 25, 2011, 11:55:46 am
-
hey nesecito su ayuda con un pequeño control ciber lo que pasa es que nos se como hacer que el siquiente cronometro inicie porque cuando lo cambio me toma como inicio el primer timer
aqui esta el codigo
Public Class Form1
Private Hora As Integer = 0
Private minuto As Integer = 0
Private segundo As Integer = 0
Private milisegundo As Integer = 0
Sub mostrartiempo()
Label1.Text = Hora.ToString.PadLeft(2, "0") & ":"
Label2.Text = minuto.ToString.PadLeft(2, "0") & ":"
Label3.Text = segundo.ToString.PadLeft(2, "0") & ":"
Label4.Text = milisegundo.ToString.PadLeft(2, "0") & ":"
Label1.Refresh()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
milisegundo += 1
If milisegundo = 9 Then
milisegundo = 0
segundo += 1
If segundo = 59 Then
segundo = 0
minuto += 1
If minuto = 59 Then
minuto = 0
Hora += 1
End If
End If
End If
mostrartiempo()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Hora = 0
minuto = 0
segundo = 0
milisegundo = 0
mostrartiempo()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim p, tm, th As Decimal
tm = Convert.ToDecimal(Label2.Text.Replace(":", "")) * 0.01
th = Convert.ToDecimal(Label1.Text.Replace(":", "")) * 0.6
p = (tm + th)
MsgBox("lo gastado es: " & p)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Timer2.Enabled = True
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
milisegundo += 1
If milisegundo = 9 Then
milisegundo = 0
segundo += 1
If segundo = 59 Then
segundo = 0
minuto += 1
If minuto = 59 Then
minuto = 0
Hora += 1
End If
End If
End If
mostrartiempo()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Timer2.Enabled = False
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Hora = 0
minuto = 0
segundo = 0
milisegundo = 0
mostrartiempo()
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
End
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim p, tm, th As Decimal
tm = Convert.ToDecimal(Label8.Text.Replace(":", "")) * 0.01
th = Convert.ToDecimal(Label7.Text.Replace(":", "")) * 0.6
p = (tm + th)
MsgBox("lo gastado es: " & p)
End Sub
End Class
nesecito su ayuda programadores :thumbsup: :thumbsup: :thumbsup: :thumbsup:
-
aqui como que ya te habian ayudado...
http://www.svcommunity.org/forum/programas/ayuda-con-visual-2008-en-net-con-un-pequeno-control-ciber/ (http://www.svcommunity.org/forum/programas/ayuda-con-visual-2008-en-net-con-un-pequeno-control-ciber/)
-
es cierto pero ahora el problema es que ahora cuando cambio los datos del timer 2
siempre me corre el timer 2 unque le de alos botones del 2
-
Hola, está algo largo el código, pero tu error es de lógica y está explicito...
Si no lo has resuelto, pues el método "mostrartiempo()" ordena cambiar los valores a Label1, Label2, Label3 y Label4. Pero tu necesitas en Timer2_Tick que se cambien Label5, Label6, Label7 y Label8 (supongo) entonces deberías hacer lo siguiente
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
milisegundo += 1
If milisegundo = 9 Then
milisegundo = 0
segundo += 1
If segundo = 59 Then
segundo = 0
minuto += 1
If minuto = 59 Then
minuto = 0
Hora += 1
End If
End If
End If
mostrartiempo(Label1, Label2, Label3, Label4)
End Sub
......
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
milisegundo += 1
If milisegundo = 9 Then
milisegundo = 0
segundo += 1
If segundo = 59 Then
segundo = 0
minuto += 1
If minuto = 59 Then
minuto = 0
Hora += 1
End If
End If
End If
mostrartiempo(Label5, Label6, Label7, Label8)
End Sub
Private Sub mostrartiempo(ByVal Lbl_Hora As Label, ByVal Lbl_Minuto As Label, ByVal Lbl_Segundo As Label, ByVal Lbl_MilSegundo As Label)
Lbl_Hora.Text = Hora.ToString.PadLeft(2, "0") & ":"
Lbl_Minuto.Text = minuto.ToString.PadLeft(2, "0") & ":"
Lbl_Segundo.Text = segundo.ToString.PadLeft(2, "0") & ":"
Lbl_MilSegundo.Text = milisegundo.ToString.PadLeft(2, "0") & ":"
End Sub
Aunq la verdad no me gusta como has trabajado la logica. Yo no usaría 2 timers! Luego te vas a topar con el problema que no puedes correr 2 al mismo tiempo (bueno, de poder, si se puede) pero no te mostrará lo que querés (sino lo mismo en los 2 controles de PCs)... te sugiero q ocupes otra lógica
Saludos :thumbsup: