Custom tag function?

Discussion in 'ASP General' started by Hagge, Dec 31, 2003.

  1. Hagge

    Hagge Guest

    I'm stuck in a problem

    Hi I want to create a funtion in asp.
    Like this [userid=Smith] Then the function convert the "custom tag" to.
    <a href=www.mypage.com/user/Smith>Smith</a>

    How to do?
    I'm real stucked.

    // Hagge
    Hagge, Dec 31, 2003
    #1
    1. Advertising

  2. Hagge

    Ray at Guest

    Is this what you mean?

    <%
    Sub WriteUserHref(Username)
    Response.Write "<a href=""http://www.mypage.kom/user/" & Username &
    """>" & Username & "</a>"
    End Sub

    WriteUserHref "Smith"
    %>

    Ray at work

    "Hagge" <> wrote in message
    news:%...
    > I'm stuck in a problem
    >
    > Hi I want to create a funtion in asp.
    > Like this [userid=Smith] Then the function convert the "custom tag" to.
    > <a href=www.mypage.com/user/Smith>Smith</a>
    >
    > How to do?
    > I'm real stucked.
    >
    > // Hagge
    >
    >
    Ray at, Dec 31, 2003
    #2
    1. Advertising

  3. Hagge

    Hagge Guest

    I solved it, this is my function to be used like this...

    Response.write userLink("This will be a link to [userid=Hagge]")

    Will be displayed as...
    This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>


    Function userLink(sText)
    sFuncText=""
    Dim arrayWords(20000)
    arrWords = Split(sText," ")
    For iWords=0 to Ubound(arrWords)
    iStartLength = Int("0")
    iEndLength=0
    iStartLength = Int(Instr(arrWords(iWords),"[userid=")+8)
    iEndLength = Int(Instr(arrWords(iWords),"]"))
    iNameLength = Int(iEndLength-iStartLength)
    If iNameLength > Int("0") Then
    sFuncUserName = Mid(arrWords(iWords),iStartLength,iNameLength)
    SQL=""
    SQL=SQL & "SELECT sUserGUID"
    SQL=SQL & " FROM tblUsers"
    SQL=SQL & " WHERE sUserName='" & sFuncUserName & "'"
    Set rsName = db.execute( SQL )
    If NOT rsName.EOF Then
    sFuncText=sFuncText & "<a href=""userpage.asp?userid=" &
    rsName("sUserGUID") & """>" & sFuncUserName & "</a>"
    End If

    rsName.Close
    Set rsName = Nothing
    Else
    sFuncText=sFuncText & arrWords(iWords) & " "
    End If
    Next
    userLink = sFuncText
    End Function


    // Hagge



    "Hagge" <> wrote in message
    news:%...
    > I'm stuck in a problem
    >
    > Hi I want to create a funtion in asp.
    > Like this [userid=Smith] Then the function convert the "custom tag" to.
    > <a href=www.mypage.com/user/Smith>Smith</a>
    >
    > How to do?
    > I'm real stucked.
    >
    > // Hagge
    >
    >
    Hagge, Jan 2, 2004
    #3
  4. Hagge

    Brynn Guest

    Re: Custom tag function? (Easier For You)

    Just to help a little. There is no reason to have to build an array or
    have any loop for what you want to do with your function. The below
    should do what you are wanting to do, and much faster and easier to
    use.

    Response.Write "This will be a link to" & userLink("Hagge")

    will return...

    This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>

    I added also ... if Hagge is not in the usersTable ... it will return

    This will be a link to **Invalid username**

    Anyway, I hope the below function helps ... if yours is working, this
    one should work with no changes in my function. Also, it will be much
    easier to call since you are giving it the username only. The function
    only returns the link.




    <%
    Function userLink(theUserName)
    Dim theUserID, theSQLStatement, linkSentence

    theSQLStatement = "Select sUserGUID From tblUsers "
    theSQLStatement = theSQLStatement & "Where sUserName = '" &
    theUserName & "';"
    Set rsName = db.Execute(theSQLStatement)

    If Not rsName.EOF Then '//User Exists
    theUserID = rsName("sUserGUID")
    linkSentence = "<a href=""userpage.asp"
    linkSentence = linkSentence & "?userid=" & theUserID & """>"
    linkSentence = linkSentence & theUserName
    linkSentence = linkSentence & "</a>"
    Else '//User Doesn't Exist
    linkSentence = "**Invalid username**"
    End If

    rsName.Close
    Set rsName = Nothing

    userLink = linkSentence
    End Function



    Response.Write "This will be a link to " & userLink("Hagge")
    %>


    Brynn
    www.coolpier.com


    On Fri, 2 Jan 2004 18:29:57 +0100, "Hagge" <> wrote:

    >I solved it, this is my function to be used like this...
    >
    >Response.write userLink("This will be a link to [userid=Hagge]")
    >
    >Will be displayed as...
    >This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    >
    >
    >Function userLink(sText)
    > sFuncText=""
    > Dim arrayWords(20000)
    > arrWords = Split(sText," ")
    > For iWords=0 to Ubound(arrWords)
    > iStartLength = Int("0")
    > iEndLength=0
    > iStartLength = Int(Instr(arrWords(iWords),"[userid=")+8)
    > iEndLength = Int(Instr(arrWords(iWords),"]"))
    > iNameLength = Int(iEndLength-iStartLength)
    > If iNameLength > Int("0") Then
    > sFuncUserName = Mid(arrWords(iWords),iStartLength,iNameLength)
    > SQL=""
    > SQL=SQL & "SELECT sUserGUID"
    > SQL=SQL & " FROM tblUsers"
    > SQL=SQL & " WHERE sUserName='" & sFuncUserName & "'"
    > Set rsName = db.execute( SQL )
    > If NOT rsName.EOF Then
    > sFuncText=sFuncText & "<a href=""userpage.asp?userid=" &
    >rsName("sUserGUID") & """>" & sFuncUserName & "</a>"
    > End If
    >
    > rsName.Close
    > Set rsName = Nothing
    > Else
    > sFuncText=sFuncText & arrWords(iWords) & " "
    > End If
    > Next
    > userLink = sFuncText
    >End Function
    >
    >
    >// Hagge
    >
    >
    >
    >"Hagge" <> wrote in message
    >news:%...
    >> I'm stuck in a problem
    >>
    >> Hi I want to create a funtion in asp.
    >> Like this [userid=Smith] Then the function convert the "custom tag" to.
    >> <a href=www.mypage.com/user/Smith>Smith</a>
    >>
    >> How to do?
    >> I'm real stucked.
    >>
    >> // Hagge
    >>
    >>

    >
    >
    Brynn, Jan 3, 2004
    #4
  5. Hagge

    Hagge Guest

    Re: Custom tag function? (Easier For You)

    But say you type in...
    [userid=Hagge] and [userid=Smith]

    Will it convert both then, or just the first match?

    // Hagge

    "Brynn" <> wrote in message
    news:...
    > Just to help a little. There is no reason to have to build an array or
    > have any loop for what you want to do with your function. The below
    > should do what you are wanting to do, and much faster and easier to
    > use.
    >
    > Response.Write "This will be a link to" & userLink("Hagge")
    >
    > will return...
    >
    > This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    >
    > I added also ... if Hagge is not in the usersTable ... it will return
    >
    > This will be a link to **Invalid username**
    >
    > Anyway, I hope the below function helps ... if yours is working, this
    > one should work with no changes in my function. Also, it will be much
    > easier to call since you are giving it the username only. The function
    > only returns the link.
    >
    >
    >
    >
    > <%
    > Function userLink(theUserName)
    > Dim theUserID, theSQLStatement, linkSentence
    >
    > theSQLStatement = "Select sUserGUID From tblUsers "
    > theSQLStatement = theSQLStatement & "Where sUserName = '" &
    > theUserName & "';"
    > Set rsName = db.Execute(theSQLStatement)
    >
    > If Not rsName.EOF Then '//User Exists
    > theUserID = rsName("sUserGUID")
    > linkSentence = "<a href=""userpage.asp"
    > linkSentence = linkSentence & "?userid=" & theUserID & """>"
    > linkSentence = linkSentence & theUserName
    > linkSentence = linkSentence & "</a>"
    > Else '//User Doesn't Exist
    > linkSentence = "**Invalid username**"
    > End If
    >
    > rsName.Close
    > Set rsName = Nothing
    >
    > userLink = linkSentence
    > End Function
    >
    >
    >
    > Response.Write "This will be a link to " & userLink("Hagge")
    > %>
    >
    >
    > Brynn
    > www.coolpier.com
    >
    >
    > On Fri, 2 Jan 2004 18:29:57 +0100, "Hagge" <> wrote:
    >
    > >I solved it, this is my function to be used like this...
    > >
    > >Response.write userLink("This will be a link to [userid=Hagge]")
    > >
    > >Will be displayed as...
    > >This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    > >
    > >
    > >Function userLink(sText)
    > > sFuncText=""
    > > Dim arrayWords(20000)
    > > arrWords = Split(sText," ")
    > > For iWords=0 to Ubound(arrWords)
    > > iStartLength = Int("0")
    > > iEndLength=0
    > > iStartLength = Int(Instr(arrWords(iWords),"[userid=")+8)
    > > iEndLength = Int(Instr(arrWords(iWords),"]"))
    > > iNameLength = Int(iEndLength-iStartLength)
    > > If iNameLength > Int("0") Then
    > > sFuncUserName =

    Mid(arrWords(iWords),iStartLength,iNameLength)
    > > SQL=""
    > > SQL=SQL & "SELECT sUserGUID"
    > > SQL=SQL & " FROM tblUsers"
    > > SQL=SQL & " WHERE sUserName='" & sFuncUserName & "'"
    > > Set rsName = db.execute( SQL )
    > > If NOT rsName.EOF Then
    > > sFuncText=sFuncText & "<a href=""userpage.asp?userid=" &
    > >rsName("sUserGUID") & """>" & sFuncUserName & "</a>"
    > > End If
    > >
    > > rsName.Close
    > > Set rsName = Nothing
    > > Else
    > > sFuncText=sFuncText & arrWords(iWords) & " "
    > > End If
    > > Next
    > > userLink = sFuncText
    > >End Function
    > >
    > >
    > >// Hagge
    > >
    > >
    > >
    > >"Hagge" <> wrote in message
    > >news:%...
    > >> I'm stuck in a problem
    > >>
    > >> Hi I want to create a funtion in asp.
    > >> Like this [userid=Smith] Then the function convert the "custom tag" to.
    > >> <a href=www.mypage.com/user/Smith>Smith</a>
    > >>
    > >> How to do?
    > >> I'm real stucked.
    > >>
    > >> // Hagge
    > >>
    > >>

    > >
    > >

    >
    Hagge, Jan 5, 2004
    #5
  6. Hagge

    Brynn Guest

    Re: Custom tag function? (Easier For You)

    Here it is modified to handle more than one ... just enter a comma
    delimited string into the function. if only one username, don't use a
    comma.

    <%
    Function userLink(theUserNameList)
    Dim theUsernameSeperator
    theUsernameSeperator = "<b />"

    Dim theUserID, theSQLStatement, linkSentence

    Dim theUsernameArray, theUserName, n
    theUsernameArray = Split(theUserNameList, ",")

    For n = 0 to ubound(theUsernameArray)
    theUserName = theUsernameArray(n)

    theSQLStatement = "Select sUserGUID From tblUsers "
    theSQLStatement = theSQLStatement & "Where sUserName = '" &
    theUserName & "';"
    Set rsName = db.Execute(theSQLStatement)

    If Not rsName.EOF Then '//User Exists
    theUserID = rsName("sUserGUID")
    linkSentence = "<a href=""userpage.asp"
    linkSentence = linkSentence & "?userid=" & theUserID & """>"
    linkSentence = linkSentence & theUserName
    linkSentence = linkSentence & "</a>" & theUsernameSeperator
    Else '//User Doesn't Exist
    linkSentence = "**Invalid username ( " & & " )**"
    End If

    Next


    rsName.Close
    Set rsName = Nothing

    userLink = linkSentence
    End Function

    Response.Write "This will be a link to " & userLink("Hagge")
    %>


    I could make this faster using my DBConn.asp script. I would build a
    comma delimited list with each of the usernames between 2 single
    quotes. then I would use my cp_sqlArray function with a "select where
    in" statement so that you are only searching the database once. The
    code would look something like this

    I would also change this into a subroutine because performance will be
    better writing the code than building a string





    <!-- #include virtual="/coolpier_scripts/_database_tools/DBConn.asp"
    -->

    <%
    Sub userLinks(theUserNameList)
    '// Create the usersList for the sql in statement
    Dim usersList, usersArray
    usersList = "''" & Replace(theUserNameList, ",",
    "'',''") & "''"

    '// Get a 2-dimensional array of the results
    theSQL = "Select sUserGUID, sUserName " &_
    "From tblUsers " &_
    "Where sUserName IN (" & usersList & ");"
    usersArray = cp_sqlArray(theSQL)


    '//DISPLAY
    With Response

    If IsArray(usersArray) Then
    Dim theRows '//
    For theRows = 0 to ubound(usersArray,1)
    .Write "<a href=""userpage.asp"
    .Write "?userid=" & usersArray(0,n) & """>"
    .Write usersArray(1,n) & "</a>"
    .Write "<br />"
    Next
    Else
    .Write "No Users Found!"
    End If

    End With

    End Sub


    cp_TheConnectionString = "yourConnectionString"
    cp_DBConn("open")
    Call userLinks("Hagge, Smith")
    cp_DBConn("close")
    %>





    On Mon, 5 Jan 2004 01:24:00 +0100, "Hagge" <> wrote:

    >But say you type in...
    >[userid=Hagge] and [userid=Smith]
    >
    >Will it convert both then, or just the first match?
    >
    >// Hagge
    >
    >"Brynn" <> wrote in message
    >news:...
    >> Just to help a little. There is no reason to have to build an array or
    >> have any loop for what you want to do with your function. The below
    >> should do what you are wanting to do, and much faster and easier to
    >> use.
    >>
    >> Response.Write "This will be a link to" & userLink("Hagge")
    >>
    >> will return...
    >>
    >> This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    >>
    >> I added also ... if Hagge is not in the usersTable ... it will return
    >>
    >> This will be a link to **Invalid username**
    >>
    >> Anyway, I hope the below function helps ... if yours is working, this
    >> one should work with no changes in my function. Also, it will be much
    >> easier to call since you are giving it the username only. The function
    >> only returns the link.
    >>
    >>
    >>
    >>
    >> <%
    >> Function userLink(theUserName)
    >> Dim theUserID, theSQLStatement, linkSentence
    >>
    >> theSQLStatement = "Select sUserGUID From tblUsers "
    >> theSQLStatement = theSQLStatement & "Where sUserName = '" &
    >> theUserName & "';"
    >> Set rsName = db.Execute(theSQLStatement)
    >>
    >> If Not rsName.EOF Then '//User Exists
    >> theUserID = rsName("sUserGUID")
    >> linkSentence = "<a href=""userpage.asp"
    >> linkSentence = linkSentence & "?userid=" & theUserID & """>"
    >> linkSentence = linkSentence & theUserName
    >> linkSentence = linkSentence & "</a>"
    >> Else '//User Doesn't Exist
    >> linkSentence = "**Invalid username**"
    >> End If
    >>
    >> rsName.Close
    >> Set rsName = Nothing
    >>
    >> userLink = linkSentence
    >> End Function
    >>
    >>
    >>
    >> Response.Write "This will be a link to " & userLink("Hagge")
    >> %>
    >>
    >>
    >> Brynn
    >> www.coolpier.com
    >>
    >>
    >> On Fri, 2 Jan 2004 18:29:57 +0100, "Hagge" <> wrote:
    >>
    >> >I solved it, this is my function to be used like this...
    >> >
    >> >Response.write userLink("This will be a link to [userid=Hagge]")
    >> >
    >> >Will be displayed as...
    >> >This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    >> >
    >> >
    >> >Function userLink(sText)
    >> > sFuncText=""
    >> > Dim arrayWords(20000)
    >> > arrWords = Split(sText," ")
    >> > For iWords=0 to Ubound(arrWords)
    >> > iStartLength = Int("0")
    >> > iEndLength=0
    >> > iStartLength = Int(Instr(arrWords(iWords),"[userid=")+8)
    >> > iEndLength = Int(Instr(arrWords(iWords),"]"))
    >> > iNameLength = Int(iEndLength-iStartLength)
    >> > If iNameLength > Int("0") Then
    >> > sFuncUserName =

    >Mid(arrWords(iWords),iStartLength,iNameLength)
    >> > SQL=""
    >> > SQL=SQL & "SELECT sUserGUID"
    >> > SQL=SQL & " FROM tblUsers"
    >> > SQL=SQL & " WHERE sUserName='" & sFuncUserName & "'"
    >> > Set rsName = db.execute( SQL )
    >> > If NOT rsName.EOF Then
    >> > sFuncText=sFuncText & "<a href=""userpage.asp?userid=" &
    >> >rsName("sUserGUID") & """>" & sFuncUserName & "</a>"
    >> > End If
    >> >
    >> > rsName.Close
    >> > Set rsName = Nothing
    >> > Else
    >> > sFuncText=sFuncText & arrWords(iWords) & " "
    >> > End If
    >> > Next
    >> > userLink = sFuncText
    >> >End Function
    >> >
    >> >
    >> >// Hagge
    >> >
    >> >
    >> >
    >> >"Hagge" <> wrote in message
    >> >news:%...
    >> >> I'm stuck in a problem
    >> >>
    >> >> Hi I want to create a funtion in asp.
    >> >> Like this [userid=Smith] Then the function convert the "custom tag" to.
    >> >> <a href=www.mypage.com/user/Smith>Smith</a>
    >> >>
    >> >> How to do?
    >> >> I'm real stucked.
    >> >>
    >> >> // Hagge
    >> >>
    >> >>
    >> >
    >> >

    >>

    >
    >
    Brynn, Jan 5, 2004
    #6
  7. Hagge

    Brynn Guest

    Re: Custom tag function? (Easier For You)

    My DBConn.asp file is up on my site at www.coolpier.com

    click on Coolpier Scripts at the top left ... the click on the
    coolpier_scripts folder to go to the download page of my site

    The website is under total redesign, so bare with me ... the redesign
    is only a couple days old.



    On Mon, 05 Jan 2004 01:45:06 GMT, (Brynn) wrote:

    >Here it is modified to handle more than one ... just enter a comma
    >delimited string into the function. if only one username, don't use a
    >comma.
    >
    ><%
    >Function userLink(theUserNameList)
    > Dim theUsernameSeperator
    > theUsernameSeperator = "<b />"
    >
    > Dim theUserID, theSQLStatement, linkSentence
    >
    >Dim theUsernameArray, theUserName, n
    > theUsernameArray = Split(theUserNameList, ",")
    >
    >For n = 0 to ubound(theUsernameArray)
    > theUserName = theUsernameArray(n)
    >
    > theSQLStatement = "Select sUserGUID From tblUsers "
    > theSQLStatement = theSQLStatement & "Where sUserName = '" &
    >theUserName & "';"
    > Set rsName = db.Execute(theSQLStatement)
    >
    > If Not rsName.EOF Then '//User Exists
    > theUserID = rsName("sUserGUID")
    > linkSentence = "<a href=""userpage.asp"
    > linkSentence = linkSentence & "?userid=" & theUserID & """>"
    > linkSentence = linkSentence & theUserName
    > linkSentence = linkSentence & "</a>" & theUsernameSeperator
    > Else '//User Doesn't Exist
    > linkSentence = "**Invalid username ( " & & " )**"
    > End If
    >
    >Next
    >
    >
    > rsName.Close
    > Set rsName = Nothing
    >
    > userLink = linkSentence
    >End Function
    >
    >Response.Write "This will be a link to " & userLink("Hagge")
    >%>
    >
    >
    >I could make this faster using my DBConn.asp script. I would build a
    >comma delimited list with each of the usernames between 2 single
    >quotes. then I would use my cp_sqlArray function with a "select where
    >in" statement so that you are only searching the database once. The
    >code would look something like this
    >
    >I would also change this into a subroutine because performance will be
    >better writing the code than building a string
    >
    >
    >
    >
    >
    ><!-- #include virtual="/coolpier_scripts/_database_tools/DBConn.asp"
    >-->
    >
    ><%
    >Sub userLinks(theUserNameList)
    > '// Create the usersList for the sql in statement
    > Dim usersList, usersArray
    > usersList = "''" & Replace(theUserNameList, ",",
    >"'',''") & "''"
    >
    > '// Get a 2-dimensional array of the results
    > theSQL = "Select sUserGUID, sUserName " &_
    > "From tblUsers " &_
    > "Where sUserName IN (" & usersList & ");"
    > usersArray = cp_sqlArray(theSQL)
    >
    >
    > '//DISPLAY
    > With Response
    >
    > If IsArray(usersArray) Then
    > Dim theRows '//
    > For theRows = 0 to ubound(usersArray,1)
    > .Write "<a href=""userpage.asp"
    > .Write "?userid=" & usersArray(0,n) & """>"
    > .Write usersArray(1,n) & "</a>"
    > .Write "<br />"
    > Next
    > Else
    > .Write "No Users Found!"
    > End If
    >
    > End With
    >
    >End Sub
    >
    >
    >cp_TheConnectionString = "yourConnectionString"
    >cp_DBConn("open")
    > Call userLinks("Hagge, Smith")
    >cp_DBConn("close")
    >%>
    >
    >
    >
    >
    >
    >On Mon, 5 Jan 2004 01:24:00 +0100, "Hagge" <> wrote:
    >
    >>But say you type in...
    >>[userid=Hagge] and [userid=Smith]
    >>
    >>Will it convert both then, or just the first match?
    >>
    >>// Hagge
    >>
    >>"Brynn" <> wrote in message
    >>news:...
    >>> Just to help a little. There is no reason to have to build an array or
    >>> have any loop for what you want to do with your function. The below
    >>> should do what you are wanting to do, and much faster and easier to
    >>> use.
    >>>
    >>> Response.Write "This will be a link to" & userLink("Hagge")
    >>>
    >>> will return...
    >>>
    >>> This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    >>>
    >>> I added also ... if Hagge is not in the usersTable ... it will return
    >>>
    >>> This will be a link to **Invalid username**
    >>>
    >>> Anyway, I hope the below function helps ... if yours is working, this
    >>> one should work with no changes in my function. Also, it will be much
    >>> easier to call since you are giving it the username only. The function
    >>> only returns the link.
    >>>
    >>>
    >>>
    >>>
    >>> <%
    >>> Function userLink(theUserName)
    >>> Dim theUserID, theSQLStatement, linkSentence
    >>>
    >>> theSQLStatement = "Select sUserGUID From tblUsers "
    >>> theSQLStatement = theSQLStatement & "Where sUserName = '" &
    >>> theUserName & "';"
    >>> Set rsName = db.Execute(theSQLStatement)
    >>>
    >>> If Not rsName.EOF Then '//User Exists
    >>> theUserID = rsName("sUserGUID")
    >>> linkSentence = "<a href=""userpage.asp"
    >>> linkSentence = linkSentence & "?userid=" & theUserID & """>"
    >>> linkSentence = linkSentence & theUserName
    >>> linkSentence = linkSentence & "</a>"
    >>> Else '//User Doesn't Exist
    >>> linkSentence = "**Invalid username**"
    >>> End If
    >>>
    >>> rsName.Close
    >>> Set rsName = Nothing
    >>>
    >>> userLink = linkSentence
    >>> End Function
    >>>
    >>>
    >>>
    >>> Response.Write "This will be a link to " & userLink("Hagge")
    >>> %>
    >>>
    >>>
    >>> Brynn
    >>> www.coolpier.com
    >>>
    >>>
    >>> On Fri, 2 Jan 2004 18:29:57 +0100, "Hagge" <> wrote:
    >>>
    >>> >I solved it, this is my function to be used like this...
    >>> >
    >>> >Response.write userLink("This will be a link to [userid=Hagge]")
    >>> >
    >>> >Will be displayed as...
    >>> >This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    >>> >
    >>> >
    >>> >Function userLink(sText)
    >>> > sFuncText=""
    >>> > Dim arrayWords(20000)
    >>> > arrWords = Split(sText," ")
    >>> > For iWords=0 to Ubound(arrWords)
    >>> > iStartLength = Int("0")
    >>> > iEndLength=0
    >>> > iStartLength = Int(Instr(arrWords(iWords),"[userid=")+8)
    >>> > iEndLength = Int(Instr(arrWords(iWords),"]"))
    >>> > iNameLength = Int(iEndLength-iStartLength)
    >>> > If iNameLength > Int("0") Then
    >>> > sFuncUserName =

    >>Mid(arrWords(iWords),iStartLength,iNameLength)
    >>> > SQL=""
    >>> > SQL=SQL & "SELECT sUserGUID"
    >>> > SQL=SQL & " FROM tblUsers"
    >>> > SQL=SQL & " WHERE sUserName='" & sFuncUserName & "'"
    >>> > Set rsName = db.execute( SQL )
    >>> > If NOT rsName.EOF Then
    >>> > sFuncText=sFuncText & "<a href=""userpage.asp?userid=" &
    >>> >rsName("sUserGUID") & """>" & sFuncUserName & "</a>"
    >>> > End If
    >>> >
    >>> > rsName.Close
    >>> > Set rsName = Nothing
    >>> > Else
    >>> > sFuncText=sFuncText & arrWords(iWords) & " "
    >>> > End If
    >>> > Next
    >>> > userLink = sFuncText
    >>> >End Function
    >>> >
    >>> >
    >>> >// Hagge
    >>> >
    >>> >
    >>> >
    >>> >"Hagge" <> wrote in message
    >>> >news:%...
    >>> >> I'm stuck in a problem
    >>> >>
    >>> >> Hi I want to create a funtion in asp.
    >>> >> Like this [userid=Smith] Then the function convert the "custom tag" to.
    >>> >> <a href=www.mypage.com/user/Smith>Smith</a>
    >>> >>
    >>> >> How to do?
    >>> >> I'm real stucked.
    >>> >>
    >>> >> // Hagge
    >>> >>
    >>> >>
    >>> >
    >>> >
    >>>

    >>
    >>

    >
    Brynn, Jan 5, 2004
    #7
  8. Hagge

    Hagge Guest

    Re: Custom tag function? (Easier For You)

    The problem is...
    I'm running a community and in diffrent places on the site can the users
    write in the forum, comment images...
    If they write more then one [userid=XXX] Then they must include "," (no
    quotes). Else do I have to split the text in a array again.
    Else will the script fail, am I write?

    Your dbConnection script was awesome, thx alot.

    // Hagge


    "Brynn" <> wrote in message
    news:...
    > Here it is modified to handle more than one ... just enter a comma
    > delimited string into the function. if only one username, don't use a
    > comma.
    >
    > <%
    > Function userLink(theUserNameList)
    > Dim theUsernameSeperator
    > theUsernameSeperator = "<b />"
    >
    > Dim theUserID, theSQLStatement, linkSentence
    >
    > Dim theUsernameArray, theUserName, n
    > theUsernameArray = Split(theUserNameList, ",")
    >
    > For n = 0 to ubound(theUsernameArray)
    > theUserName = theUsernameArray(n)
    >
    > theSQLStatement = "Select sUserGUID From tblUsers "
    > theSQLStatement = theSQLStatement & "Where sUserName = '" &
    > theUserName & "';"
    > Set rsName = db.Execute(theSQLStatement)
    >
    > If Not rsName.EOF Then '//User Exists
    > theUserID = rsName("sUserGUID")
    > linkSentence = "<a href=""userpage.asp"
    > linkSentence = linkSentence & "?userid=" & theUserID & """>"
    > linkSentence = linkSentence & theUserName
    > linkSentence = linkSentence & "</a>" & theUsernameSeperator
    > Else '//User Doesn't Exist
    > linkSentence = "**Invalid username ( " & & " )**"
    > End If
    >
    > Next
    >
    >
    > rsName.Close
    > Set rsName = Nothing
    >
    > userLink = linkSentence
    > End Function
    >
    > Response.Write "This will be a link to " & userLink("Hagge")
    > %>
    >
    >
    > I could make this faster using my DBConn.asp script. I would build a
    > comma delimited list with each of the usernames between 2 single
    > quotes. then I would use my cp_sqlArray function with a "select where
    > in" statement so that you are only searching the database once. The
    > code would look something like this
    >
    > I would also change this into a subroutine because performance will be
    > better writing the code than building a string
    >
    >
    >
    >
    >
    > <!-- #include virtual="/coolpier_scripts/_database_tools/DBConn.asp"
    > -->
    >
    > <%
    > Sub userLinks(theUserNameList)
    > '// Create the usersList for the sql in statement
    > Dim usersList, usersArray
    > usersList = "''" & Replace(theUserNameList, ",",
    > "'',''") & "''"
    >
    > '// Get a 2-dimensional array of the results
    > theSQL = "Select sUserGUID, sUserName " &_
    > "From tblUsers " &_
    > "Where sUserName IN (" & usersList & ");"
    > usersArray = cp_sqlArray(theSQL)
    >
    >
    > '//DISPLAY
    > With Response
    >
    > If IsArray(usersArray) Then
    > Dim theRows '//
    > For theRows = 0 to ubound(usersArray,1)
    > .Write "<a href=""userpage.asp"
    > .Write "?userid=" & usersArray(0,n) & """>"
    > .Write usersArray(1,n) & "</a>"
    > .Write "<br />"
    > Next
    > Else
    > .Write "No Users Found!"
    > End If
    >
    > End With
    >
    > End Sub
    >
    >
    > cp_TheConnectionString = "yourConnectionString"
    > cp_DBConn("open")
    > Call userLinks("Hagge, Smith")
    > cp_DBConn("close")
    > %>
    >
    >
    >
    >
    >
    > On Mon, 5 Jan 2004 01:24:00 +0100, "Hagge" <> wrote:
    >
    > >But say you type in...
    > >[userid=Hagge] and [userid=Smith]
    > >
    > >Will it convert both then, or just the first match?
    > >
    > >// Hagge
    > >
    > >"Brynn" <> wrote in message
    > >news:...
    > >> Just to help a little. There is no reason to have to build an array or
    > >> have any loop for what you want to do with your function. The below
    > >> should do what you are wanting to do, and much faster and easier to
    > >> use.
    > >>
    > >> Response.Write "This will be a link to" & userLink("Hagge")
    > >>
    > >> will return...
    > >>
    > >> This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    > >>
    > >> I added also ... if Hagge is not in the usersTable ... it will return
    > >>
    > >> This will be a link to **Invalid username**
    > >>
    > >> Anyway, I hope the below function helps ... if yours is working, this
    > >> one should work with no changes in my function. Also, it will be much
    > >> easier to call since you are giving it the username only. The function
    > >> only returns the link.
    > >>
    > >>
    > >>
    > >>
    > >> <%
    > >> Function userLink(theUserName)
    > >> Dim theUserID, theSQLStatement, linkSentence
    > >>
    > >> theSQLStatement = "Select sUserGUID From tblUsers "
    > >> theSQLStatement = theSQLStatement & "Where sUserName = '" &
    > >> theUserName & "';"
    > >> Set rsName = db.Execute(theSQLStatement)
    > >>
    > >> If Not rsName.EOF Then '//User Exists
    > >> theUserID = rsName("sUserGUID")
    > >> linkSentence = "<a href=""userpage.asp"
    > >> linkSentence = linkSentence & "?userid=" & theUserID & """>"
    > >> linkSentence = linkSentence & theUserName
    > >> linkSentence = linkSentence & "</a>"
    > >> Else '//User Doesn't Exist
    > >> linkSentence = "**Invalid username**"
    > >> End If
    > >>
    > >> rsName.Close
    > >> Set rsName = Nothing
    > >>
    > >> userLink = linkSentence
    > >> End Function
    > >>
    > >>
    > >>
    > >> Response.Write "This will be a link to " & userLink("Hagge")
    > >> %>
    > >>
    > >>
    > >> Brynn
    > >> www.coolpier.com
    > >>
    > >>
    > >> On Fri, 2 Jan 2004 18:29:57 +0100, "Hagge" <> wrote:
    > >>
    > >> >I solved it, this is my function to be used like this...
    > >> >
    > >> >Response.write userLink("This will be a link to [userid=Hagge]")
    > >> >
    > >> >Will be displayed as...
    > >> >This will be a link to <a href="userpage.asp?userid=XXXXXX">Hagge</a>
    > >> >
    > >> >
    > >> >Function userLink(sText)
    > >> > sFuncText=""
    > >> > Dim arrayWords(20000)
    > >> > arrWords = Split(sText," ")
    > >> > For iWords=0 to Ubound(arrWords)
    > >> > iStartLength = Int("0")
    > >> > iEndLength=0
    > >> > iStartLength = Int(Instr(arrWords(iWords),"[userid=")+8)
    > >> > iEndLength = Int(Instr(arrWords(iWords),"]"))
    > >> > iNameLength = Int(iEndLength-iStartLength)
    > >> > If iNameLength > Int("0") Then
    > >> > sFuncUserName =

    > >Mid(arrWords(iWords),iStartLength,iNameLength)
    > >> > SQL=""
    > >> > SQL=SQL & "SELECT sUserGUID"
    > >> > SQL=SQL & " FROM tblUsers"
    > >> > SQL=SQL & " WHERE sUserName='" & sFuncUserName & "'"
    > >> > Set rsName = db.execute( SQL )
    > >> > If NOT rsName.EOF Then
    > >> > sFuncText=sFuncText & "<a href=""userpage.asp?userid="

    &
    > >> >rsName("sUserGUID") & """>" & sFuncUserName & "</a>"
    > >> > End If
    > >> >
    > >> > rsName.Close
    > >> > Set rsName = Nothing
    > >> > Else
    > >> > sFuncText=sFuncText & arrWords(iWords) & " "
    > >> > End If
    > >> > Next
    > >> > userLink = sFuncText
    > >> >End Function
    > >> >
    > >> >
    > >> >// Hagge
    > >> >
    > >> >
    > >> >
    > >> >"Hagge" <> wrote in message
    > >> >news:%...
    > >> >> I'm stuck in a problem
    > >> >>
    > >> >> Hi I want to create a funtion in asp.
    > >> >> Like this [userid=Smith] Then the function convert the "custom tag"

    to.
    > >> >> <a href=www.mypage.com/user/Smith>Smith</a>
    > >> >>
    > >> >> How to do?
    > >> >> I'm real stucked.
    > >> >>
    > >> >> // Hagge
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>

    > >
    > >

    >
    Hagge, Jan 5, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jstack
    Replies:
    1
    Views:
    588
    Tor Iver Wilhelmsen
    Jul 4, 2003
  2. kishan bisht

    struts tag inside a tag

    kishan bisht, Jul 8, 2003, in forum: Java
    Replies:
    1
    Views:
    1,477
    Wendy S
    Jul 9, 2003
  3. shahbaz
    Replies:
    0
    Views:
    889
    shahbaz
    Oct 27, 2003
  4. RC
    Replies:
    2
    Views:
    418
    Malte
    May 10, 2005
  5. shruds
    Replies:
    1
    Views:
    757
    John C. Bollinger
    Jan 27, 2006
Loading...

Share This Page