![]() ![]() The Output after pressing the buy decision button Figure 14.A button-like control used to manage (and show) a color (WindowLess version) Public Sub buy_decision(size As Integer, price As Single)ĭim shoe_size As Integer, shoe_price As Single If the size and priceĮntered fufilled the requirement via the If.Then.Else statement, buy is assigned a value of true, else it is assigned a value of false. A boolean variable buy is included to help in decision making. In this program, we create a sub procedure known as buy_decision This program determines buying decision based on shoe' size and its price. Running the program produces a message boxes as shown in Figure 14.3a and Figure 14.3b Figure 14.3a Figure 14.3b Example 14.3b The main program can reference a procedure by using its name together with the arguments in the parentheses. In this example, we create a sub procedure to sum up two values that are specified by the arguments. The structure of a sub procedure is as follows: A sub procedure begins with a Sub ProcedureName keyword and ends with an End Sub keyword. Sub procedures help to make programs smaller and seamless to manage. ![]() It is called by other code whenever it is required to perform a certain task. It is a program code by itself and it is not an event procedure because it is not associated with a runtime procedure. It is different from function in the sense that it does not return a value as a function does.A sub procedure is usually used to accept input from the user, display information, print information, manipulate properties or perform some other tasks. ![]() Public Function grade(mark As Variant) As Stringįigure 14.2 The Design Interface 14.2 Creating Sub ProcedureĪ sub procedure(also call subroutine) is a procedure that is called from the main procedure to perform a specific task. The following program will automatically compute examination grades based on MsgBox ("The Future Value is" & FutureVal)įigure 14.1 The Output Interface Example 14.2 'This procedure will calculate Future ValueįutureVal = FV(PresentVal, interest, period) Public Function FV(PV As Variant, i As Variant, n As Variant) As Variant Supposing he will invest this amount of money somewhere. Money he has today based on the interest rate and the number of years from now, In this example, a user can calculate the future value of a certain amount of ![]() Private Function functionName(Arg As dataType.) As dataType If you wish to create a function that is applicable to a module or a sub procedure, you need to use the keyword Private, as follows: Public Function functionName(Arg As dataType.) As dataType The whole project, the syntax is as follows: If you wish to create a function that is applicable to ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |