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 - Tema Oil Refinery ( TOR ) is the only company mandated to refine crude ...
- science - Questions about oil: 1. what is the main product we get from oil? 2. ...
- 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 ...
- maths - Saudi Arabia has proven oil reserves of 2.63 1011 barrels. ...
- Chemistry - Hello! I was wondering why is it that it is safe to eat olive oil, ...
- math! - an oil well produceds 2500 barrels of oil during its firt month of ...
- economics - where was the first oil factory and is it still standing today What ...