473,378 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Help with Formula

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.
Aug 8 '06 #1
4 1271
Never mind. I figured it out.

i - ((i - 1) Mod 3)
Aug 8 '06 #2
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

Tony wrote:
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.
Aug 8 '06 #3
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

"Pritcham" wrote:
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

Tony wrote:
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.

Aug 8 '06 #4
Perhaps the OP is looking for a formula like (in VB):

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

Cheers,
Randy
Pritcham wrote:
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

Tony wrote:
>>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.

Aug 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Josh | last post by:
Howdy i am newb somewhat to programing and i was just for fun trying to compile a program that asks the user for an odd int less than 22 and then returns this ***************** ******* *********...
41
by: Seth | last post by:
I am in need of source code for the Aho Corasick algorithm. I have tried searching the web but can't seem to find any code. Is there a good site for c code I can search? Thanks in advance.
2
by: alex | last post by:
I need a more advanced formula than just an average for calculating items rating. I have: raitng value is on scale 1 to 10. s - sum of all ratings for an item n - number of rates (votes)
0
by: RJN | last post by:
Hi I have a main report and a sub report. I have a formula field on the main report and one on the sub report. I want the formula in the subreport to be evaluated after the formula in the main...
0
by: RJN | last post by:
Hi Sorry for posting this message again. I have a main report and a sub report. I have a formula field on the main report and one on the sub report. I want the formula in the subreport to be...
0
by: rjn | last post by:
Hi I have a main report in which I have inserted a sub report. I have a formula field on the main report and one on the sub report. I want the formula in the subreport to be evaluated after the...
0
by: =?Utf-8?B?TGV0emRvXzF0?= | last post by:
I'd like to create a Macro that will sort some raw data, apprx 20k lines, remove some lines based upon a condition in a certain column. Then copy this data into a new spreadsheet and sort the ...
2
by: dreamer1963 | last post by:
Write a Java program without a graphical user interface that calculates and displays the monthly mortgage payment amount, given the amount of the mortgage, the term of the mortgage, and the interest...
3
by: alaurent71 | last post by:
I have a SELECT statement THAT has several embedded SELECT statements. I want to search using LIKE on the result of the embedded SELECT (AS f_item, AS f_desc, AS r_item or AS r_desc). The very...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.