Posted by Dom on Monday, July 8, 2013 at 6:20am.
I'm trying to write a sub that asks how much oil I made, and then gives me number of barrels needed to hold oil, cost of producing oil, and profit from oil. This is what I have so far, I'm not sure what to do.
Dim barrels As Variant
Dim tons As Integer
InputBox "How many tons of oil were produced?"
Barrels = Gallons / 10
cost = 0.38 * Barrels
profit = 0.27 * Barrels
MsgBox "" & Barrels & " barrels needed to hold milk"
MsgBox "Cost of producing oil = " & cost & ""
MsgBox "Profit of producing oil = " & profit & ""
- Vba - Dom, Monday, July 8, 2013 at 6:53am
sorry, the input box above is supposed to ask how many gallons* of oil were produced
- Vba - MathMate, Monday, July 8, 2013 at 7:48am
First, the concept of sub programs is to isolate a particular calculation and make a "black box" which returns a "complicated" answer without having to worry about how it is done.
On the other hand, the UI (user-interface) belongs to a separate element of your program which might change due to user feed-back, requirements etc.
It is usually considered good program design to separate the two elements so that changing one does not necessitate the modification of the other.
As you go later into OOP (object oriented programming), the concept will be more clear.
Here you have combined the two design elements together. VBA will allow you to do this, but do bear in mind that in larger programs, this is not a good idea.
In the program, the concept is quite clear: input - calculations - output.
However, You have not defined the variable Gallons, and a value has not been assigned to be before first use. So the sub will not run properly even if it compiles.
You need to store the value of gallons of oil. The syntax (I believe) should be
Gallons=object.InputBox("How many gallons of oil")
where "object" is the object in which the sub resides.
Answer This Question
More Related Questions
- macroeconomics - Suppose that France and Denmark both produce oil and olives. ...
- Math - An oil company owns two refineries. The daily production limits and ...
- Math - Tamara needs to buy motor oil to fill the 3 empty cylindrical barrels at...
- math help fast - During an oil change, each car needs 4 1/2 quarts of oil. ...
- math - Tema Oil Refinery ( TOR ) is the only company mandated to refine crude ...
- math help - Mr. Richards has two cars that he changes the oil in every four ...
- science - Questions about oil: 1. what is the main product we get from oil? 2. ...
- math - An oil company operates two Southern refineries. The Alabama facility ...
- math - fractions - Hello, I need help for my 5th grader...Solve the problem by ...
- chemistry - Looking up the specifications of an oil online, the spec sheet ...