11 Replies - 2548 Views - Last Post: 08 October 2012 - 06:50 AM Rate Topic: -----

#1 TheVoliand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 25-September 12

Progress Bar opens Message Box?

Posted 03 October 2012 - 07:32 AM

So, I'm making a fighting game. my hp bars, when reach 0, are supposed to open a msgbox that says player1 wins or player2 wins.
 If ProgressBar2.Value = 0 Then
            MsgBox("Black Player Wins!")
            Close()
        End If 
        If ProgressBar1.Value = 0 Then
            MsgBox("White Player Wins!")
            Close()
        End If

Is This A Good Question/Topic? 0
  • +

Replies To: Progress Bar opens Message Box?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9500
  • View blog
  • Posts: 35,848
  • Joined: 12-June 08

Re: Progress Bar opens Message Box?

Posted 03 October 2012 - 07:56 AM

Kudos? I think you forgot the question.
Was This Post Helpful? 0
  • +
  • -

#3 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 285
  • View blog
  • Posts: 1,503
  • Joined: 07-April 08

Re: Progress Bar opens Message Box?

Posted 03 October 2012 - 07:58 AM

ok, so whats your question? you need to provide us with a specific question, what you've done to try to solve the question, errors you've received and relevant code snippets. With out this information we really can't help you.

This post has been edited by rgfirefly24: 03 October 2012 - 07:58 AM

Was This Post Helpful? 0
  • +
  • -

#4 King of the Nerds  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 3
  • Joined: 03-October 12

Re: Progress Bar opens Message Box?

Posted 04 October 2012 - 05:15 AM

Okey. If you don't want to add a Timer, I can't really help you. But, you add a timer with this code:

If ProgressBar1.Value = "0" Then
MsgBox("Player1 wins")
Timer1.Enabled = False
ElseIf ProgressBar2.Value = "0" Then
MsgBox("Player2 wins")
Timer1.Enabled = False
End If



And when you are launching the game (starting it):

Timer1.Enabled = True



Not 100% sure this will work, but its worth a try :-)
Was This Post Helpful? -2
  • +
  • -

#5 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 285
  • View blog
  • Posts: 1,503
  • Joined: 07-April 08

Re: Progress Bar opens Message Box?

Posted 04 October 2012 - 05:42 AM

There is no reason to use timer. Again, until the OP actually poses a question there is nothing we can do.

This post has been edited by rgfirefly24: 04 October 2012 - 09:26 AM

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Progress Bar opens Message Box?

Posted 04 October 2012 - 06:08 AM

I'm thinking the OP is implying the question, "Why doesn't this work" because he is assuming the either ProgressBar1.Value = 0 or ProgressBar2.Value = 0 and therefore should produce a MessageBox and it doesn't.

TheVoliand, Place a breakpoint in your code where you think a condition should fire of this check and step through the code and look at the values of both progressbars. If one of them = 0 then step on through to see why it's not reaching this block of code and if it is reaching this block of code, why did the value change from 0.

The code you have above is error free and therefore means that you have a logic problem (this could be that you're not processing that code or that the values are not what you expect when it reaches this code)

That's pretty much all we can give without more input from you.

This post has been edited by CharlieMay: 04 October 2012 - 06:09 AM

Was This Post Helpful? 0
  • +
  • -

#7 Null::Void()  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-October 12

Re: Progress Bar opens Message Box?

Posted 04 October 2012 - 06:44 AM

Im not sure if VB.net has unsigned integers but if it does you could make your variables unsigned int so that no matter the damage your player takes the value will be no less that 0.
Was This Post Helpful? 0
  • +
  • -

#8 TheVoliand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 25-September 12

Re: Progress Bar opens Message Box?

Posted 08 October 2012 - 05:35 AM

sorry the problem was that when i tried to debug it i could get the hp bar to 0 and then an error occurs where it says you -20 is not a valid value. i can get it to open the msgbox, but after that it pretty much crashes
Was This Post Helpful? 0
  • +
  • -

#9 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 767
  • Joined: 19-October 11

Re: Progress Bar opens Message Box?

Posted 08 October 2012 - 05:57 AM

By default, ProgressBar has set minimum value to 0, and maximum to 100. You can set them different, but usually, that is not needed, because they are used as representation of percentage (0 to 100%).

When you subtract fighters' damage to -20, the exception is thrown. This means, you'd probably want to prevent the damage to be less than 0. Unless you want your worrier to be more dead than dead ;)

This post has been edited by lucky3: 08 October 2012 - 06:01 AM

Was This Post Helpful? 0
  • +
  • -

#10 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Progress Bar opens Message Box?

Posted 08 October 2012 - 06:06 AM

TheVoliand
Did you check to see if the damage takes the value below 0 prior to setting the new value to the progressbar?

ie:
Damage = 20
If ProgressBar1.Value - Damage =< 0 Then 'Meaning this will cause an exception if you try to set it
  ProgressBar1.Value = 0 'Since it would take it < 0 and cause an exception, force it to 0 
  'Do Death Routine
Else
  ProgressBar1.Value -= Damage 'Otherwise, subtract damage and wait for more damage
End If

Was This Post Helpful? 1
  • +
  • -

#11 TheVoliand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 25-September 12

Re: Progress Bar opens Message Box?

Posted 08 October 2012 - 06:15 AM

charliemay, that makes it so that they both die instantly

Figured it out, charliemay what was wrong when i attempted your code was the else was put in a timer, which meant it would just hit -20 infinitly, but the <= was what i needed thanks!
Was This Post Helpful? 0
  • +
  • -

#12 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Progress Bar opens Message Box?

Posted 08 October 2012 - 06:50 AM

OK , that was a demonstration. You would pass your damage to the routine. Where I set 20 was to demonstrate subtracting a variable. For example, if you have a progress bar with a total of 61 it would take 4 hits to kill because each hit is 20 but without the check, the 4th hit would cause -19 which would throw an exception so the check is put in place to say if it WOULD go below 0 make it 0. Thus, no exception thrown.

Part of this is you're taking what people show you and trying to make it work verbatim. You need to understand that the only thing I'm trying to show you is how to subtract from a ProgressBar .Value without causing an ArgumentException. What those values are and how you subtract them is part of your code logic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1