473,326 Members | 2,090 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,326 software developers and data experts.

Cost Block Allocation

25
I am using VB in Excel v.6.3.

I am trying to write a program that will solve the folowing problem:

I have a list of random numbers (PurchBlks) and the list is a random length (for practical purposes I will use a list of 5 numbers)

250
68
453
124
13

I also have a variable single number (Saleshrs). For example
743

I need to have the program figure out how many of the numbers on the list to use going from top to bottom.

In the example I would use 250, 68, and 425 of the 453.
Feb 29 '08 #1
3 873
kadghar
1,295 Expert 1GB
I am using VB in Excel v.6.3.

I am trying to write a program that will solve the folowing problem:

I have a list of random numbers (PurchBlks) and the list is a random length (for practical purposes I will use a list of 5 numbers)

250
68
453
124
13

I also have a variable single number (Saleshrs). For example
743

I need to have the program figure out how many of the numbers on the list to use going from top to bottom.

In the example I would use 250, 68, and 425 of the 453.
It seems like a homework to me ^.^

Anyway, you shouldnt have any trouble using a DO / LOOP :

lets say PurchBlks is an array of doubles (of one dimension), which first index is zero:
Expand|Select|Wrap|Line Numbers
  1. dim i as long
  2. dim Str1 as string
  3. dim Sum1 as double 'if you dont care about the value of Saleshrs after the result is given, you can skip this variable and just make substractions to Saleshrs.
  4.  
  5. do
  6.     sum1=sum1 + PurchBlks(i)
  7.     if sum1> Saleshrs then exit do
  8.     str1 = cstr(PurchBlks(i)) & ", "
  9.     i= i+1
  10. loop
  11.  
  12. sum1=sum1 - PurchBlks(i)
  13. str1 = str1 & " and " cstr(Saleshrs - sum1) & " from " cstr(PurchBlks(i))
  14. msgbox str1 ' only to show you the result.
you can improve a lot this code (it's not even good), but i think it'll give you an idea. (the first thing you must add is an UNTIL, after the loop, because if you get to the last index and you never reach Saleshr, it'll show you an error)

HTH
Feb 29 '08 #2
if1467
25
It seems like a homework to me ^.^

Anyway, you shouldnt have any trouble using a DO / LOOP :

lets say PurchBlks is an array of doubles (of one dimension), which first index is zero:
Expand|Select|Wrap|Line Numbers
  1. dim i as long
  2. dim Str1 as string
  3. dim Sum as double 'if you dont care about the value of Saleshrs after the result is given, you can skip this variable and just make substractions to Saleshrs.
  4.  
  5. do
  6.     sum1=sum1 + PurchBlks(i)
  7.     if sum > Saleshrs then exit do
  8.     str1 = cstr(PurchBlks(i)) & ", "
  9.     i= i+1
  10. loop
  11.  
  12. sum1=sum1 - PurchBlks(i)
  13. str1 = str1 & " and " Saleshrs - sum1 & " from " cstr(PurchBlks(i))
  14. msgbox str1 ' only to show you the result.
you can improve a lot this code (it's not even good), but i think it'll give you an idea. (the first thing you must add is an UNTIL, after the loop, because if you get to the last index and you never reach Saleshr, it'll show you an error)

HTH
Thanks, I'll have to take a look at this on Monday, since it is for my full-time job as an investment accountant which is Mon-Fri 9-5. :)
Feb 29 '08 #3
kadghar
1,295 Expert 1GB
Thanks, I'll have to take a look at this on Monday, since it is for my full-time job as an investment accountant which is Mon-Fri 9-5. :)
My apologies.
But we're not supposed to answer homeworks, but as i answered it, it's clear that i really didnt think it was so.
Once again, im sorry, i didnt pretend to be rude.
Feb 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Steven T. Hatton | last post by:
I read Stroustrup's article of the day: http://www.research.att.com/~bs/C++.html Programming with Exceptions. InformIt.com. April 2001. http://www.research.att.com/~bs/eh_brief.pdf Some of...
5
by: Miyra | last post by:
Hi. I'm working with an app that uses exceptions for control flow. These are code blocks where exceptions are thrown/caught regularly. A couple hundred exceptions occur per hour and they're caught...
3
by: jiing | last post by:
Now I am try to transfer a memory pointer between two threads. but there has a error mesage. _CrtIsValidHeapPointer(pUserData) in dbgheap.c I lookup google and find it's seems to be the local...
3
by: Vinay Jain | last post by:
select *, lower(name) from student; gives error: could not find block containing chunk 0x8483530 what does this error mean & what may be the cause? template1=# \d student Table...
8
by: ma740988 | last post by:
Consider this statement in Excel's text Thinking in C++, Vol 2: /// 1 " A vector starts by grabbing a block of storage, as if it's taking a guess at how many objects you plan to put into it. ...
165
by: Dieter | last post by:
Hi. In the snippet of code below, I'm trying to understand why when the struct dirent ** namelist is declared with "file" scope, I don't have a problem freeing the allocated memory. But...
14
by: Adam H. Peterson | last post by:
Is there a way (idiom, construct, anything like that) to divorce the scope of a try block from the region of code where it will catch the exception? I mean, suppose I have a code snippet like...
5
by: i.c.code | last post by:
maybe like: #include "boost/function.hpp" template <typename T> class Do_When_Return { private: Do_When_Return(const Do_When_Return&); Do_When_Return();
7
by: John A Grandy | last post by:
I'm trying to get a decent idea of the relative performance of three types of implementations of data-access classes in ASP.NET 2.0. I believe this boils down to a more basic question regarding...
5
by: Tiglath | last post by:
We are building a high performance system and suddenly the cost of using exception has been magnified. What is the actual cost of having a frequent call inside a try-catch block when the vast...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.