Creating a Server Component with VB - Redesigned - Part 2[18]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 sonicdater 的 blog

tring & strtextfontend & vbcrlf strreturnstring = strreturnstring & strtextdataend & vbcrlf '///// send back constructed string ///////////////////////////// shownotes = strreturnstring after the first two html style variables are set (strtitledatastart and strtitlefontstart), the code declares a local variable (lngnoteidindex) that will be used within the loop to see if the note that is currently being itinerated is the same note that was selected by the user. the user-sent lngnoteid is subtracted by one and stored in this lngnoteidindex variable. it is subtracted by one because our array is zero based and the database table starts with one rather than zero.


    '///// set selected noteid to array index (for not inserting the <a> tag)
    lngnoteidindex = (lngnoteid - 1)

we itinerate through the array by starting at the first item in the array, set at zero, and end with the last item in the array. the lngarraycount variable is used to indicate the end of the array by using the vb ubound() method.

    '///// loop through array
    for lngindexcount = 0 to lngarraycount
 
the first thing to do within the record-array looping code is to check if the noteid stored in the array, and currently being processed by the loop, matches the noteid selected by the user. if it's not the user-selected noteid, then we need to construct an html <a> tag that will link back to the asp file with a query string that indicates the noteid value of the title. an "if not lngnoteidindex = lngindexcount then" statement will fulfill this need since the lngindexcount variable value contains the current loop count.

	'///// include an <a> tag if not the selected noteid
        if not lngnoteidindex = lngindexcount then
            strreturnstring = strreturnstring & "<a href=""" & strurl
            strreturnstring = strreturnstring & "?id=" & vrecordarray(array_note_id_index, lngindexcount) & """>"
        end if

within the if/then statement the strurl is concatenated to the first part of the <a> tag and then a query string named "id" is assigned the noteid valued from the vrecordarray. double quotations marks are used to include quotation marks for the file name within the html <a> tag.

the two lines of code within this if/then process result in the following string, given that the current loop count is at 3 and it isn't the note that was selected by the user.


<a href="noteexample.asp?id=3>

since the <a> tag has been constructed, we'll add in the note title values.
 
        '///// include the note title text from the array
        strreturnstring = strreturnstring & vrecordarray(array_title_index, lngindexcount)

we again check to see if the current note within the loop is other than the user-selected note and end the <a> tag. an optional vbcrlf is added to the string for clearer html source-code reading.

'///// include an </a> tag if not the selected noteid
if not lngnoteidindex = lngindexcount then strreturnstring = strreturnstring & "</a>" & vbcrlf

we'll also add a <br> so the note titles won't all end up on one line within the html table record.

        '///// end the title line with a line break
        strreturnstring = strreturnstring & "<br>" & vbcrlf

this html table ends by adding the ending two html style variables (strtitlefontend and strtitledataend) to our return string.

the second html table record is much simpler since it basically involves adding the two html style variables (strtextdatastart and strtextfontstart), the variable containing the selected note text (strnotetext), and the last two html style variables (strtextfontend and strtextdataend).


    '///// include the beginning table data and font tags
    strreturnstring = strreturnstring & strtextdatastart & vbcrlf
    strreturnstring = strreturnstring & strtextfontstart & vbcrlf
    
    '///// include the note text body
    strreturnstring = strreturnstring & strnotetext & vbcrlf
    
    '///// include the ending font table data tags
    strreturnstring = strreturnstring & strtextfontend & vbcrlf
    strreturnstring = strreturnstring & strtextdataend & vbcrlf
    
after that, the return string is ready to send back to the calling code.

    '///// send back constructed string /////////////////////////////
    shownotes = strreturns

本文关键:Creating a Server Component with VB - Redesigned
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top