VB使用CommonDialog控件获取颜色后,比较颜色:
With CommonDialog1
.ShowColor
If .Color <> 0& Then xxx
End With
代码可正常执行。
换成CreatObject建立控件
Dim colorDlg As Object
Set colorDlg = CreateObject("MSComDlg.CommonDialog")
With colorDlg
.ShowColor
If .Color <> 0& Then xxx
End With
运行时出现错误提示:
’实时错误458’:变量使用了一个 VISUAL BASIC 不支持的自动化类型
原因:.Color是OLE_COLOR类型,未添加控件所以不支持,加上CLng()函数转换一下即可。