Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global Variables mattsvai[_11_] Excel Programming 4 February 3rd 06 05:02 PM
Global Variables Francis Brown Excel Programming 9 November 27th 05 06:14 PM
global variables [email protected] Excel Programming 3 November 16th 05 11:44 PM
Global Variables Ernst Guckel[_4_] Excel Programming 2 May 7th 05 11:10 PM
Global vs Local variables Ken Loomis Excel Programming 1 October 12th 04 05:03 AM


All times are GMT +1. The time now is 05:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"