手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

Creating a Server Component with VB - Redesigned - Part 2

来源:互联网 作者:西部数码 时间:2008-04-10
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
The second table, which displays the selected note text, is much simpler and basically combines the HTML style formatting with the note text value retrieved from the database.

Here''''s the code fragment that constructs the return string composed of the database note information and the HTML styling. This code section will be placed after all the database work has been completed. Since all the database values have been tucked away in local variables (strTextNote and vRecordArray), the database can be closed before this string construction code.

Code Fragment for Using Concatenation to Construct a Return String


    ''''///// CONSTRUCT NOTE TITLES ///////////////////////////////////
    ''''///// Include the beginning table data and font tags
    strReturnString = strTitleDataStart & vbCrLf
    strReturnString = strReturnString & strTitleFontStart & vbCrLf
    
    ''''///// Get the number of titles stored in the array
    lngArrayCount = UBound(vRecordArray, 2)
    
    ''''///// Set selected NoteID to array index (for not inserting the <A> tag)
    lngNoteIdIndex = (lngNoteID - 1)
    
    ''''///// Loop through array
    For lngIndexCount = 0 To lngArrayCount
    
        ''''///// 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
        
        ''''///// Include the note title text from the array
        strReturnString = strReturnString & vRecordArray(ARRAY_TITLE_INDEX, lngIndexCount)
        
        ''''///// Include an </A> tag if not the selected NoteID
        If Not lngNoteIdIndex = lngIndexCount Then strReturnString = strReturnString & "</A>" & vbCrLf
        
        ''''///// End the title line with a line break
        strReturnString = strReturnString & "<BR>" & vbCrLf
    Next
    
    ''''///// Include the ending font and table data tags
    strReturnString = strReturnString & strTitleFontEnd & vbCrLf
    strReturnString = strReturnString & strTitleDataEnd & vbCrLf & vbCrLf
    
    
    ''''///// CONSTRUCT NOTE TEXT BODY ////////////////////////////////
    ''''///// 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
    
    
    ''''///// 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.

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!