[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
  1. Option Explicit
  2.  
  3. Private Type REGISTER
  4. name As String
  5. addr As Byte
  6. bank As Integer
  7. End Type
  8.  
  9. Type DRIVER_INFO
  10. strID As String
  11. reg() As REGISTER
  12. End Type
  13.  
  14. Sub main()
  15. Dim UC51 As DRIVER_INFO
  16. Dim tmpBuf() As String
  17. Debug.Print IsEmptyArray(tmpBuf)
  18. Debug.Print IsEmptyArray(UC51.reg) ' error here
  19. End Sub
  20.  
  21. Function IsEmptyArray(source As Variant) As Boolean
  22. On Error GoTo ERROR_HANDLER
  23.  
  24. If UBound(source) >= 0 Then
  25. Exit Function
  26. End If
  27.  
  28. ERROR_HANDLER:
  29. IsEmptyArray = True
  30. End Function




留言

張貼留言

這個網誌中的熱門文章

[VB6]使用File Dialog選擇檔案

[VB6]MSFlexGrid使用記錄

[VBA]如何藉由使用 Excel 中的 Visual Basic 程序選取儲存格/範圍