How To Expose and Use ENUMS from Visual Basic Components in Active Server Pages (261250)



The information in this article applies to:

  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual InterDev 6.0

This article was previously published under Q261250

SUMMARY

This article demonstrates how to use ENUMS that are built in Visual Basic (VB) components in the Active Server Pages (ASP) code. This method provides an alternative for .inc files with CONSTANTS.

MORE INFORMATION

Step-by-Step Example

  1. Open a new ActiveX DLL Visual Basic project.
  2. Rename Project1 to PrjEnum, and rename Class1 to ClsEnum.
  3. Copy the following code to ClsEnum:
    Public Enum Salsa
        Mild
        Medium
        Hot
    End Enum
    
    Public Function test(var As Salsa) As String
        Select Case var
            Case Mild
                test = "Can I get a Mild Salsa"
            Case Medium
                test = "Can I get a Medium Salsa"
            Case Hot
                test = "Can I get a Hot Salsa"
            Case Else
                test = "No thanks!"
        End Select
    End Function
    					
  4. Compile and make the PrjEnum.dll.
  5. Create a blank Global.asa file, and then add the following line to the Global.asa file:
    <!-- METADATA TYPE="typelib" FILE="c:\MyProjects\PrjEnum\PrjEnum.dll" -->
    Note Make sure that the file path that is referenced in the METADATA tag is correct.
  6. Create a blank ASP page in the same folder where the Global.asa file is created, copy the following code, and then save the .asp page:
    <%
    	Dim Obj
    	Set Obj = Server.CreateObject("prjEnum.clsEnum")
    	response.write "What kind of salsa would you like?<BR>"
    	response.write Obj.test(Hot)
    	set obj = NOTHING
    %>
  7. In your browser, browse to the new .asp page to check the results.

Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbhowto KB261250