Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reusing conditional statements? 1

Status
Not open for further replies.

mehr27

Structural
Dec 18, 2001
27
This is structural in nature but could apply to any subject:

I have set up a set of
Code:
if
statements that will output a rebar diameter based on rebar size. That's no problem.

Code:
bar_diameter := |0.375 in if bar_size = 3 
                |0.500 in if bar_size = 4
(etc.)

However, I have several different bar sizes within a structure. I am trying to define different diameters depending on the location (i.e. bar_diameter_compression, bar_diameter_tension) without having to redefine my conditional statement above to suit each location (i.e. bar_size_compression, bar_size_tension) since a bar size has a specific diameter regardless of location.

Any way of using this one definition above to suit every location and keep it local to whichever bar I am working with? Is there a better way of defining this (something like a case statement)? Sorry about being so wordy.
 
Replies continue below

Recommended for you


I wish you'd been more prolix! As I understand it you want to define the conditional statement once, and then have local values for the returned diameter.

I am not conversant with the structure shown, but why not set up a matrix of bar diameters, with say the rows being the size and the columns being the flag that defines the local condition (say column 0 for tension, 1 for compression etc etc)
.

Then define a function to refer to the matrix elements.

I'm not sure if this will work by picking up the local value of flag, you may have to include that in the function call, so you would have to

1)define your matrix

2) write your function

bar_diameter(f,bs):=matrix[bs,f]

or just return the matrix result directly, which is not as clear

3)Then call it with

newbardia:=bar_diameter(flag,barsize)


Is that clear?


Cheers

Greg Locock
 
I use a matrix method as follows:

bar_dia := {0.00 0.00 0.375 0.500 0.625 0.750 0.875 1.00 etc.}

a.s := {0.00 0.00 0.11 0.20 0.31 0.44 0.60 0.79, etc.}

Note the first to 0's.. this means that the position is the rebar size.

so a.s[7 gives me the area of steel for a #7 bar and bar_dia[7 gives me the diameter.

Imagineer
 
but that doesn't give him different bar diameters for a given size depending on the local condition.

Cheers

Greg Locock
 
Thanks for all the input. My last response did not go through.

I agree with the idea of building a matrix. I made 3 matrices (bar, diam, area) since they are different units, which can be used for the entire sheet. I made a pull-down menu of all bar sizes and by selecting a size, it stored the index of the selected bar. When I select
Code:
bar_size_tens := 6[\code] (from the menu), the program returns the index, [code]bar_size_tens = 4[\code] (bar #'s start at 3).

Finally,  [code]bar_diameter_tens := diam[bar_size_tens[\code]. Then I recreate the menu for different locations (i.e.  [code]bar_size_comp :=[\code] same pull-down menu).
 
Greg,
Huh? There is only one diameter for a given bar_size. Did I misunderstand your post? [3eyes] Imagineer
 
No, he wanted a bar diameter depending on the (quote) I am trying to define different diameters depending on the location (i.e. bar_diameter_compression, bar_diameter_tension)


So he wants a 2d array Cheers

Greg Locock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor