20 likes | 183 Views
Here’s a sample function showing the use of the If then / else / end if construct. Function computes the volume of material in cone bottom silo. The silo’s radius is R, the height of the cones section is hc, and the height of the material in the silo is h. Units are assume to be consistent.
E N D
Here’s a sample function showing the use of the If then / else / end if construct. Function computes the volume of material in cone bottom silo. The silo’s radius is R, the height of the cones section is hc, and the height of the material in the silo is h. Units are assume to be consistent. Public Function SiloVolume1(h, hc, R) Dim rc As Single Dim pi As Single pi = WorksheetFunction.pi() SiloVolume1 = 0# If h < hc Then rc = h * R / hc SiloVolume1 = (1 / 3) * pi * rc ^ 2 * h Else SiloVolume1 = (1 / 3) * pi * R ^ 2 * hc + pi * R ^ 2 * (h - hc) End If ' and check to make sure h was => 0 If h < 0 Then SiloVolume1 = "Error -- h must be > 0" End Function
Some Form items “Sub”s are created for each object on the form. When viewing the code, the drop down list in left panel shows the items in the form and the list box in the right hand panel gives the various methods associated with the selected object. “Declaration s” can be found at the top of the drop down list in the left panel. When you compute a new value for R and set the text with the “plabel & v label /…” string, it should be assigned to lblR.caption, not just lblR ( or whatever you called your label box). The macro to run the form must be in a module, not in the form. So Insert / Module then Insert / Procedure and select Sub.