0

I have this simple Address class, that only have:

  Public street as String
  Public number as Integer

Then, i'm creating a instance inside a module calle "mdl1", and using it on the same module function:

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

I've assigned a value to objectAdrress.street on the f1() function, but when it enters the ìsNothing()`function, the objectAddress is Nothing again.

And when the control comes back to the f1 function, the object returns to having a value and the street property still have the value i assigned it...

So, shouldn't a module "property" behave like a class one? Or the global/local scope doesn't exist inside a module?

SOLVED: Even though no one got the point of the question, the problem was that I was creating a local object with the same name of the global one, that's why it was always Nothingwhen it entered another function.

  • What's your question? Is your object value NOTHING as mentioned in your title? Or does it bear same value as before the function call? can you please clarify your question? – Nadeem_MK Apr 01 '15 at 05:33
  • You realise... there is a variable spelling mistake? 'Public objectAddres as Address' and ' If objectAddress is Nothing then' – Rob Apr 01 '15 at 06:56
  • There are Class modules as well as Static Basic (.bas) modules in VB6. Every Class requires its own module and the syntax you've shown isn't valid at all. Even if it *was* you have no default property defined as far as we can tell so your "works fine" line should fail or do something you haven't told us about (perhaps your `street` String is the default property?). And the static module syntax is also incorrect. This is not VB6 but some sort of weird combination of VB6, VBA, and VBScript syntax or something. – Bob77 Apr 01 '15 at 09:44

0 Answers0