小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

vb6.0 判斷數(shù)組為空

 chinablank 2011-12-15

方法一:Error方法

 

就是采用通用的錯誤捕獲功能

On Error Goto 行號       '遇到錯誤,轉(zhuǎn)到行號處處理

On Error Resume Next '忽略錯誤,繼續(xù)執(zhí)行

On Error Goto 0           '強制取消錯誤捕獲功能

Function IsNotEmpty(ByVal sArray As Variant) As Boolean '判斷數(shù)組是否為空

        Dim i     As Long

        IsNotEmpty = True

        On Error GoTo lerr:

        i = UBound(b)

        Exit Function

lerr:

        IsNotEmpty = False

End Function

 

方法二:CopyMemory方法

 

VB的數(shù)組都是安全數(shù)組,通過訪問一個結(jié)構(gòu)來確定 數(shù)組內(nèi)容保存位置,上標下標和維數(shù)

安全數(shù)組結(jié)構(gòu)的地址可以用

Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (ByRef Ptr() As Any) As Long

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _

             (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

獲得

安全數(shù)組的頭兩位就保存著維數(shù)信息

 

Option Explicit

Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (ByRef Ptr() As Any) As Long

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

 

Private Sub Form_Load()

    Dim MyArr() As Long

    Dim pMyarr As Long

    Dim nDims As Integer

   

    '從數(shù)據(jù)指針得到SafeArray結(jié)構(gòu)的指針

    CopyMemory pMyarr, ByVal VarPtrArray(MyArr), 4

    If pMyarr = 0 Then

        MsgBox "這個數(shù)組是空數(shù)組"

    Else

        '再從這個指針所指地址的頭兩個字節(jié)取出cDims

        CopyMemory nDims, ByVal pMyarr, 2

        MsgBox "這個數(shù)組有" & nDims & ""

    End If

End Sub

 

方法三:使用api函數(shù)safearraygetdim()的返回值,返回值值<=0,說明數(shù)組元素個數(shù)為0或者數(shù)組還沒有初始化.

SafeArrayGetDim用來判斷一個數(shù)組的維數(shù),該函數(shù)在MSDN中定義為:

UINT SafeArrayGetDim(

  SAFEARRAY FAR* psa 

);

轉(zhuǎn)換維VB中的語法格式為:

Public Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long

如果數(shù)組已經(jīng)初始化,則返回非0,否則返回0

'API判斷數(shù)組為空或沒有初始化

Sub diag()

Dim msg As String

Dim arr1() As String, arr2() As String, arr3() As Date, arr4() As Date, arr5() As Range, arr6() As Range

msg = "arr1 " & IIf(SafeArrayGetDim(arr1) > 0, "數(shù)組不為空!", "數(shù)組為空!")

arr2 = Split("一、二、三、四、五、六", "、")

msg = msg & vbCrLf & "arr2 " & IIf(SafeArrayGetDim(arr2) > 0, "數(shù)組不為空!", "數(shù)組為空!")

msg = msg & vbCrLf & "arr3 " & IIf(SafeArrayGetDim(arr3) > 0, "數(shù)組不為空!", "數(shù)組為空!")

ReDim arr4(1 To 100)

msg = msg & vbCrLf & "arr4 " & IIf(SafeArrayGetDim(arr4) > 0, "數(shù)組不為空!", "數(shù)組為空!")

ReDim arr6(1 To 256, 1 To 65536)

msg = msg & vbCrLf & "arr5 " & IIf(SafeArrayGetDim(arr5) > 0, "數(shù)組不為空!", "數(shù)組為空!")

msg = msg & vbCrLf & "arr6 " & IIf(SafeArrayGetDim(arr6) > 0, "數(shù)組不為空!", "數(shù)組為空!")

MsgBox msg

End Sub

 

方法四:使用cstr(Join(list[, delimiter]))函數(shù)的返回值是否不等于""

 

delimiter參數(shù)設(shè)置為""

 

例如:if (cstr(join(arr,""))) = "" then msgbox "arr 數(shù)組為空或者尚未初始化"

 

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

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多