690 likes | 836 Vues
Part 3. Description of a function code. Part 3. Description of a function code. 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.
E N D
Part 3. Description of a function code 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 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 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 "Pipe_Imp_CS_Dext_dn_sch"
Part 3. Description of a function code 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 "Pipe_Imp_CS_Dext_dn_sch" This function is based on outside diameters defined in ASME B36.10M
Part 3. Description of a function code 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 "Pipe_Imp_CS_Dext_dn_sch" 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.
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
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 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
The exterior diameter depends only on the nominal diameter (Dn) and is in the third column of the table.
The code begins by defining the matrix "C" containing rows 1 through 36 and columns 1 through 3.
Matrix "C" in whose third column from rows 7 to 36 are the exterior diameters "OD [mm]"
Next, it will be defined in the code, the array dimension of "C"
Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) End Function
Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) End Function The matrix C is defined with 36 columns and 3 rows
Reading of the table To read the information in the table, one uses a structure called For-next
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".
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
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"
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
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 Next m
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 Next m The loop ends after the operation with index "m = 36" is performed.
The “ For-next” is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read
The “ For-next” is programed as follows This indicates that cells in column 3, from row 1 to 36, shall be read
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"
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"
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" The reading is done in the sheet that has been named 6.CS_Imp
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" The reading is done in the sheet that has been named 6.CS_Imp
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" The reading is done in the sheet that has been named 6.CS_Imp On sheet "6.CS_Imp" it must be read the contents of the cell (m, 3)
Summary of programming steps Function
Summary of programming steps Function Pipe_Imp_CS_Dext_dn(Dn) End Function
Summary of programming steps Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) End Function
Summary of programming steps Function Pipe_Imp_CS_Dext_dn(Dn) Dim C(36, 3) For m = 1 To 36 End Function
Summary of programming steps 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 End Function
Summary of programming steps 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 End Function
Identification of the row in which each nominal diameter is found
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.
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
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
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
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