2015-03-03 52 views
0

我正在写一个VB6中的小实用程序,它调用C#.Net类(它带来了打印机列表),但在调用C#方法时,它抛出的错误以下,我无法编译/运行应用程序。有人可以帮忙吗?错误:预期的函数或变量

VB6代码:用于方法

Dim retval As Integer 
Dim tbp As NamespaceXYZ.CGETList 
Dim a As String 
Dim col As New Collection 
Set tbp = New CGETList 
retval = tbp.GetDefaultPrinterAndList(col, a) 

C#定义。

public void GetDefaultPrinterAndList(ref Microsoft.VisualBasic.Collection vntPrinterList, ref string defaultPrinter) 
    { 

错误: while calling the C# method, it throws the error

+0

你需要使用一个字符串数组来代替 - 混合语言类型可能不起作用。 – 2015-03-03 07:25:38

+0

感谢您的建议,但刚才我意识到它抛出了这个错误,因为上面的代码对象没有在VB中初始化。 当我添加手表时,发现“tbp”设置为空。任何想法为什么? – atp9 2015-03-03 08:05:09

+0

当你得到编译错误时,它应该带你到一个特定的行。哪条线? – MarkJ 2015-03-03 12:12:29

回答

1

你宣布tbp,却忘了初始化它。

Dim tbp As NamespaceXYZ.CGETList 
'tbp value is currently Nothing 

Set tbp = New NamespaceXYZ.CGETList 
'now it's something. 

注意的是,上述假设NamespaceXYZ.CGETList类有一个默认的构造函数,即你可以创建只使用New一个新的对象。有些课程没有这个;他们需要你以其他方式创建对象。

相关问题