2012-04-03 10 views
0

私はいくつかの古代のコードで探していますし、次のコード行があります:関数から変数を戻す?

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>"

答えて

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 
+0

ありがとう!以前は "return strResult"を試みていましたが、エラーが発生しました。私はこれを試してみましょう! p.s.ありがとう! –

+0

それを並べ替えてうれしいです。 –

関連する問題