PDA

View Full Version : how to write a vba code to perform complex calculations



nutman
05-17-2012, 06:36 PM
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

nutman
05-17-2012, 06:41 PM
so desperate for help... all suggestions are welcome :D

nutman
05-17-2012, 07:33 PM
anyone??

Paul_Hossler
05-17-2012, 07:34 PM
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

Kenneth Hobs
05-17-2012, 07:36 PM
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.

nutman
05-17-2012, 07:43 PM
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

Kenneth Hobs
05-17-2012, 08:34 PM
To see what the area moment of Inertia means, see http://www.engineeringtoolbox.com/area-moment-inertia-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%20engg%20calculator/beam.htm
http://www.engineeringtoolbox.com/beam-stress-deflection-d_1312.html
http://www.wa4dsy.net/robot/bending

nutman
05-17-2012, 08:41 PM
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.

Kenneth Hobs
05-17-2012, 09:01 PM
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.

Kenneth Hobs
05-18-2012, 08:14 PM
I don't have time to check this much. It should be about 95% complete.

Paul_Hossler
05-19-2012, 06:35 AM
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:think:

Paul

Kenneth Hobs
05-19-2012, 06:45 PM
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...

Paul_Hossler
05-20-2012, 06:47 AM
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 :mbounce2:


Paul