# 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.

## Presentation on theme: "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."— 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

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.

Download ppt "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."

Similar presentations