DateTime Object as Property

If I create a LeaveDate dateTime property in a module and create a dateTime object in a method:

Var LeaveDate As New DateTime(Val(year(ArrayElement).Text),month(ArrayElement).listIndex,Val(day(ArrayElement).Text),Val(hr(ArrayElement).Text) + (12*AmPm(ArrayElement).listIndex),Val(minutes(ArrayElement).Text))

why would LeaveDate be nil when I attempt to use it in another method?

That’s because LeaveDate is defined in a method. So it only exists while this method runs – see Scope in the documentation.
In order to preserve it, the property must be saved in a place where it lives beyond the runtime of the method, like a module, window or class property.

I think I mentioned the property is stored in a module which should be global if I’m correct.

Because you’re creating a local variable, which will be destroyed at the end of the method, rather than using your global variable. Change that to

LeaveDate = New ....
1 Like

Var in your code means a new private method property is created. If you have another property of the same name somewhere else, don’t use Var but address this property directly.

Tim was faster. :smile:

You did but you said you create it in a method. When the method returns, your locally declared variables (which live on the stack), go out of scope and are destroyed.

1 Like

Some mornings I really need someone to watch over me. You was first to answer Ulrich. Thanks for the quick response.

1 Like

Tim, does the App treat properties any different then a module?

The only real difference is you have to namespace app variables (app.LeaveDate) where in a module you can choose to do so or not.