Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Use Checkbox Value or Public Variable?

When an Excel file with a macro is opened, do all the
forms and the controls on the forms exist before the form
is initialized or called? The reason I am asking is that
I was recently using the value of a form's checkbox
instead of a boolean variable to control an IF statement.
It seems to work just as well either way, but I decided
that it might be dangerous to assume that the form's
checkbox is true or false or even that the form exists
before being called, so I created an explicit boolean
variable and made it public. What's the best practice?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Use Checkbox Value or Public Variable?

Start,

Don't rely on it. It doesn't exist on the workbook opening, but when you
reference it, it is loaded into memory. Loading initialises all controls,
etc. So a checkbox is initialised to whatever the design sets it at. A
variable is the same problem, re-opening the workbook will initialise.

The safest places are the registry, stored in a file, or a workbook name.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Stratuser" wrote in message
...
When an Excel file with a macro is opened, do all the
forms and the controls on the forms exist before the form
is initialized or called? The reason I am asking is that
I was recently using the value of a form's checkbox
instead of a boolean variable to control an IF statement.
It seems to work just as well either way, but I decided
that it might be dangerous to assume that the form's
checkbox is true or false or even that the form exists
before being called, so I created an explicit boolean
variable and made it public. What's the best practice?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Use Checkbox Value or Public Variable?

You can be guaranteed a newly-declared boolean variable will have a
value that coerces to false i.e.

Sub test()
Dim blnTest As Boolean
Debug.Print blnTest ' returns false
Debug.Print blnTest = Empty ' returns true
Debug.Print IsEmpty(blnTest) ' returns false
End Sub

But best practise is to never use a *public* variable.

--

"Stratuser" wrote in message ...
When an Excel file with a macro is opened, do all the
forms and the controls on the forms exist before the form
is initialized or called? The reason I am asking is that
I was recently using the value of a form's checkbox
instead of a boolean variable to control an IF statement.
It seems to work just as well either way, but I decided
that it might be dangerous to assume that the form's
checkbox is true or false or even that the form exists
before being called, so I created an explicit boolean
variable and made it public. What's the best practice?

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
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
Public/Procedure Variable Otto Moehrbach[_6_] Excel Programming 2 February 6th 04 04:58 PM
Scope of a public variable Jos Vens Excel Programming 0 November 24th 03 10:08 AM
Scope of Public Variable Dkline[_2_] Excel Programming 9 October 22nd 03 04:53 PM
public variable marwan hefnawy Excel Programming 1 September 5th 03 08:54 AM


All times are GMT +1. The time now is 11:05 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"