Progressbar Error

newb2388

New member
Joined
Mar 23, 2012
Messages
1
Programming Experience
Beginner
So i made sort of like a dice like thing that drains the progressbar so if the button is clicked it will land on a number from 1-6.

VB.NET:
   Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        Dim rndnumber As Random
        Dim number As Integer
        rndnumber = New Random
        number = rndnumber.Next(1, 6)
        TextBox1.Text = number.ToString
        Timer1.Enabled = True


Then i tied them together to the progress bar if it lands on 1 it will inflict 1 value damage to the healthbar and 2 will inflict 2 value damage and etc.

VB.NET:
   If TextBox1.Text = 1 Then
            CompBar.Value = CompBar.Value - 1
            You.Value = You.Value - 1
            Timer1.Stop()
        End If
        If TextBox1.Text = 2 Then
            CompBar.Value = CompBar.Value - 2
            You.Value = You.Value - 1
            Timer1.Stop()
        End If
        If TextBox1.Text = 3 Then
            CompBar.Value = CompBar.Value - 3
            You.Value = You.Value - 1
            Timer1.Stop()
        End If
        If TextBox1.Text = 4 Then
            CompBar.Value = CompBar.Value - 4
            Timer1.Stop()
        End If
        If TextBox1.Text = 5 Then
            CompBar.Value = CompBar.Value - 5
            Timer1.Stop()
        End If
        If TextBox1.Text = 6 Then
            CompBar.Value = CompBar.Value - 6
            Timer1.Stop()
        End If

Once i launch the application it will drain the healthbar correctly but if it reaches the end of the healthbar it will shut down the game and will not respond

the error states its the value going below the minimum value of the healthbar How can i insure the value does not decrease bellow 0 ?

Note: CompBar is the healthbar and the min is 0 max is at 100 in value.
 
You can either do the check yourself, or set Step property (as negative number) and call PerformStep method.
 
Back
Top