set#1 Posted October 2, 2009 at 09:42 AM Report Share #289593 Posted October 2, 2009 at 09:42 AM Hello. Tenho um progress bar no form de Login com timer, que ao terminar a contagem quero que feche o formulario consecutivamente o sistema. Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick ProgressBar1.Value = ProgressBar1.Value + 1 If (ProgressBar1.Value > 100) Then MsgBox("O sistema fechou por ficar muito tempo sem acede-lo. Volte a abrir novamente", MsgBoxStyle.OkOnly, "System Exit") Me.Close() End If End Sub Mas quando termina a contagem tenho erro: Value of '101' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'. Parameter name: Value Tenho o max = 100 e min = 0 Any idea?? Obrigado Link to comment Share on other sites More sharing options...
ribeiro55 Posted October 2, 2009 at 09:44 AM Report Share #289594 Posted October 2, 2009 at 09:44 AM Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick ProgressBar1.Value = ProgressBar1.Value + 1 If (ProgressBar1.Value > 100) Then MsgBox("O sistema fechou por ficar muito tempo sem acede-lo. Volte a abrir novamente", MsgBoxStyle.OkOnly, "System Exit") Me.DialogResult = Windows.Forms.DialogResult.Abort End If End Sub Sugiro o seguinte: Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick If (ProgressBar1.Value => 100) Then MsgBox("O sistema fechou por ficar muito tempo sem acede-lo. Volte a abrir novamente", MsgBoxStyle.OkOnly, "System Exit") Me.DialogResult = Windows.Forms.DialogResult.Abort Else ProgressBar1.Value = ProgressBar1.Value + 1 End If End Sub Deves verificar antes de incrementares o valor. Da tua maneira, estavas a atribuír um valor impossível (101 quando o máximo é 100) e só depois é que ias verificar se estava fora. Para além disso, > não pode funcionar, por a mesma razão. 101 é impossível quando o máximo é 100. BTW, não precisas da condição entre parentesis no VB 😄 Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
set#1 Posted October 2, 2009 at 10:12 AM Author Report Share #289596 Posted October 2, 2009 at 10:12 AM Sugiro o seguinte: Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick If (ProgressBar1.Value => 100) Then MsgBox("O sistema fechou por ficar muito tempo sem acede-lo. Volte a abrir novamente", MsgBoxStyle.OkOnly, "System Exit") Me.DialogResult = Windows.Forms.DialogResult.Abort Else ProgressBar1.Value = ProgressBar1.Value + 1 End If End Sub Deves verificar antes de incrementares o valor. Da tua maneira, estavas a atribuír um valor impossível (101 quando o máximo é 100) e só depois é que ias verificar se estava fora. Para além disso, > não pode funcionar, por a mesma razão. 101 é impossível quando o máximo é 100. BTW, não precisas da condição entre parentesis no VB 🙂 Com o Me.DialogResult = Windows.Forms.DialogResult.Abort o prompt do System Exit não para de aparecer. Pus Me.Close() também não para, mas clicando OK sai do sistema. Agora o problema ta no prompt...o ideal seria aparecer uma vez e esperar pelo click OK. E obrigado pela dica dos parentesis!! 😄 Link to comment Share on other sites More sharing options...
fLaSh_PT Posted October 2, 2009 at 10:21 AM Report Share #289597 Posted October 2, 2009 at 10:21 AM Tenta parar o timer Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick If (ProgressBar1.Value => 100) Then MsgBox("O sistema fechou por ficar muito tempo sem acede-lo. Volte a abrir novamente", MsgBoxStyle.OkOnly, "System Exit") Me.DialogResult = Windows.Forms.DialogResult.Abort Timer.Enabled = False Me.Close Else ProgressBar1.Value = ProgressBar1.Value + 1 End If End Sub Making the impossible possible and pwing the world on db at a time. Link to comment Share on other sites More sharing options...
set#1 Posted October 2, 2009 at 10:25 AM Author Report Share #289598 Posted October 2, 2009 at 10:25 AM Tenta parar o timer Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick If (ProgressBar1.Value => 100) Then MsgBox("O sistema fechou por ficar muito tempo sem acede-lo. Volte a abrir novamente", MsgBoxStyle.OkOnly, "System Exit") Me.DialogResult = Windows.Forms.DialogResult.Abort Timer.Enabled = False Me.Close Else ProgressBar1.Value = ProgressBar1.Value + 1 End If End Sub Ainda continua o loop da msgbox!! Link to comment Share on other sites More sharing options...
fLaSh_PT Posted October 2, 2009 at 10:53 AM Report Share #289601 Posted October 2, 2009 at 10:53 AM Algo está errado.. podes colocar mais código? Making the impossible possible and pwing the world on db at a time. Link to comment Share on other sites More sharing options...
ribeiro55 Posted October 2, 2009 at 11:50 AM Report Share #289612 Posted October 2, 2009 at 11:50 AM Exprimenta parar o Timer antes da messagebox, as in, logo a primeira instrução do IF Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
set#1 Posted October 2, 2009 at 12:31 PM Author Report Share #289621 Posted October 2, 2009 at 12:31 PM Exprimenta parar o Timer antes da messagebox, as in, logo a primeira instrução do IF Ficou assim e esta a funcionar: Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick If ProgressBar1.Value >= 100 Then Timer.Stop() MsgBox("O sistema fechou por ficar muito tempo sem acede-lo. Volte a abrir novamente", MsgBoxStyle.OkOnly, "System Exit") Me.DialogResult = Windows.Forms.DialogResult.Abort Me.Close() Else ProgressBar1.Value = ProgressBar1.Value + 1 End If End Sub Parei o timer depois da condição If e antes da msgbox. Obrigado pela atencao, voces sao gr8 😄 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now