Basically i need a little bit of an equation that does the folowing:
if number is 24 then add 13
if number is 23 then add 14
if number is 22 then add 15
if number is 21 then add 16
if number is 20 then add 17
...
...
if number is 14 then add 23
if number is 13 then add 24
can anyone see a one line soution (or near as dammit) to this???
thanks
Last edited by youngnoviceinneedofh; Feb 13th, 2008 at 11:37 AM.
Instead of doing all that math (which isn't much, I know) why not just check the value of 'Number' and if it's between the certain range, just make it 37
If Number is between (or equal to) 13 and 24, then make it equal to 37
Currently using VS 2015 Enterprise on Win10 Enterprise x64.
Instead of doing all that math (which isn't much, I know) why not just check the value of 'Number' and if it's between the certain range, just make it 37
If Number is between (or equal to) 13 and 24, then make it equal to 37
I think by his question he's looking for what the number is needed to add to the first number. He has 24, puts it into the function, he's returned 13... that's how I read it. He listed it out as an example.
I think by his question he's looking for what the number is needed to add to the first number. He has 24, puts it into the function, he's returned 13... that's how I read it. He listed it out as an example.
Thus:
Code:
intNumberOut = 37 - intNumberIn
In that case, yes a function would serve nicely. I read his post as:
If Number = 24 then add 13, so Number = 37
If Number = 23 then add 14, so Number = 37
If Number = 22 then add 15, so Number = 37
In which case, the end result is always Number = 37
Currently using VS 2015 Enterprise on Win10 Enterprise x64.
From your original post, it seems that the sum is always 37... Now that you've said the total is not always the same, I think you need to give us more details.
OtherNumber += CalcNumber(Number)
Private Function CalcNumber(Byval OriginalNumber As Integer) As Integer
If OriginalNumber >= 13 AndAlso OriginalNumber <= 24 Then
Return 37I - OriginalNumber
Else
Return 0I
End If
End Function
Currently using VS 2015 Enterprise on Win10 Enterprise x64.