调用第三个函数时,模块对象无效

时间:2015-04-01 03:53:40

标签: vb6 nothing

我有这个简单的Address类,只有:

  Public street as String
  Public number as Integer

然后,我在模块calle“mdl1”中创建一个实例,并在相同的模块函数上使用它:

Public objectAddress as Address

Public Function f1() As String
  Set objectAddress = New Address
  objectAddress = "5th street" 'this works fine

  If Not isNothing() Then
    f1 = objectAddress.street
  Else
    f1 = vbNullString
  End If

End Function

Public Function isNothing() As Boolean

'When entering here, the objectAddres is ALWAYS Nothing, even though i just assigned a value to the street property...

  If objectAddress is Nothing then
    isNothing = True
  Else
    isNothing = False
  End If
End Function

我在f1()函数上为objectAdrress.street赋值,但是当它进入“ofNothing()”函数时,objectAddress再次为Nothing。

当控件返回到f1函数时,对象返回一个值,而street属性仍然具有i赋值的值...

那么,模块“属性”是否应该像第一类一样?或者模块内部不存在全局/局部范围?

解决: 尽管没有人明白这个问题,但问题是我正在创建一个与全局对象同名的本地对象,这就是为什么它在进入另一个函数时总是Nothing

0 个答案:

没有答案