Consulting

Results 1 to 13 of 13

Thread: how to write a vba code to perform complex calculations

  1. #1
    VBAX Newbie
    Joined
    May 2012
    Posts
    5
    Location

    how to write a vba code to perform complex calculations

    How do I write a VBA code to calculate the deflection of a beam for the following two cases: (i) Rectangular or Circular cross section
    (ii) Point load or Uniformly distributed load
    By using Input Boxs to choose between rectangular & circular cross section; and choose between point load and uniformly distributed load; and to select the material type.
    When Timber= 12,000 MPa
    Concrete= 28,000 MPa
    Metal 1= 200,000 MPa
    Metal 2= 78,500 MPa
    Metal 3= 150,000 MPa
    uniformly distributed load= 5wL^4/384EI
    point load = WL^3/48EI
    rectangular inertia = bd^3/12
    circular inertia = pi*D^4/64

  2. #2
    VBAX Newbie
    Joined
    May 2012
    Posts
    5
    Location
    so desperate for help... all suggestions are welcome

  3. #3
    VBAX Newbie
    Joined
    May 2012
    Posts
    5
    Location
    anyone??

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    Could you just use a worksheet formula and skip the InputBox?

    The calculations are a little ..... obscure.

    What's WL and EI and BD and D?

    What are the calculations?

    Paul

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Sounds like a homework problem. Typical forums rules don't allow such. You can get help on concepts though. Even if it was not homework, it is expected that you would help us help you by doing as much as you can first.

    When working on Engineering problems like this, you need to pay attention to what units you have. L would probably be meters. w, b, d, and D might be millimeters or centimeters. I would imagine that you would want the deflection to be in millimeters so your equations will have conversion factors.

    Work example problems out on paper with sample data. Then make your Userform. You should define somewhere what the terms mean. If you really want to dress up your program, make or get a graphic showing the input parameters with a diagram for each scenario. If nothing else, draw it out on Engineering paper, scan to PDF and then snip the PDF portions to graphic files. The diagrams are so simple you can make those by shapes in Excel and snip to a graphic file.

    Even if this is homework, there are several forums that can help you learn how to add controls to a Userform.

    Once you have some of these basics down, post the XLSM with these details if you get stuck on some concept.

    These are not complex equations.

  6. #6
    VBAX Newbie
    Joined
    May 2012
    Posts
    5
    Location
    Thanks,
    y = deflection (mm)
    L = span (mm)
    E = elastic modulus (MPa)
    I = moment of inertia (mm4)
    W = point load (N)
    w = uniformly distributed load (N/m)
    I dont know how to input the values in the equations for inertia so that the input box guides me to The load eqautations and then the Mpa for the materials

  7. #7
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    To see what the area moment of Inertia means, see http://www.engineeringtoolbox.com/ar...ia-d_1328.html.

    You can see some load diagrams at this site. How the beam is fixed determines what deflection equation you need. I assume that those equations are for simply supported beams and the point load is in the middle. This will give you an idea. http://www.clag.org.uk/beam.html

    There are some web based beam deflection calculators on the web. Once you complete your project, be sure to verify your answers manually or check some of these types of sites.
    e.g.
    http://www.calculatoredge.com/civil%...lator/beam.htm
    http://www.engineeringtoolbox.com/be...on-d_1312.html
    http://www.wa4dsy.net/robot/bending

  8. #8
    VBAX Newbie
    Joined
    May 2012
    Posts
    5
    Location
    I know the maths behind it... i dont know how to write a vba code to actually use an input box to choose between rectangular & circular cross section and from that choose between point load and uniformly distributed load; and to select the material type.

  9. #9
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    As I Illustrated by example, most use a ComboBox control for such. Other otpions might be OptionButton controls, ListBox, MultiPage, etc.

    For Load type, two Option button controls with an EditBox for w (N/m) and another for W (N). For the Section, one for Circular with Editbox control for Diameter (mm). One for Rectangular with b, d, and L EditBox controls. Make liberal use of Label controls to show what you want and what the units should be.

    When I make suggestions, it is not just for your benefit but for all others that might participate.

  10. #10
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I don't have time to check this much. It should be about 95% complete.
    Attached Files Attached Files

  11. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    Very nice Ken

    I didn't look at the math so much, but was playing around with some UI options for my suggestion for the OP.

    BTW -- One typo that might cause confusion is on the User Form the control was accidently named 'bBoxDiameter' instead of 'tBoxDiameter' as in the code.

    This is my offering to just demo some interactivity concepts (w/o any real math).

    After all, we have to leave something as an exercise to the reader

    Paul
    Attached Files Attached Files

  12. #12
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Thanks Paul! I was a bit sleepy and had to get up early today so I did not get time to check much as I said.

    For yours, you probably need d, w, and a W.

    When doing these sorts of things, if the textbox is near a diagram, they are a bit more clear. If you want to impress the teacher, first solve the math and then make it pretty with graphics. I am just a dull and boring guy though or so I have been told...

  13. #13
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    For yours, you probably need d, w, and a W.
    I never made the attempt to actually try and figure out the formulas from #1 so I 100% agree that the results are FUBAR.


    When doing these sorts of things, if the textbox is near a diagram, they are a bit more clear. If you want to impress the teacher, first solve the math and then make it pretty with graphics.

    I am just a dull and boring guy though or so I have been told...
    1. If I were doing it, I'd probably have a little image that changed based on the combination of buttons.

    2. No one here ever says that


    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •