while you're in the properties window with the exampleclass properties being displayed, take note that the instancing property is set to "5 multiuse." this property value will change if you switch your project's type to a standard exe project, so make sure it's set to "5 multiuse" before you compile a project if you have fooled around with the type setting of your project in the project properties window.
speaking of the project properties window, if you go to the vb menu and select "project/exampleproject properties..." it will be displayed. under the general tab selection of the "exampleproject - project propertied" window, you'll notice that the threading model at the bottom right-hand side is set to apartment threading. this will ensure that more than one visitor will be able to use individual instances of our component class at the same time. also, select the 'unattended execution' and 'retain in memory' options to avoid a memory leak bug in vb6.
now we need to use the code window in vb to enter our method code. if you don't have a window opened that has two drop-down boxes (typically showing general and declarations, at least initially), then select view/code from the vb menu. if your code window is totally blank, type in the following code, which will require all variables to be declared. the way a method is defined is sometimes called its "signature." this includes whether the method is a sub or a function, the method's scope (where it can successfully be called from), what type of variable the method returns if it's a function, the number and type of parameters, whether the parameter variables are passed by value or reference, whether the parameter variables are optional or not, and if the optional parameters have default values set for them or not.
option explicit
in the example code above, notice we've designed our method to be a public function. this means that any code outside of the component can successfully call this method because it's designated as "public." the method will also return a value back to the code that calls it because it's a function and not a sub (subs don't have return values). you can use "private" in place of public if you don't want code outside of the class to be able to call the method. using "friend" will let other classes in your project call your method, but not any code outside of your project.
public function examplemethod(byval strname as string, _
byval intage as integer, _
optional byval blnageemphasison as boolean = false) as string
since this is a function, we'll want to determine what type of value is sent back to the calling code. in our example, we'll be sending back a string so "as string" is attached to the end of the method definition. if no variable type is declared at the end of a method, it will return a variant.
here's what we have described in detail so far... this is a valid method and if you type this line of code into the code window, vb will accept it. as a courtesy to programmers everywhere, vb will even add a few spaces and place an "end function" statement beneath the method definition in order to close off this function's code section for us.
public function examplemethod() as string
our vb method is designed with three parameter variables that will be assigned values sent from our asp file code. the last of these three parameter variables will be optional, meaning its value can be validly sent or not sent. all method parameter variables used to receive values from code outside of the vb method itself need to be placed and declared between the vb method's parenthesis (). the variables that we declare as method parameters in this way can be used in the methods code just as if they were declared within the body of the method itself. the only difference is that the outside asp code will be determining their values.
so rather than declare our three variables within the body of our method, we'll declare them in the methods definition, e.g., between the parentheses. here are the three variables and their declared types: now we'll designate the last parameter variable as optional:
strname as string
intage as integer
blnageemphasis as boolean
each parameter variable that's not designated as optional must have a value sent to it by the calling code or an error will be thrown. there's a restriction to using optional parameter variables, however.
strname as string
intage as integer
optional blnageemphasis as boolean