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.
3 873
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: -
dim i as long
-
dim Str1 as string
-
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.
-
-
do
-
sum1=sum1 + PurchBlks(i)
-
if sum1> Saleshrs then exit do
-
str1 = cstr(PurchBlks(i)) & ", "
-
i= i+1
-
loop
-
-
sum1=sum1 - PurchBlks(i)
-
str1 = str1 & " and " cstr(Saleshrs - sum1) & " from " cstr(PurchBlks(i))
-
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
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: -
dim i as long
-
dim Str1 as string
-
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.
-
-
do
-
sum1=sum1 + PurchBlks(i)
-
if sum > Saleshrs then exit do
-
str1 = cstr(PurchBlks(i)) & ", "
-
i= i+1
-
loop
-
-
sum1=sum1 - PurchBlks(i)
-
str1 = str1 & " and " Saleshrs - sum1 & " from " cstr(PurchBlks(i))
-
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. :)
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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. ...
|
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...
|
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...
|
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();
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
|
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...
| |