列表选项包含FirstName、 LastName、 Company 和 City。为了正确地安排第一栏的格式,我们必须发现字节数最多的名字''Nathan'',然后为全部7个字符增加一个无间断空间。然后我们给John和Sue增加适当数量的空格,使它成为7个字符,在结尾增加管道符号,现在我们就有了一个格式化了的栏。
要注意我们在以上代码中增加了< FONT > 标记。这是为了在Netscape上使用考虑,因为Netscape不象 IE能够识别字体属性。还要注意< FORM > 标记的出现。这也是Netscape 的要求。IE允许你绘制表单域、 选项列表等,不用将它们放在< FORM > 标记中,而在Netscape ,如果想要提取表单控制的话,就要求 表单的标记。
对于我们这个特定情况,你可能想要在函数的最开头包含一个On Error Resume Next 语句。把这个语句放在代码中允许代码在发生错误的情况下继续执行(也许在返回的记录集中,代码在某一行中遇到了一个意外的值)。代码中有这个语句,你还可以建立选项列表的内容。缺点是在发生错误的情况,你的应用程序用户将不能直接向你报告错误,也许这个错误会导致下一个错误,使你的调试工作更加困难。
''Loop for formatting the select list values For i = 0 to UBound(column) maxStrLenTemp = 0 finalMaxLenArray(i) = 0 '' Loop through recordset to determine the maximum length string '' in given column If Not rsSelect.BOF Then rsSelect.MoveFirst Do While Not rsSelect.EOF maxStrLenTemp = Len(Trim(rsSelect(CStr(Trim(column(i)))))) If Not IsNull(maxStrLenTemp) Then If CInt(maxStrLenTemp) > CInt(finalMaxLenArray(i)) Then finalMaxLenArray(i) = maxStrLenTemp End If rsSelect.MoveNext Loop
'' If the derived col length is greater than the maxcollen parameter '' then reset col length. If IsArray(maxcollen) = True Then If CInt(maxcollen(i)) < > -1 Then If finalMaxLenArray(i) > CInt(maxcollen(i)) Then finalMaxLenArray(i) = CInt(maxcollen(i)) End If Else If CInt(maxcollen) < > -1 Then If finalMaxLenArray(i) > CInt(maxcollen) Then finalMaxLenArray(i) = CInt(maxcollen) End If End If Next
''strDif Can be negative number if maxcollen is in effect. strDif = CInt(finalMaxLenArray(n)) - Len(descTemp) If strDif < 0 Then descTemp = Mid(descTemp, 1, finalMaxLenArray(n) + 1) Else For x = 0 to strDif ''0 for one extra descTemp = descTemp & " " Next End If
然后我们在字符串结尾处增加"|" 字符,然后将那个字符串增加到最后的字符串finalDesc上。 注意循环的次数要与选项列表中的栏数相当,这样结束时就可以有一个完整的选项列表行。 If n < > UBound(column) Then descTemp = descTemp & "|" strDif = 0