0

I created a property in a class module called clsProperties:

Dim blnProduction As Boolean

Public Property Get IsProduction() As Boolean
  IsProduction = blnProduction
End Property

Public Property Let IsProduction(ByVal vNewValue As Boolean)
    blnProduction = vNewValue
End Property

I then call the Let statement from a form:

Private objPropertiesAs New clsProperties

'Determine if we're in production
    If (Environ("computername")) = "WS0006" Then
      objPropertiesAs.IsProduction = True
    Else
      objPropertiesAs.IsProduction = False
    End If

I test the code using "WS006" and IsProduction will be equal to True. However, when I try to access the Get in clsProperties IsProduction is equal to False.

If IsProduction Then
      Debug.Print "Prod"
    Else
      Debug.Print "Dev"
    End If

Please help!

Tilting Code
  • 137
  • 1
  • 3
  • 13
  • Where exactly is that last snippet? There isnt a class reference there so it is confusing. Also be sure you dont (re) create another `New` one – Ňɏssa Pøngjǣrdenlarp Dec 14 '17 at 17:33
  • The last snippet is in the clsProperties class module where the IsProduction property exists. Do I create an object reference to itself? Is that what your saying? – Tilting Code Dec 14 '17 at 17:41
  • Old VB6 had the great ability to set the debugger to break when a variable changes. You could use that to see where/what is changing the value. – Ňɏssa Pøngjǣrdenlarp Dec 14 '17 at 17:45
  • I tried that and it never went into break, or even changed. – Tilting Code Dec 14 '17 at 18:09
  • You didnt give a [mcve] so I can only guess that you are using a different instance object – Ňɏssa Pøngjǣrdenlarp Dec 14 '17 at 18:13
  • Okay, apparently there's something screwy in this application I inherited. I created a new project with just the pertinent code and it works fine. There's other things wrong with this program so it must be effecting my property as it does work as expected.... just not in this project. thanks for your help. – Tilting Code Dec 14 '17 at 18:32
  • beware of this VB6 behaviour https://stackoverflow.com/q/8114684 – froque Dec 18 '17 at 11:31
  • Maybe something else other than the property get/let procedures in the class is modifying blnProduction. – StayOnTarget Dec 18 '17 at 12:54
  • Thanks for comment, DaveInCaz, I did a watch on blnProduction and I saw nothing change it. I did as minimal as possible to ease the process of stepping through the code and it just plain changed back to False. The only variable named blnProduction is the one I added. – Tilting Code Dec 20 '17 at 16:54

1 Answers1

0

You've set up your clsProperties module correctly. But there are some problems with the rest of the code as published (as it is, it won't compile, so you haven't cut and pasted actual code). Here's a stab at a fix:

Private objProperties As New clsProperties

objPropertiesAs.IsProduction = (Environ("computername") = "WS0006") 
Debug.Print Iif (objProperties.IsProduction, "Prod", "Dev")

I've done some things to make your code more concise. The only substantive difference between my code and yours is that yours doesn't reference the object with which your IsProduction property is associated when you do the Get. I don't know why you aren't getting an "Object Required" error there, but perhaps you have an On Error Resume Next in your code somewhere.

BobRodes
  • 5,990
  • 2
  • 24
  • 26