[VB6]only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions

自定義Type類型於module中, 無法傳入function/sub函數
因user-define type無法與variant相容

下面為error code
Line 19, UC51宣告為DRIVER_INFO, 傳入IsEmptyArray()的source為Variant-type
兩種type無法強制轉換
只能將IsEmptyArray()source宣告為REGISTER-type
但導致IsEmptyArray()只能接受REGISTER-type, 無法接受其他data type
Option Explicit

Private Type REGISTER
    name As String
    addr As Byte
    bank As Integer
End Type

Type DRIVER_INFO
    strID As String
    reg() As REGISTER
End Type

Sub main()
    Dim UC51 As DRIVER_INFO
    Dim tmpBuf() As String
    
    Debug.Print IsEmptyArray(tmpBuf)
    Debug.Print IsEmptyArray(UC51.reg)  ' error here
    
End Sub

Function IsEmptyArray(source As Variant) As Boolean
    On Error GoTo ERROR_HANDLER

    If UBound(source) >= 0 Then
        Exit Function
    End If

ERROR_HANDLER:
    IsEmptyArray = True
End Function




留言

張貼留言

這個網誌中的熱門文章

[VB6]使用File Dialog選擇檔案

[VB6]MSFlexGrid使用記錄