我正在查看一些古老的代码,并且有以下代码行:
strResult = strResult + "<table>" & vbLf
output = PrintTableHead("Field Office Code","1")
strResult = strResult + PrintTableHead("Field Office Code","1")
strResult = strResult + "<tr>" & vbLf
Function PrintTableHead( TheTitle , TheColSpan )
strResult = "<tr><th colspan="
strResult = strResult + TheColSpan
strResult = strResult + " BGCOLOR=""#004D95"" align=center>" & vbLf
strResult = strResult + "<font face=""Time New Roman"" color=""#ffffff"" SIZE=3>" & vbLf
strResult = strResult + TheTitle
strResult = strResult + "</font></th></tr>" & vbLf
End Function
当我尝试调试strResult时。它不会附加pIrntTableHead函数的内容。为什么这不起作用?我怎样才能重写这个以正确追加?
所以在strResult = strResult + "<tr>" & vbLf
之后,strResult的值仍然只是:
"table><tr>"
答案 0 :(得分:5)
该函数永远不会返回其值。您需要在End Function
之前的以下行。
PrintTableHead = strResult
请注意,您应该确保strResult在函数内本地声明,以避免覆盖您在调用代码中使用的变量。整个功能看起来像这样:
Function PrintTableHead( TheTitle , TheColSpan )
Dim strResult
strResult = "<tr><th colspan="
strResult = strResult + TheColSpan
strResult = strResult + " BGCOLOR=""#004D95"" align=center>" & vbLf
strResult = strResult + "<font face=""Time New Roman"" color=""#ffffff"" SIZE=3>" & vbLf
strResult = strResult + TheTitle
strResult = strResult + "</font></th></tr>" & vbLf
PrintTableHead = strResult
End Function