our simple example vb component will take the name and the age of a user and then return a string stating the user's age in number of days. there will also be an optional setting that can indicate which users are at least 45 years old, just in case they have forgotten.
so if we send a fictional name (unrelated to any known idol of mine) to our component as the value of the method's first parameter, say eric clapton, and an arbitrary age like56 as the value of the second parameter, we'll get the following results returned as a string:
eric clapton is over 20440 days old.
if we set the optional third parameter to true, which emphasizes who is 45 or older, we'll get the following string retuned from our method:
eric clapton is over 20440 days old.
notice that our simple example method is, well, simple. it doesn't actually calculate how many days a person has been alive, it just returns how many days their age in years equals.
since there are three different variables being used -- the user's name, the user's age, and whether to indicate that they are 45 or older -- we'll need three method parameters to carry this information from the asp file to the vb code. when working with vb methods it's important to take into consideration what type of data you're working with. here we'll use a string for the user's name variable that will be named "strname." an integer will be used for the age variable, named "intage." a boolean type will be used for the optional middle- age indicator, named "blnageemphasison."
three method parameters (variables to be sent to the vb component's method code) of course, it's not the name that determines a variable's type, so we'll need to declare the type of each of the method parameters as we define our method. but first we need to start up vb in a way that will produce as a server-side component for us.
strname (string)
intage (integer)
blnageemphasison (boolean)
when you start up vb you'll see the new project window. select the new tab if it's not already selected. if you don't see the new project window when vb starts up, select file/new project from the menu at the top of vb. the new project window will have various icons displayed. select the activex dll icon by double-clicking it.
once vb loads a new activex dll project you'll see at least two open windows: the project window and the properties window. if either of these two windows are not displayed you can display either of them by selecting view from the vb menu (view/project explorer and view/properties window).
since vb inserts default names for the initial project (project1) and class (class1), we'll change these to exampleproject and exampleclass. if it's not already selected, select the default project name in the project window, typically project1. now select the default project name (project1) in the properties window, delete it, and enter exampleproject in its place. the name in the project window will simultaneously change to exampleproject as you type it into the properties window.
to the left of the newly entered project name in the project window there will be a small box with either a plus [+] or a minus [-] in it. if yours has a plus in it, select the [+] box so that it displays a minus. now the default class name (class1) will be displayed beneath the project name. select this default class name in the project window and change the default class name to exampleclass in the properties window.
now let's save our project (file/save project) using the names vb suggests for the class (exampleclass.cls) and the project (exampleproject.vbp). you'll be asked whether these names are acceptable as vb displays two windows, one after the other. vb will save the code that comprises your class in a file with a cls extension (although there's really no telling class code to save at this point). the project file has a vbp file extension where various settings, file names, and file locations of your project are saved. be sure to save your project and class files in a directory that makes sense to you.
now there's nothing left to do except to enter our vb method code. but first let's take a look at some of the property values for a server-side dll component.