Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you're re-using that object variable for something that may not exist, it
might be better to set it to nothing to re-initialize it. For example, I put a single checkbox on the activeworksheet: Option Explicit Sub Macro1() Dim myCBX As MSForms.CheckBox Set myCBX = ActiveSheet.CheckBox1 Set myCBX = Nothing '<-- try commenting this line On Error Resume Next Set myCBX = ActiveSheet.checkbox2 On Error GoTo 0 If myCBX Is Nothing Then MsgBox "not there" Else MsgBox myCBX.Caption End If End Sub Try it once with the line commented and once without the line being commented. ==== If you know the object exists, then you don't need this (as both Tom and Bob wrote), but .... Matt Jensen wrote: Thanks Tom Pertaining to that checkbox naming code you helped me with yesterday: snippet dim cb as OLEObject Set cb = ws.OLEObjects.Add(ClassType:="Forms.CheckBox.1", _ I reuse / redfine this cb variable/object several times in one procedure, should I set it to nothing before each I use it again or just at the end of the proc? Thanks Matt "Tom Ogilvy" wrote in message ... integers can't be set to nothing. They are initialized to a value of zero. You shouldn't have to worry about any type of local variable because they go out of scope and are destroyed when the code in which they are defined stops running. No variables have a default value of Null, so you shouldn't use that. Only objects can be set to Nothing Dynamic arrays can be erased -- Regards, Tom Ogilvy "Matt Jensen" wrote in message ... As good programming practice, what of the possible variable types should be set to nothing or null? Can /should you set integers to nothing for example? Thanks Matt -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Setting Multiple Variables with a loop | Excel Discussion (Misc queries) | |||
Not at all clear on use of variables and/or object variables | Excel Discussion (Misc queries) | |||
Confused about setting up functions based on variables? | Excel Worksheet Functions | |||
VBA Setting .Value to a date does not respect local system setting | Excel Programming | |||
Setting a print range using variables | Excel Programming |