从函数中传回变量?

Mad*_* Zu 0 asp-classic

我正在看一些古老的代码,并有以下代码行:

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
Run Code Online (Sandbox Code Playgroud)

当我尝试调试strResult时.它不会附加pIrntTableHead函数的内容.为什么这不起作用?我怎样才能重写这个以正确追加?

所以在 strResult = strResult + "<tr>" & vbLfstrResult的值仍然只是:

"table><tr>"

Dav*_*d M 5

该函数永远不会返回其值.你之前需要以下几行End Function.

PrintTableHead = strResult
Run Code Online (Sandbox Code Playgroud)

请注意,您应该确保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
Run Code Online (Sandbox Code Playgroud)