< web  portfolio >

Brenda C. Mondragon

< Main Page >


ASP :: Functions & Subroutines


- Splitting ASP code into logical processing units by using functions and subroutines. Splitting ASP (VBScript) code into logical processing units by using functions and subroutines.



<%
'usernameCodes array holds the username (value 0) along with its associated tracking "code" (value 1)
    Dim usernameCodes(4,1)
    usernameCodes(0,0) = "guestuser"
    usernameCodes(0,1) = "GUEST"

    usernameCodes(1,0) = "administrator"
    usernameCodes(1,1) = "ADMIN"

    usernameCodes(2,0) = "dataentry"
    usernameCodes(2,1) = "DATA"

    usernameCodes(4,0) = "readonly"
    usernameCodes(4,1) = "READ"

'================================================='
'getPrefixUsername
'================================================='
function getPrefixUsername(ByVal pu_tracking_prefix)
    if pu_tracking_prefix <> "" then
        Dim x
        For x = 0 to Ubound(usernameCodes,1)
        if pu_tracking_prefix = usernameCodes(x,1) then
          getPrefixUsername = usernameCodes(x,0)
          Exit Function
        end if
        Next
        if pu_tracking_prefix = "OTHER" then
          Dim prefixesString, y
          For y = 0 to Ubound(usernameCodes,1)
            prefixesString = prefixesString + "'" + usernameCodes(y,0) + "'"
            if y < Ubound(usernameCodes,1) then prefixesString = prefixesString + "," end if
          Next
          getPrefixUsername = prefixesString
        end if
    end if
end function

...

if action = "search" then
    call searchForm
end if

...

'================================================='
'searchForm
'================================================='
sub searchForm
    if msg <> "" then
        Response.Write("<center><b><font color=""#FF0000"">" & msg & "</font></b></center>")
    end if
%>
    <form name="searchform" method="get" action="<%=thispagename%>">
    <input type="hidden" name="action" value="dosearch">
        <center>
            <b>SEARCH</b>
            <br clear="all">
            <br clear="all">
            <table border="0" cellspacing="0" cellpadding="15" bgcolor="#D6D6D6">
                <tr>
                    <td>
                        <input type="text" name="searchtext" size="50" maxlength="100">
                        <br clear="all">
                        <br clear="all">
                        <input type="radio" name="searchtype" value="number" checked onClick="document.searchform.searchtext.focus()"><b>Order Number</b><br clear="all">
                        <br clear="all">
                        <input type="radio" name="searchtype" value="name" onClick="document.searchform.searchtext.focus()"><b>Customer Name</b><br clear="all">
                        <br clear="all">
                        <input type="radio" name="searchtype" value="state" onClick="document.searchform.searchtext.focus()"><b>By State</b> <%=SelectUSStates("", "searchstate", 1)%><br clear="all">
                        <br clear="all">
                    </td>
                    <td valign="top"><input type="submit" value="FIND"></td>
                </tr>
            </table>
            <br clear="all">
            <br clear="all">
            <!--#include file="main_screen.asp"-->
            <br clear="all">
            <br clear="all">
            <!--#include file="../log_out.asp"-->

        </center>
    </form>
</body>
</html>
<%
end sub
%>

Categories:



< Main Page >

This portfolio powered by Blosxom

All content Copyright © 1995 - 2012 Brenda C. Mondragon