|
-
Apr 9th, 2006, 10:42 PM
#1
Thread Starter
Addicted Member
Up Down problem
Hey everyone,
I'm having a problem with an updown thingy. When you click the up and down arrows it adds or subtracts from your total money to spend, but if you manually imput a number into the box it doesn't change the money. :-/
Here's part of my code where "rs" is the total you have to spend:
VB Code:
Private Sub resourcesValue()
If purchase Then
spent = scal + sinf + sgen + sart + skni + sport
lblResources.Text = "Available Resources: " & rs - spent
If (rs - spent < 0) Then
lblResources.ForeColor = Color.Red
btnPurchase.Enabled = False
Else
lblResources.ForeColor = Color.Black
btnPurchase.Enabled = True
End If
End If
End Sub
Private Sub udCalvary_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles udCalvary.ValueChanged
scal = udCalvary.Value * 8
resourcesValue()
End Sub
Private Sub udKnight_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles udKnight.ValueChanged
skni = udKnight.Value * 11
resourcesValue()
End Sub
Private Sub udInfantry_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles udInfantry.ValueChanged
sinf = udInfantry.Value * 5
resourcesValue()
End Sub
Is there any way I can make it read this value change too? Thanks,
Mike
-
Apr 9th, 2006, 11:40 PM
#2
Re: Up Down problem
The ValueChanged event is not raised until the Text is successfully validated. When you type directly into the control that will not happen until you either click an arrow button, press an arrow key or shift focus to another control. I think pressing the Enter key will also force validation but I haven't tested that to confirm. This happens to prevent the event being raised after you type each digit of a multi-digit number, and also to prevent attempts to validate numbers that may be invalid because you haven't finished typing.
-
Apr 10th, 2006, 07:13 AM
#3
Thread Starter
Addicted Member
Re: Up Down problem
Hey,
Well, I guess I understand why it does that, but is there anything I can do to force it to validate. The form is setup so that after you enter in the numbers you must push a button to confirm your selection.
Here's the button's code:
VB Code:
Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
btnPurchase.Enabled = False
purchase = 0
udCalvary.Enabled = False
udKnight.Enabled = False
udInfantry.Enabled = False
udArtillery.Enabled = False
udGeneral.Enabled = False
udPort.Enabled = False
rs -= spent
End Sub
Is there anything that I can add to force it to validate all the up down things before subtracting the money?
Thanks
Mike
-
Apr 10th, 2006, 07:38 AM
#4
Re: Up Down problem
Like I said, when you enter a value manually the Text will be validated and the Value updated when the NUD loses focus. If you are clicking a Button then that validation will have occurred by the time the Button's Click event is raised.
-
Apr 10th, 2006, 01:40 PM
#5
Thread Starter
Addicted Member
Re: Up Down problem
Well, maybe I'm doing something wrong but it does not validate when they push the button. The money goes away fine when using the up down arrows, but when the enter a number and then push the button (without pressing enter or an arrow) the money stays.
-
Apr 10th, 2006, 07:23 PM
#6
Re: Up Down problem
All I can tell you is what happens when I try it, and it works for me in 2003 and 2005. Are you sure you aren't entering a value that is not valid, like it's outside the min or max limits?
-
Apr 11th, 2006, 12:41 AM
#7
Thread Starter
Addicted Member
Re: Up Down problem
well, actually i did enter a value outside of the range. Is there a way to do something about that?
-
Apr 11th, 2006, 03:20 AM
#8
Re: Up Down problem
 Originally Posted by spelltwister
well, actually i did enter a value outside of the range. Is there a way to do something about that?
If you have limits set on your fields then your user should know about them, and you as the developer should certainly know about them. If you enter a value outside the range then when it is validated it will automatically be changed to either the maximum or minimum value, depending on what limit you've breached. Either you want those limits imposed or you don't. If you do then I don't see the problem. If you you don't then you need to change them. The Maximum and Minimum properties are type Single, so you are limited only by the MinValue and MaxValue of the Single type. The default range is 0 to 100. Have you just left those values unchanged?
-
Apr 11th, 2006, 11:39 AM
#9
Thread Starter
Addicted Member
Re: Up Down problem
I have limits set, but it does not return to the maximum when i push the button. Here's what happens.
I have 80 money to spend. I enter into the udInfantry control the number 80, meaning I need 400 money, but when I push the button, it gives me the 16 infantry that I purchased that turn (IE, 80/5 is 16 infantry) and does not subtract anything from my money.
I believe this is how you set limits:
VB Code:
udCalvary.Maximum = Math.Floor(rs / 8)
udKnight.Maximum = Math.Floor(rs / 11)
udInfantry.Maximum = Math.Floor(rs / 5)
udArtillery.Maximum = Math.Floor(rs / 10)
udGeneral.Maximum = 1
If Math.Floor(rs / 10) >= 1 Then
udPort.Maximum = 1
Else
udPort.Maximum = 0
End If
Any idea?
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|