Question[HELP]MsgBox Progressbar

Posts 1–15 of 19 · Page 1 of 2
[HELP]MsgBox Progressbar
Okay, so I need help with my msgbox showing up after the processbar has reached it's maximum.
Here's the code:
[PHP] If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then
MsgBox("Congratualations! You have succesfully found a life!")
Else : MsgBox("No succes, please try again!")
End If[/PHP]

When I put it in the timer's section it spams me with pop-ups.
When I put in in the progressbar's section it does nothing.

Can anyone help me out on this?
Progress bars are usually incremented on specific events. When you put it in a timer, the timer will display the message box on reaching the interval every time. Therefore, you need to disable the timer after the maximum point is reached. To do this, simply use the 'TimerName.Enabled=false' statement.

Your code will now be something like this:

Code:
If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then 
            MsgBox("Congratualations! You have succesfully found a life!") 
        Else 
'To disable msgbox until the user presses ok.
Timer1.Interval=300000
 MsgBox("No succes, please try again!") 
Timer1.Enabled=False
End If  
Quote Originally Posted by Hassan View Post
Progress bars are usually incremented on specific events. When you put it in a timer, the timer will display the message box on reaching the interval every time. Therefore, you need to disable the timer after the maximum point is reached. To do this, simply use the 'TimerName.Enabled=false' statement.

Your code will now be something like this:

Code:
If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then 
            MsgBox("Congratualations! You have succesfully found a life!") 
        Else 
'To disable msgbox until the user presses ok.
Timer1.Interval=300000
 MsgBox("No succes, please try again!") 
Timer1.Enabled=False
End If  
Thanks, but didn't quite help, now the MsgBox shows up after the first increment of the progressbar and it does not load any further.
Anyone?
EDIT:
Since the else statement doesn't tell the MsgBox to popup when the progressbar has reached it's maixmum, it pops-up immideatly.
So I tried this, but it didn't work either:
[php] If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then
MsgBox("Congratualations! You have succesfully found a life!")
Elseif ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text <> "10762" Then
MsgBox("No succes, please try again!")
End If[/php]
Send me your project.

I tested everything, no issues, I had to make no corrections.
Ahh I think I see the problem. Were you adding Xscapism's code to the same timer that is increasing the ProgressBar value? If so you'll have to edit it like so:

[php]
If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then
MsgBox("Congratualations! You have succesfully found a life!")
End if
[/php]

I recommend not having the MsgBox with "No Success" because that means every time that the progress bar is NOT at maximum and the timer ticks over, it'll give you that little message box. Either refine what triggers a "MsgBox("No success")" or exclude it entirely.
Quote Originally Posted by NextGen1 View Post
Send me your project.

I tested everything, no issues, I had to make no corrections.
I'll send it to you right away
Okay, The issue here is easy to find, it's basic logic.

Code:
   Dim random As New Random
        ProgressBar1.Increment(1)
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Stop()
            Label2.Text = ("Done!")
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Label3.Text = random.Next(20000)
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            ProgressBar1.Value = ProgressBar1.Minimum
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then
            MsgBox("Congratualations! You have succesfully found a life!")
        Else
            Timer1.Interval = 30000000
            MsgBox("No succes, please try again!")
            Timer1.Enabled = False
        End If
Go at it, teach the young jedi the way of the logic force.
Quote Originally Posted by NextGen1 View Post
Okay, The issue here is easy to find, it's basic logic.

Code:
   Dim random As New Random
        ProgressBar1.Increment(1)
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Stop()
            Label2.Text = ("Done!")
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Label3.Text = random.Next(20000)
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            ProgressBar1.Value = ProgressBar1.Minimum
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then
            MsgBox("Congratualations! You have succesfully found a life!")
        Else
            Timer1.Interval = 30000000
            MsgBox("No succes, please try again!")
            Timer1.Enabled = False
        End If
Go at it, teach the young jedi the way of the logic force.
Haha, I still have much to learn indeed/
In the meantime, I'll TRY to solve this xD
Quote Originally Posted by NextGen1 View Post
Okay, The issue here is easy to find, it's basic logic.

Code:
   Dim random As New Random
        ProgressBar1.Increment(1)
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Stop()
            Label2.Text = ("Done!")
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Label3.Text = random.Next(20000)
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            ProgressBar1.Value = ProgressBar1.Minimum
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then
            MsgBox("Congratualations! You have succesfully found a life!")
        Else
            Timer1.Interval = 30000000
            MsgBox("No succes, please try again!")
            Timer1.Enabled = False
        End If
Go at it, teach the young jedi the way of the logic force.
I already posted why the logic wouldn't work but everyone ignored the post :O
Quote Originally Posted by Jason View Post


I already posted why the logic wouldn't work but everyone ignored the post :O
I read your post, but it's neccesary for the MsgBox to popup :s
So I can't exclude it from my project.
Lolland deleted my flawless code
I'm surprised lolland, blubb or xscape , didn't jump on this one immediately.

It's not just what yo posted Jdeezy, the logic is all wrong throughout the whole timer.

and the biggest issue in this logic is here

Else
Timer1.Interval = 30000000
MsgBox("No succes, please try again!")
Timer1.Enabled = False

code reads bottom to top , the way the logic is currently written is

Progressbar1.Value = progressbar1.value + 1 (or in this case increments + 1)
Which is fine, however it is also reading the rest of the code in the timer,

and your else statement is true when the timer clicks in so , what happens is the else statement triggers.

What I would do is Use Select Case for randomization and user 2 timers, one which handles the progress bar increments and the other which handles the logic .

and still that logic would need to be corrected.
Quote Originally Posted by NextGen1 View Post

It's not just what yo posted Jdeezy, the logic is all wrong throughout the whole timer.

and the biggest issue in this logic is here

Else
Timer1.Interval = 30000000
MsgBox("No succes, please try again!")
Timer1.Enabled = False

.
That was exactly what I posted lol.
Any1 sees issues in the new code? :s
I just decided to make label2 change text instead of a MsgBox popping up.
Here's the code now:
Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
        Label4.Text = ("Searching...")
        Timer2.Start()
        Timer3.Start()
        Timer4.Start()
    End Sub

    Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Randomize()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Increment(1)
    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim random As New Random
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Stop()
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Label3.Text = Random.Next(20000)
        End If
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            ProgressBar1.Value = ProgressBar1.Minimum
        End If
    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text = "10762" Then
            Label4.Text = ("Congratualations! You have succesfully found a life!")
        End If
    End Sub

    Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
        If ProgressBar1.Value = ProgressBar1.Maximum And Label3.Text <> "10762" Then
            Label4.Text = ("No life was found! Please try again!")
        End If
    End Sub
End Class
Posts 1–15 of 19 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us