电竞比分网-中国电竞赛事及体育赛事平台

分享

VBA函數(shù)最后一個參數(shù)可重復(fù)添加

 nxhujiee 2018-05-02

━━━━━━━━━━━━━━━━━━━━━━━━━

'可以傳入多個參數(shù)
'使用 ParamArray 關(guān)鍵字可以使函數(shù)接收數(shù)目可變的參數(shù)

Function CalcSum(ByVal FirstArg As Integer, ParamArray OtherArgs())
    
Dim As Integer
    
CalcSum FirstArg
    For To UBound(OtherArgs)
        
CalcSum CalcSum OtherArgs(i)
    
Next
End Function

'如果用如下代碼調(diào)用該函數(shù):
Sub Example1()
    
Dim ReturnValue
    '局部變量賦予以下值:FirstArg 4,
    'OtherArgs(0) 3,OtherArgs(1) 2,OtherArgs(2) 1,等等。
    
ReturnValue CalcSum(4, 3, 2, 1)
    
MsgBox ReturnValue
End Sub

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多