?
Solved

Urgent Case! -  the best combination of dividers '22' and '30' which divide a certain number with the smallest remainder

Posted on 2004-04-23
19
Medium Priority
?
308 Views
Last Modified: 2010-05-02
Hi,
Urgently Can I have some VB code so that if I enter a certain number, say '203', then the program can find out
the best combination of dividers '22' and '30' with the smallest remainder'
Example:

Enter "203"

Output:
30 x (6) + 22 X (1) => remainder is 1

I want to output '6' and '1' in the program.
0
Comment
Question by:starstarhk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
  • 2
  • +1
19 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10906418
what about...

201x1+1x1
0
 

Author Comment

by:starstarhk
ID: 10906423
I need '30' and '22' to be my divider
30 and 22 must be used for calculation
0
 

Author Comment

by:starstarhk
ID: 10906426
the remainder must be the smallest in all cases of combinations
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Ryan Chong
ID: 10906455
Try:

myvalue = 203
    divider1 = Int(myvalue / 30)
    tmp = myvalue Mod 30
    divider2 = Int(tmp / 22)
    MsgBox "divider1 = " & divider1 & ", divider2 = " & divider2

?
0
 

Author Comment

by:starstarhk
ID: 10906466
the number '30' doesn't have a priorty that the myvalue must not be always divided by it first.
The system must analyze in which combination is the best with the smallest remainder or no remainder
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 10906498
>>the number '30' doesn't have a priorty that the myvalue must not be always divided by it first.
of course, you can put 30 and 22 into variables, in order to meet your requirement
0
 

Author Comment

by:starstarhk
ID: 10906519
how about if the input day is '67'

The best combination should be '22 * (3)' with remainder '1'

but the program generated '30 * (2)' with remainder '7'

remainder '1' should be chosen.....
0
 
LVL 9

Accepted Solution

by:
p_sie earned 120 total points
ID: 10906593
Dim divider1(2),divider2(2),tmp(2)

divider1(1) = Int(myvalue / 30)
tmp(1) = myvalue Mod 30
divider2(1) = Int(tmp(1) / 22)

divider1(2) = Int(myvalue / 22)
tmp(2) = myvalue Mod 22
divider2(2) = Int(tmp(2) / 30)

if myvalue - divider1(1) * 30 - divider2(1) * 22 < myvalue - divider1(2) * 22 - divider2(2) * 30
    MsgBox "divider1 = " & divider1(1) & ", divider2 = " & divider2(1)
else
    MsgBox "divider1 = " & divider1(2) & ", divider2 = " & divider2(2)
endif
0
 

Author Comment

by:starstarhk
ID: 10906744
Hi, there is another case...

I want to have combination of dividers '22' and '30' and this time I want to avoid any remainder..
for example if the input is 23, then the old answer is that remainder is 1,
Now I want it to become 30, then if the input is 31, then I want it to become '22x2' = 44
......
so if the input is 206, then the answer should be 22x8+30 = 206
then if the input is 205, then the answer still should be 22x8+30 = 206
The criteria is that I need to have a combination with no remainder which is the closest to the input number.


This is a very difficult task for me.....
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10906765
Did my solution to your first problem (this question!) resolve it?
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10906770
By the way do not forget to close your open questions, you have 7 open!
0
 

Author Comment

by:starstarhk
ID: 10906811
thanks...your solution resolve my problem!! Thank you very much
How can I close my question?

one more thing for the new question..is
the max for the input number is 360
I still cannot figure out how to do it...
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10906826
You can close the question by clicking the accept button at the comment that answered your question.

To put a limit to the input number

If myvalue > 360 then
    MsgBox "Maximum inputnumber is 360!",vbExclamation
    exit sub
end if
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10906827
0
 

Author Comment

by:starstarhk
ID: 10906833
I need your help on this problem....
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10906850
If I understand you correctly, you want the closest higher numer that has no remainder.

Dim divider1(2),divider2(2),tmp(2)

myvalue = myvalue + 21 'because it can be maximal 21 above the imputnumber
divider1(1) = Int(myvalue / 30)
tmp(1) = myvalue Mod 30
divider2(1) = Int(tmp(1) / 22)

divider1(2) = Int(myvalue / 22)
tmp(2) = myvalue Mod 22
divider2(2) = Int(tmp(2) / 30)

if  divider1(1) * 30 - divider2(1) * 22 <  divider1(2) * 22 - divider2(2) * 30
    MsgBox divider1(1) * 30 - divider2(1) * 22
else
    MsgBox  divider1(2) * 22 - divider2(2) * 30
endif
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10906852
By the way thanks for the grade of A!
0
 

Author Comment

by:starstarhk
ID: 10914825
thanks for your help !
If I want to sort a list of numbers, which sorting is good?
I want to find the smallest number among a set of number from an array?
Can u teach me how?
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10915940
Sorting numbers? In code or in a control?

Find the smallest number in an array?

Dim Lowest as Double, Arr() as Double, i as Long

Lowest = Arr(0)
For i = 1 to NumberOfRecordsInArray
    If Arr(i) < Lowest Then Lowest = Arr(i)
Next

Msgbox "Lowest number in array: " & Lowest
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question