ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   global variables (https://www.excelbanter.com/excel-programming/360477-global-variables.html)

Mike Archer

global variables
 
Hello - When VBA code chokes and the user selects the debug button, all
global variables are cleared. It there a way to keep the global variable
values or an option other than global variables?
--
Thanks,
Mike

Zone

global variables
 
I use a separate spreadsheet to store variables I want to keep after
breaking the program. Anyway, I don't think I've ever run into this
problem. If I use this code

Dim myGlobal as string

Sub Huhoh
myGlobal="still here"
msgbox 0/0
End Sub

myGlobal still keeps its string in Debug.

James


Bob Phillips[_14_]

global variables
 
He means on a subsequent run the variable is cleared.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"Zone" wrote in message
oups.com...
I use a separate spreadsheet to store variables I want to keep after
breaking the program. Anyway, I don't think I've ever run into this
problem. If I use this code

Dim myGlobal as string

Sub Huhoh
myGlobal="still here"
msgbox 0/0
End Sub

myGlobal still keeps its string in Debug.

James




Tom Ogilvy

global variables
 
Why not write a routine to initialize your global variables. In you code,
have a global variable that is dedicated to just checking

Public gbChecker as Boolean

Initialize it to true in the workbook_open event.


if gbChecker = False then
' run code to init variables
end if


Better is to handle errors so the user never sees an error message displayed
by the system unless it is fatal.

--
Regards,
Tom Ogilvy


"Mike Archer" wrote:

Hello - When VBA code chokes and the user selects the debug button, all
global variables are cleared. It there a way to keep the global variable
values or an option other than global variables?
--
Thanks,
Mike


Jim Thomlinson

global variables
 
There is no way to hold on to the variables short of storing them in a
worksheet somewhere. When the execution is halted the memory that stores the
variables is automatically cleared. In the grander scheme of things if you
just had an error though you can not gurantee that the values in your globals
would be correct anyways so clearing them is really no great loss. What you
want to do is to write bullet proof code with a robust error handler to
gracefully handle anything that is thrown at it. That will keep you from
getting to the debug screen in the first place.

--
HTH...

Jim Thomlinson


"Mike Archer" wrote:

Hello - When VBA code chokes and the user selects the debug button, all
global variables are cleared. It there a way to keep the global variable
values or an option other than global variables?
--
Thanks,
Mike



All times are GMT +1. The time now is 07:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com