Part 3. Description of a function code 1. Part 3. Description of a function code 2 As an example we will write a function code to find the outside diameter.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

EcoTherm Plus WGB-K 20 E 4,5 – 20 kW.
1 A B C
Trend for Precision Soil Testing % Zone or Grid Samples Tested compared to Total Samples.
Simplifications of Context-Free Grammars
Variations of the Turing Machine
AP STUDY SESSION 2.
1
Slide 1Fig 26-CO, p.795. Slide 2Fig 26-1, p.796 Slide 3Fig 26-2, p.797.
Slide 1Fig 25-CO, p.762. Slide 2Fig 25-1, p.765 Slide 3Fig 25-2, p.765.
& dding ubtracting ractions.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Addition and Subtraction Equations
David Burdett May 11, 2004 Package Binding for WS CDL.
We need a common denominator to add these fractions.
Local Customization Chapter 2. Local Customization 2-2 Objectives Customization Considerations Types of Data Elements Location for Locally Defined Data.
Create an Application Title 1Y - Youth Chapter 5.
Add Governors Discretionary (1G) Grants Chapter 6.
CALENDAR.
CHAPTER 18 The Ankle and Lower Leg
The 5S numbers game..
Media-Monitoring Final Report April - May 2010 News.
Break Time Remaining 10:00.
EE, NCKU Tien-Hao Chang (Darby Chang)
Turing Machines.
PP Test Review Sections 6-1 to 6-6
MM4A6c: Apply the law of sines and the law of cosines.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
1 2 Teeth and Function 3 Tooth structure 4 Dental Problems.
Regression with Panel Data
K ONTRAK PERKULIAHAN I Made Gatot K, ST. MT 1. PENILAIAN Kehadiran min 75 % : 5 % Tugas: 20 % Diskusi / Presentasi: 20 % UTS: 25 % UAS: 30 % TOTAL: 100%
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Biology 2 Plant Kingdom Identification Test Review.
Adding Up In Chunks.
FAFSA on the Web Preview Presentation December 2013.
MaK_Full ahead loaded 1 Alarm Page Directory (F11)
Facebook Pages 101: Your Organization’s Foothold on the Social Web A Volunteer Leader Webinar Sponsored by CACO December 1, 2010 Andrew Gossen, Senior.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
Artificial Intelligence
Before Between After.
Slide R - 1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Prentice Hall Active Learning Lecture Slides For use with Classroom Response.
12 October, 2014 St Joseph's College ADVANCED HIGHER REVISION 1 ADVANCED HIGHER MATHS REVISION AND FORMULAE UNIT 2.
Subtraction: Adding UP
: 3 00.
5 minutes.
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
1 Titre de la diapositive SDMO Industries – Training Département MICS KERYS 09- MICS KERYS – WEBSITE.
Static Equilibrium; Elasticity and Fracture
Essential Cell Biology
FIGURE 12-1 Op-amp symbols and packages.
Converting a Fraction to %
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
Clock will move after 1 minute
famous photographer Ara Guler famous photographer ARA GULER.
PSSA Preparation.
Copyright © 2013 Pearson Education, Inc. All rights reserved Chapter 11 Simple Linear Regression.
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Select a time to count down from the clock above
Copyright Tim Morris/St Stephen's School
1.step PMIT start + initial project data input Concept Concept.
A Data Warehouse Mining Tool Stephen Turner Chris Frala
1 Dr. Scott Schaefer Least Squares Curves, Rational Representations, Splines and Continuity.
Meat Identification Quiz
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
Presentation transcript:

Part 3. Description of a function code 1

Part 3. Description of a function code 2 As an example we will write a function code to find the outside diameter of a carbon steel pipe, with input nominal diameter in inches.

Part 3. Description of a function code 3 As an example we will write a function code to find the outside diameter of a carbon steel pipe, with input nominal diameter in inches. The name of the function will be

Part 3. Description of a function code 4 "Pipe_Imp_CS_Dext_dn_sch" As an example we will write a function code to find the outside diameter of a carbon steel pipe, with input nominal diameter in inches. The name of the function will be

Part 3. Description of a function code 5 "Pipe_Imp_CS_Dext_dn_sch" As an example we will write a function code to find the outside diameter of a carbon steel pipe, with input nominal diameter in inches. The name of the function will be This function is based on outside diameters defined in ASME B36.10M

Part 3. Description of a function code 6 "Pipe_Imp_CS_Dext_dn_sch" As an example we will write a function code to find the outside diameter of a carbon steel pipe, with input nominal diameter in inches. The name of the function will be This function is based on outside diameters defined in ASME B36.10M A table with the outside diameters "dext [mm]", corresponding to the nominal diameters "dn [in]", should be included on a sheet in the Excel file. The function will read the information from this sheet.

7 The following table shows outside diameters and thicknesses for carbon steel pipes of different nominal diameters and schedules, according to the standard ASME B36. 10

8

9 Function code for the exterior diameter

10 Function code for the exterior diameter As explained in Part 1, the code starts by defining the function name and Visual Basic adds the "End Function".

11 Function code for the exterior diameter As explained in Part 1, the code starts by defining the function name and Visual Basic adds the "End Function". Function Pipe_Imp_CS_Dext_dn(Dn) End Function

12 The exterior diameter depends only on the nominal diameter (Dn) and is in the third column of the table.

13

14 The code begins by defining the matrix "C" containing rows 1 through 36 and columns 1 through 3.

15

16 Matrix "C" in whose third column from rows 7 to 36 are the exterior diameters "OD [mm]"

17 Next, it will be defined in the code, the array dimension of "C"

18 Dim C(36, 3) Function Pipe_Imp_CS_Dext_dn(Dn) End Function

19 Dim C(36, 3) Function Pipe_Imp_CS_Dext_dn(Dn) End Function The matrix C is defined with 36 columns and 3 rows

20 Reading of the table

21 Reading of the table To read the information in the table, one uses a structure called For-next

22 Reading of the table To read the information in the table, one uses a structure called For-next The For-next indicates to repeat an operation that depends on an index "m" and indicates the start and end values of "m".

23 Reading of the table To read the information in the table, one uses a structure called For-next The For-next indicates to repeat an operation that depends on an index "m" and indicates the start and end values of "m". For m = 1 To 36

24 Reading of the table To read the information in the table, one uses a structure called For-next The For-next indicates to repeat an operation that depends on an index "m" and indicates the start and end values of "m". For m = 1 To 36 In this space are introduced the operations to be performed, which depend on the temporal value of the index "m"

25 Reading of the table To read the information in the table, one uses a structure called For-next The For-next indicates to repeat an operation that depends on an index "m" and indicates the start and end values of "m". For m = 1 To 36 In this space are introduced the operations to be performed, which depend on the temporal value of the index "m" The operations with the index "m" end with

26 Reading of the table To read the information in the table, one uses a structure called For-next The For-next indicates to repeat an operation that depends on an index "m" and indicates the start and end values of "m". For m = 1 To 36 In this space are introduced the operations to be performed, which depend on the temporal value of the index "m" Next m The operations with the index "m" end with

27 Reading of the table To read the information in the table, one uses a structure called For-next The For-next indicates to repeat an operation that depends on an index "m" and indicates the start and end values of "m". For m = 1 To 36 In this space are introduced the operations to be performed, which depend on the temporal value of the index "m" Next m The operations with the index "m" end with The loop ends after the operation with index "m = 36" is performed.

28 The For-next is programed as follows

29 The For-next is programed as follows

30 The For-next is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read

31 The For-next is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read

32 The For-next is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read The read value is assigned to the element (m, 3) of the matrix "C"

33 The For-next is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read The read value is assigned to the element (m, 3) of the matrix "C"

34 The For-next is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read The reading is done in the sheet that has been named 6.CS_Imp The read value is assigned to the element (m, 3) of the matrix "C"

35 The For-next is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read The reading is done in the sheet that has been named 6.CS_Imp The read value is assigned to the element (m, 3) of the matrix "C"

36 The For-next is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read The reading is done in the sheet that has been named 6.CS_Imp The read value is assigned to the element (m, 3) of the matrix "C" On sheet "6.CS_Imp" it must be read the contents of the cell (m, 3)

37 Summary of programming steps

38 Summary of programming steps Function

39 Summary of programming steps Function Pipe_Imp_CS_Dext_dn(Dn) End Function

40 Summary of programming steps Function Pipe_Imp_CS_Dext_dn(Dn) End Function Dim C(36, 3)

41 Summary of programming steps Function Pipe_Imp_CS_Dext_dn(Dn) End Function Dim C(36, 3) For m = 1 To 36

42 Summary of programming steps Function Pipe_Imp_CS_Dext_dn(Dn) End Function Dim C(36, 3) For m = 1 To 36 C(m, 3) = thisWorkbook.Worksheets("6.CS_Imp").Cells(m, 3).Value

43 Summary of programming steps Function Pipe_Imp_CS_Dext_dn(Dn) End Function Dim C(36, 3) For m = 1 To 36 C(m, 3) = thisWorkbook.Worksheets("6.CS_Imp").Cells(m, 3).Value Next m

44 Identification of the row in which each nominal diameter is found

45 Identification of the row in which each nominal diameter is found By associating the nominal diameter to its row in the matrix, one knows the row where the rest of the data related to this diameter is located in the matrix.

46

47 Identification of the row in which each nominal diameter is found By associating the nominal diameter to its row in the matrix, one knows the row where the rest of the data related to this diameter is located in the matrix. En el código se agrega la siguiente línea

48 Identificación de la fila en que se encuentra cada diámetro nominal Al asociar el diámetro nominal del caso a su fila en la matriz, se conoce la ubicación de la fila de todos los datos correspondientes a ese diámetro. En el código se agrega la siguiente línea If Dn = 0.5 Then x = 7

49 Identificación de la fila en que se encuentra cada diámetro nominal Al asociar el diámetro nominal del caso a su fila en la matriz, se conoce la ubicación de la fila de todos los datos correspondientes a ese diámetro. En el código se agrega la siguiente línea If Dn = 0.5 Then x = 7 Cuyo significado es Si Dn tiene el valo 0.5 [in] entonces se trata de la fila 7

50 Identificación de la fila en que se encuentra cada diámetro nominal Al asociar el diámetro nominal del caso a su fila en la matriz, se conoce la ubicación de la fila de todos los datos correspondientes a ese diámetro. En el código se agrega la siguiente línea If Dn = 0.5 Then x = 7 Cuyo significado es Si Dn tiene el valo 0.5 [in] entonces se trata de la fila 7 La siguiente línea es

51 Identificación de la fila en que se encuentra cada diámetro nominal Al asociar el diámetro nominal del caso a su fila en la matriz, se conoce la ubicación de la fila de todos los datos correspondientes a ese diámetro. En el código se agrega la siguiente línea ElseIf Dn = 0.75 Then x = 8 If Dn = 0.5 Then x = 7 Cuyo significado es Si Dn tiene el valo 0.5 [in] entonces se trata de la fila 7 La siguiente línea es

52 Identificación de la fila en que se encuentra cada diámetro nominal Al asociar el diámetro nominal del caso a su fila en la matriz, se conoce la ubicación de la fila de todos los datos correspondientes a ese diámetro. En el código se agrega la siguiente línea Cuyo significado es O Si Dn tiene el valor 0.75 [in], se trata de la fila 8 ElseIf Dn = 0.75 Then x = 8 If Dn = 0.5 Then x = 7 Cuyo significado es Si Dn tiene el valo 0.5 [in] entonces se trata de la fila 7 La siguiente línea es

53 Identificación de la fila en que se encuentra cada diámetro nominal By associating the nominal diameter to its row in the matrix, one knows the row where the rest of the data related to this diameter is located in the matrix. En el código se agrega la siguiente línea Cuyo significado es O Si Dn tiene el valor 0.75 [in], se trata de la fila 8 ElseIf Dn = 0.75 Then x = 8 If Dn = 0.5 Then x = 7 Y así sucesivamente hasta identificar todas las filas Cuyo significado es Si Dn tiene el valo 0.5 [in] entonces se trata de la fila 7 La siguiente línea es

54 Identification of the row in which each nominal diameter is found By associating the nominal diameter to its row in the matrix, one knows the row where the rest of the data related to this diameter is located in the matrix. In the code we add the following line Whose meaning is Or if Dn has the value 0.75 [in], then it is row 8 ElseIf Dn = 0.75 Then x = 8 If Dn = 0.5 Then x = 7 And so on until all all rows are identified With these two new lines, the code looks like Whose meaning is If Dn has the values 0.5 [in] then the row is row 7 The next line is

55 Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) For m = 1 To 36 C(m, 3) = ThisWorkbook.Worksheets("6.CS_Imp").Cells(m, 3).Value Next m If Dn = 0.5 Then x = 7 ElseIf Dn = 0.75 Then x = 8 End Function

56 And with all the rows identified, this part of the code looks like

57 Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) For m = 1 To 36 C(m, 3) = ThisWorkbook.Worksheets("6.CS_Imp").Cells(m, 3).Value Next m If Dn = 0.5 Then x = 7 ElseIf Dn = 0.75 Then x = 8 ElseIf Dn = 1 Then x = 9 ElseIf Dn = 1.5 Then x = 10 ElseIf Dn = 2 Then x = 11 ElseIf Dn = 3 Then x = 12 ElseIf Dn = 4 Then x = 13 ElseIf Dn = 5 Then x = 14 ElseIf Dn = 6 Then x = 15 ElseIf Dn = 8 Then x = 16 ElseIf Dn = 10 Then x = 17 ElseIf Dn = 12 Then x = 18 ElseIf Dn = 14 Then x = 19 ElseIf Dn = 16 Then x = 20 ElseIf Dn = 18 Then x = 21 ElseIf Dn = 20 Then x = 22 ElseIf Dn = 22 Then x = 23 ElseIf Dn = 24 Then x = 24 ElseIf Dn = 26 Then x = 26 ElseIf Dn = 28 Then x = 26 ElseIf Dn = 30 Then x = 27 ElseIf Dn = 32 Then x = 28 ElseIf Dn = 34 Then x = 29 ElseIf Dn = 36 Then x = 30 ElseIf Dn = 38 Then x = 31 ElseIf Dn = 40 Then x = 32 ElseIf Dn = 42 Then x = 33 ElseIf Dn = 44 Then x = 34 ElseIf Dn = 46 Then x = 35 ElseIf Dn = 48 Then x = 36 ' If the Dn-value is not within the given values, ' The function returns Dext = "N/A" Else Pipe_Imp_CS_Dext_dn = "N/A" Exit Function End If

58 A resume of the code is

59 Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) For m = 1 To 36 C(m, 3) = ThisWorkbook.Worksheets("6.CS_Imp").Cells(m, 3).Value Next m If Dn = 0.5 Then x = 7 ElseIf Dn = 0.75 Then x = 8 ElseIf Dn = 1 Then x = 9 ElseIf Dn = 1.5 Then x = 10 ElseIf Dn = 2 Then x = 11 ElseIf Dn = 44 Then x = 34 ElseIf Dn = 46 Then x = 35 ElseIf Dn = 48 Then x = 36 ' If the Dn-value is not within the given values, ' The function returns Dext = "N/A" Else Pipe_Imp_CS_Dext_dn = "N/A" Exit Function End If

60 Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) For m = 1 To 36 C(m, 3) = ThisWorkbook.Worksheets("6.CS_Imp").Cells(m, 3).Value Next m If Dn = 0.5 Then x = 7 ElseIf Dn = 0.75 Then x = 8 ElseIf Dn = 1 Then x = 9 ElseIf Dn = 1.5 Then x = 10 ElseIf Dn = 2 Then x = 11 ElseIf Dn = 44 Then x = 34 ElseIf Dn = 46 Then x = 35 ElseIf Dn = 48 Then x = 36 ' If the Dn-value is not within the given values, ' The function returns Dext = "N/A" Else Pipe_Imp_CS_Dext_dn = "N/A" Exit Function End If This part of the function concludes saying, "Else" that is, in another case, if the nominal diameter received as input is not one of those reviewed, then the input is wrong. The function finish giving the answer Not Applicable (N / A)

61 If the input value of the nominal diameter corresponds to one of the values defined in the standard, it means that in the recently made review, the "x value" of the line corresponding to the nominal diameter has been identified.

62 If the input value of the nominal diameter corresponds to one of the values defined in the standard, it means that in the recently made review, the "x value" of the line corresponding to the nominal diameter has been identified. Thus, the value of x is a known value

63 If the input value of the nominal diameter corresponds to one of the values defined in the standard, it means that in the recently made review, the "x value" of the line corresponding to the nominal diameter has been identified. Known the matrix row in which the required exterior diameter is (row "x"), and as it is also known that this diameter is in column "3", the element of array with the desired value is the element (x, 3) Thus, the value of x is a known value

64 If the input value of the nominal diameter corresponds to one of the values defined in the standard, it means that in the recently made review, the "x value" of the line corresponding to the nominal diameter has been identified. Known the matrix row in which the required exterior diameter is (row "x"), and as it is also known that this diameter is in column "3", the element of array with the desired value is the element (x, 3) Thus, the value of the desired function is Thus, the value of x is a known value

65 If the input value of the nominal diameter corresponds to one of the values defined in the standard, it means that in the recently made review, the "x value" of the line corresponding to the nominal diameter has been identified. Pipe_Imp_CS_Dext_dn = C(x, 3) Known the matrix row in which the required exterior diameter is (row "x"), and as it is also known that this diameter is in column "3", the element of array with the desired value is the element (x, 3) Thus, the value of the desired function is Thus, the value of x is a known value

66 If the input value of the nominal diameter corresponds to one of the values defined in the standard, it means that in the recently made review, the "x value" of the line corresponding to the nominal diameter has been identified. Pipe_Imp_CS_Dext_dn = C(x, 3) Known the matrix row in which the required exterior diameter is (row "x"), and as it is also known that this diameter is in column "3", the element of array with the desired value is the element (x, 3) Thus, the value of the desired function is With this, the function is finished Thus, the value of x is a known value

67 The complete code is

68 Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) As Variant For m = 1 To 36 C(m, 3) = ThisWorkbook.Worksheets("6.CS_Imp").Cells(m, 3).Value Next m x = 7 ElseIf Dn = 0.75 Then x = 8 ElseIf Dn = 1 Then x = 9 ElseIf Dn = 1.5 Then x = 10 ElseIf Dn = 2 Then x = 11 ElseIf Dn = 3 Then x = 12 ElseIf Dn = 4 Then x = 13 ElseIf Dn = 5 Then x = 14 ElseIf Dn = 6 Then x = 15 ElseIf Dn = 8 Then x = 16 ElseIf Dn = 10 Then x = 17 ElseIf Dn = 12 Then x = 18 ElseIf Dn = 14 Then x = 19 ElseIf Dn = 16 Then x = 20 ElseIf Dn = 18 Then x = 21 ElseIf Dn = 20 Then x = 22 ElseIf Dn = 22 Then x = 23 ElseIf Dn = 24 Then x = 24 ElseIf Dn = 26 Then x = 26 ElseIf Dn = 28 Then x = 26 ElseIf Dn = 30 Then x = 27 ElseIf Dn = 32 Then x = 28 ElseIf Dn = 34 Then x = 29 ElseIf Dn = 36 Then x = 30 ElseIf Dn = 38 Then x = 31 ElseIf Dn = 40 Then x = 32 ElseIf Dn = 42 Then x = 33 ElseIf Dn = 44 Then x = 34 ElseIf Dn = 46 Then x = 35 ElseIf Dn = 48 Then x = 36 Else Pipe_Imp_CS_Dext_dn = "N/A" Exit Function End If Pipe_Imp_CS_Dext_dn = C(x, 3) End Function

69 End of Part 3 Note. In the web page "piping-tools.net", in the file Pipe dimensions and friction factor.xlsm, there are three functions (outside diameter, inside diameter and thickness) with complete code.