DWUTKA at marlow.com
DWUTKA at marlow.com
Sat Nov 26 23:36:49 CST 2005
End. I wasn't referring to the stop statement, but actually stopping the execution of your code. When Access is running, your code is 'running'. The best way to give an example of this, is if you run VB 6. Pressing the 'play' button in VB6, runs your code in debug mode. Startup processes run (first form loads, or Sub Main() runs). If you press the stop button (the square button), or run into an END statement, your entire project unloads. Forms close/shutdown, variables clear, memory is returned to the system, etc. Access doesn't close your forms. It doesn't do this, because with Access you are running two processes, one is the code, one is the .mdb in the Access window. If the code is stopped (execution ended), all variables are reset, and memory is returned to the system. However, the Access project is not unloaded. Drew -----Original Message----- From: Arthur Fuller [SMTP:artful at rogers.com] Sent: Saturday, November 26, 2005 9:41 PM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Public Variables - Scope and Lifetime Okay... Since I never use globals, I decided to write a tester to verify your assertion. <code> Option Compare Database Option Explicit Global gstrTest As String Function TestGlobal() As Long gstrTest = "This is a test" MsgBox gstrTest Stop Call Proc1 MsgBox gstrTest Call Proc2 End Function Private Sub Proc1() MsgBox gstrTest, vbOKOnly, "Proc1" Stop End Sub Private Sub Proc2() MsgBox gstrTest, vbOKOnly, "Proc2" Stop End Sub </code> Which leads me to wonder what Drew meant in the foregoing message: "Ugh....not this again! LOL. Marty, that is not what happens. If you STOP your code, then everything gets reset. That does include your global variables. It's not a maybe, and they don't 'lose' their values, the code is stopped. It is just like stopping an .exe, all values in memory are cleared." Just to make sure, at each STOP statement, I went into the Debug window and entered "Debug.Print gstrTest" and obtained the expected result. So in this respect, it would appear that globals and statics are equivalent. So then what was Drew getting at? I could easily be missing the point; it certainly wouldn't be the first time. Arthur -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: November 26, 2005 7:48 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Public Variables - Scope and Lifetime On 26 Nov 2005 at 16:46, Arthur Fuller wrote: > Your reply made me decide to test static functions against a STOP, which I > have never done before. > Turns out that static values are preserved despite a STOP. Code follows. No different to a global variable, this works the same way: Function TestGlobal() As Long gstrTest = "This is a test" MsgBox gstrTest Stop MsgBox gstrTest End Function -- Stuart -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com