Help with Formula

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to create a formula in dot net to achieve the following:

Input: Output:
1 1
2 1
3 1
4 4
5 4
6 4
7 7
8 7
9 7

So... pass any value from 1 to 9 into this mathematical formula and it
churns out either 1, 4 or 7.

Been struggling with this formula.
Any ideas.
 
Hi

It's not really a formula you're after unless there is a numerical
relationship between your input and output (i.e. why does 2 = 1 and 5 =
4?).

If you're just trying to have an input of 1-9 and get an output of 1, 4
or 7 then you could use either a couple of IF statements or a
SELECT....CASE construct - e.g. something like...

If Input < 4 Then Output = 1 ElseIf Input < 7 then output = 4 Else
Output = 7

Or

Select Case Input
Case 1 - 3
Output = 1
Case 4 - 6
Output = 4
Case Else
Output = 7
End Select

HTH
Martin
 
Many thanks for the reply Martin. I'd been pondering this problem in my head
for quite a while... and (typical)... I stumbled across the formula a few
minutes after this post.

I thought about creating a function with a select case statement to solve
the problem, but I wanted to solve it elegantly.

Thanks for taking the time to reply.

Cheers,
Tony
 
Perhaps the OP is looking for a formula like (in VB):

Output = 1 + 3 * Int((Input - 1) / 3)

Cheers,
Randy
 
Back
Top