Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am getting the errors normally associated with using undimensioned
variables in an Option Explicit module. But I haven't set Option Explicit on that module nor anywhere else in my project (an Excel 2K3 workbook with some VBA routines). If I dim the variables, the problem goes away. So, I can work with it, but the problem is contrary to my understanding of "Option Explicit". My understanding is that "Option Explicit" only operates at module level (says so in the Help file), but this I haven't done. ***Is it possible for a third party addin to somehow set "Option Explicit" at the application level? The reason I ask is that the only machine out of 11 which has the problem is one which has a third party add-in installed. Some of the add-in code is exposed and uses "Option Explicit", though, as expected, on a per-module basis. Perhaps there is some code for the add-in that I can't see. ***More generally, how can "Option Explicit" type dimensioning requirements come to be in my module without my having set them? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Yes, Option Explicit is module level. However, I have never heard of a good
reason not to use it. There is the setting ToolsOptionsEditorRequire Variable Declaration, which will add "Option Explicit" to all subsequently created modules, but not existing ones. NickHK wrote in message oups.com... I am getting the errors normally associated with using undimensioned variables in an Option Explicit module. But I haven't set Option Explicit on that module nor anywhere else in my project (an Excel 2K3 workbook with some VBA routines). If I dim the variables, the problem goes away. So, I can work with it, but the problem is contrary to my understanding of "Option Explicit". My understanding is that "Option Explicit" only operates at module level (says so in the Help file), but this I haven't done. ***Is it possible for a third party addin to somehow set "Option Explicit" at the application level? The reason I ask is that the only machine out of 11 which has the problem is one which has a third party add-in installed. Some of the add-in code is exposed and uses "Option Explicit", though, as expected, on a per-module basis. Perhaps there is some code for the add-in that I can't see. ***More generally, how can "Option Explicit" type dimensioning requirements come to be in my module without my having set them? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Nick. Yep, it's not caused by that option as it isn't selected.
6 lines of code, 2 variables, acceptable time for completion. Simple stuff. No burning need to dim those, other than this weird behaviour. Also it's just slopping around with some test code before using it in the real thing (it gets dimmed there), and don't want to have to dim every variable as I introduce or delete it as it takes longer to finish playing about with it. You're right though, the need to not use Option Explicit is relatively marginal. Am mostly looking to solve the mystery or to discover if my Excel installation is doing things that it shouldn't do. NickHK wrote: Yes, Option Explicit is module level. However, I have never heard of a good reason not to use it. There is the setting ToolsOptionsEditorRequire Variable Declaration, which will add "Option Explicit" to all subsequently created modules, but not existing ones. NickHK |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Well, if you do not have Option Explicit at the top of that module, I cannot
see how you would get : "Compile Error Variable not defined" Any undefined variable would take its default value depending on its data type. NickHK wrote in message oups.com... Thanks Nick. Yep, it's not caused by that option as it isn't selected. 6 lines of code, 2 variables, acceptable time for completion. Simple stuff. No burning need to dim those, other than this weird behaviour. Also it's just slopping around with some test code before using it in the real thing (it gets dimmed there), and don't want to have to dim every variable as I introduce or delete it as it takes longer to finish playing about with it. You're right though, the need to not use Option Explicit is relatively marginal. Am mostly looking to solve the mystery or to discover if my Excel installation is doing things that it shouldn't do. NickHK wrote: Yes, Option Explicit is module level. However, I have never heard of a good reason not to use it. There is the setting ToolsOptionsEditorRequire Variable Declaration, which will add "Option Explicit" to all subsequently created modules, but not existing ones. NickHK |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"don't want to have to dim every variable as I introduce or delete it as it
takes longer to finish playing about with it" And you don't find that it's too easy to mistype a variable name and get unexpected results, if the lack of Option Explicit allows you to use an undeclared variable? For example, this sub will produce a message box with a value of zero rather than ten, and it may take minutes to notice the misspelling. Sub TestRange Set MyRange = ActiveSheet.Range("A1:A10") MsgBox MyRnage.Rows.Count End Sub This type of problem is eliminated if Option Explicit is used, as it will detect the misspelled variable when the sub is compiled or first run. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ wrote in message oups.com... Thanks Nick. Yep, it's not caused by that option as it isn't selected. 6 lines of code, 2 variables, acceptable time for completion. Simple stuff. No burning need to dim those, other than this weird behaviour. Also it's just slopping around with some test code before using it in the real thing (it gets dimmed there), and don't want to have to dim every variable as I introduce or delete it as it takes longer to finish playing about with it. You're right though, the need to not use Option Explicit is relatively marginal. Am mostly looking to solve the mystery or to discover if my Excel installation is doing things that it shouldn't do. NickHK wrote: Yes, Option Explicit is module level. However, I have never heard of a good reason not to use it. There is the setting ToolsOptionsEditorRequire Variable Declaration, which will add "Option Explicit" to all subsequently created modules, but not existing ones. NickHK |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I understand your point Jon and it makes sense.
Horses for courses I guess. I can type 60WPM @ 99% accuracy. I type code slower than that and rarely mistype things. I find experimentation easier without Option Explicit. That's my experience. Who knows, maybe I'm fooling myself... doesn't really matter. Any ideas on why I might be getting those errors when not using Option Explicit? It still seems mighty peculiar. Jon Peltier wrote: "don't want to have to dim every variable as I introduce or delete it as it takes longer to finish playing about with it" And you don't find that it's too easy to mistype a variable name and get unexpected results, if the lack of Option Explicit allows you to use an undeclared variable? For example, this sub will produce a message box with a value of zero rather than ten, and it may take minutes to notice the misspelling. Sub TestRange Set MyRange = ActiveSheet.Range("A1:A10") MsgBox MyRnage.Rows.Count End Sub This type of problem is eliminated if Option Explicit is used, as it will detect the misspelled variable when the sub is compiled or first run. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ wrote in message oups.com... Thanks Nick. Yep, it's not caused by that option as it isn't selected. 6 lines of code, 2 variables, acceptable time for completion. Simple stuff. No burning need to dim those, other than this weird behaviour. Also it's just slopping around with some test code before using it in the real thing (it gets dimmed there), and don't want to have to dim every variable as I introduce or delete it as it takes longer to finish playing about with it. You're right though, the need to not use Option Explicit is relatively marginal. Am mostly looking to solve the mystery or to discover if my Excel installation is doing things that it shouldn't do. NickHK wrote: Yes, Option Explicit is module level. However, I have never heard of a good reason not to use it. There is the setting ToolsOptionsEditorRequire Variable Declaration, which will add "Option Explicit" to all subsequently created modules, but not existing ones. NickHK |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Any ideas on why I might be getting those errors when not using Option
Explicit? It still seems mighty peculiar. I have no suggestion for this, sorry. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ wrote in message ups.com... I understand your point Jon and it makes sense. Horses for courses I guess. I can type 60WPM @ 99% accuracy. I type code slower than that and rarely mistype things. I find experimentation easier without Option Explicit. That's my experience. Who knows, maybe I'm fooling myself... doesn't really matter. Jon Peltier wrote: "don't want to have to dim every variable as I introduce or delete it as it takes longer to finish playing about with it" And you don't find that it's too easy to mistype a variable name and get unexpected results, if the lack of Option Explicit allows you to use an undeclared variable? For example, this sub will produce a message box with a value of zero rather than ten, and it may take minutes to notice the misspelling. Sub TestRange Set MyRange = ActiveSheet.Range("A1:A10") MsgBox MyRnage.Rows.Count End Sub This type of problem is eliminated if Option Explicit is used, as it will detect the misspelled variable when the sub is compiled or first run. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ wrote in message oups.com... Thanks Nick. Yep, it's not caused by that option as it isn't selected. 6 lines of code, 2 variables, acceptable time for completion. Simple stuff. No burning need to dim those, other than this weird behaviour. Also it's just slopping around with some test code before using it in the real thing (it gets dimmed there), and don't want to have to dim every variable as I introduce or delete it as it takes longer to finish playing about with it. You're right though, the need to not use Option Explicit is relatively marginal. Am mostly looking to solve the mystery or to discover if my Excel installation is doing things that it shouldn't do. NickHK wrote: Yes, Option Explicit is module level. However, I have never heard of a good reason not to use it. There is the setting ToolsOptionsEditorRequire Variable Declaration, which will add "Option Explicit" to all subsequently created modules, but not existing ones. NickHK |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Option Explicit | Excel Discussion (Misc queries) | |||
option explicit | Excel Discussion (Misc queries) | |||
Option Explicit | Excel Programming | |||
Option Commands (Option Explicit / Option Base etc) - Scope | Excel Programming | |||
Option Explicit | Excel Programming |