Vba

posted by .

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.

Sub Oil()

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 & ""
End Sub

  • Vba -

    sorry, the input box above is supposed to ask how many gallons* of oil were produced

  • Vba -

    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.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. math - fractions

    Hello, I need help for my 5th grader...Solve the problem by working backward. Write the ans. in a compl. sentence. Mara followed a recipe she found on the net to make her own perfume. She started by adding jojoba oil to a small bottle. …
  2. science

    Questions about oil: 1. what is the main product we get from oil?
  3. macroeconomics

    Suppose that France and Denmark both produce oil and olives. Frances’s opportunity cost of producing a crate of olives is 4 barrels of oil, while Denmark’s opportunity cost of producing a crate of olives is 7 barrels of oil. By …
  4. math

    Tema Oil Refinery ( TOR ) is the only company mandated to refine crude oil in Ghana. The company has estimated that the fixed cost would be $ 80000. Variable costs depends on the amount of crude oil refined but include the cost of …
  5. Math

    An oil company owns two refineries. The daily production limits and operating costs for each refinery are given in the table below. An order is received for 1540 barrels of high-grade oil, 1650 barrels of medium-grade oil, and 2860 …
  6. math help

    Mr. Richards has two cars that he changes the oil in every four months. During an oil change, each car needs 4 1/2 quarts of oil. Each 5-quart container of oil costs $14.99. Before tax, how much will the oil cost Mr. Richards for both …
  7. math help fast

    During an oil change, each car needs 4 1/2 quarts of oil. Each 5-quart container of oil costs $14.99. Before tax, how much will the oil cost Mr. Richards for both cars in a year?
  8. Math

    Tamara needs to buy motor oil to fill the 3 empty cylindrical barrels at her oil service center. Each barrel is 7ft deep and has a radius 4ft. What is the volume of oil needed?
  9. math

    An oil company operates two Southern refineries. The Alabama facility produces 500 barrels of high-grade oil and 200 barrels of medium-grade oil per day. The Texas facility produces 600 barrels of high-grade and 400 barrels of medium-grade …
  10. algebra

    the dollar price for a barrel of oil sold at a certain oil refinery tends to follow the demand equation below where x is the number of barrels of oils on the hand in ( millions ) a) how much should be charged for a barrel of oil if …

More Similar Questions