Jump to content

Progress bar (VB.Net 2005)


set#1
 Share

Recommended Posts

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

    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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.