看板 Programming 關於我們 聯絡資訊
我要寫一個求因數的函式,該函式傳回值為該整數的所有因數 然後在程式中呼叫此函式,則可以顯示所有該數的因數 我用VB語法寫的 以下這邊是副程式 <script language="vb" runat="server"> Function count(ByVal n As Integer) As Integer Dim i As Integer Dim k As String For i = 1 To 100 If n Mod i = 0 Then Response.Write(i & ".") End If Next End Function </script> 主程式呼叫 <% count(100) %> 這樣印出來的結果為 1. 2. 4. 5. ......100 請問我想要把response.write 寫在主程式呼叫 印出來的結果為 100的因數為1. 2. 4. 5. ........100 請問要怎麼寫 或者有其他的寫法 可以出現一樣的結果 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.117.117.58
Peruheru:function回傳一個結果字串如何?220.136.229.110 09/05 13:01
Peruheru:主程式用一個變數接字串,由主程式印220.136.229.110 09/05 13:02
Peruheru:話說妳的Function根本沒有回傳嘛...220.136.229.110 09/05 13:03
tellalie:對耶 提示說傳回值用字串 請問該怎麼寫 122.117.117.58 09/05 14:50
Peruheru:首先呢,As Integer改成As String220.136.229.110 09/05 15:06
Peruheru:function後面的As xxx表示回傳xxx220.136.229.110 09/05 15:06
Peruheru:再來,宣告一個string,每次的輸出改成220.136.229.110 09/05 15:07
Peruheru:接在該串後面(不知ASP有無stringbuilder)220.136.229.110 09/05 15:08
Peruheru:最後離開程式前,用return xxx 或是220.136.229.110 09/05 15:08
Peruheru:count = xxx就可以回傳結果了220.136.229.110 09/05 15:08
Peruheru:感覺好基本,這些妳應該會吧?220.136.229.110 09/05 15:08
Peruheru:主程式拿到字串再看妳要怎麼輸出220.136.229.110 09/05 15:09
tellalie:了解 非常感謝 122.117.117.58 09/05 15:33