Reputation: 1121
I'm trying to find the Min/Max value of a textbox that has 1 variable and display it to the user, so the variable changes everytime the button is clicked. How would I find the maximum value of something that is constantly changing? The trick is that I can NOT use if statements or case statements. I'm totally at a loss here.
Upvotes: 0
Views: 421
Reputation: 7130
Ok, the things that limit you.
if
/case
statementsThe lesson seems to revolve around using Math.Max()
.
Math.Max()
, as we can see on MSDN returns
the larger of two 32-bit signed integers.
The one variable we are going to use needs to exist outside of the button's click
event. So, just make it a class variable.
This variable will essentially store the largest value. Math.Max()
returns the largest of two values... see what I am getting at here? You can pass the current largest variable as a parameter to Math.Max()
without any issues.
Dim max As Integer
max = Math.Max(1, 100)
'max would be 100
max = Math.Max(max, 10)
'max would be 100
max = Math.Max(max, 1000)
'max would be 1000
Upvotes: 1