Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Option Explicit

With this new feature, it seems everything must be defined. It just told me
that "i" in my do loop was undefined. How should I dimension this?

Thanks,
Grace


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Option Explicit

Hi Grace

that's the purpose of option explicit (and by the way, its not a new
feature - it must not have been turned on in your previous version)

if i is a counter you can use

dim i as long

cheers
JulieD

"Grace" wrote in message
...
With this new feature, it seems everything must be defined. It just told

me
that "i" in my do loop was undefined. How should I dimension this?

Thanks,
Grace




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Option Explicit

Hi Grace,

For a full discussion of Option Explicit go to Chip Pearson's page:
http://www.cpearson.com/excel/DeclaringVariables.htm

In this particular case, Option Explicit is telling you that i has not been
dimmed (dimensioned).
Solution: At the top of the Sub type:
Dim i as long

---
Regards,
Norman


"Grace" wrote in message
...
With this new feature, it seems everything must be defined. It just told

me
that "i" in my do loop was undefined. How should I dimension this?

Thanks,
Grace




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Option Explicit

Thanks, Norman, and Julie, and Bob.

Grace

"Norman Jones" wrote in message
...
Hi Grace,

For a full discussion of Option Explicit go to Chip Pearson's page:
http://www.cpearson.com/excel/DeclaringVariables.htm

In this particular case, Option Explicit is telling you that i has not

been
dimmed (dimensioned).
Solution: At the top of the Sub type:
Dim i as long

---
Regards,
Norman


"Grace" wrote in message
...
With this new feature, it seems everything must be defined. It just

told
me
that "i" in my do loop was undefined. How should I dimension this?

Thanks,
Grace






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Option Explicit

The beauty of this feature is that it can capture typos, because each
variable must be explicitly declared.

Consider this code

For iRowCounter = 1 To 500
If Cells(iRowCounter,"A").Value = "" Then
Cells(iRowCoanter,"B").Value = "X"
End If
Next i

IF you don't have Option Explicit, it will run okay, but not work as the
variable is mis-spelt in the action statement. If you have Option Explicit,
it will not compile, so you will immediately force you to correct it. Could
save hours of debugging.

--

HTH

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

"Grace" wrote in message
...
With this new feature, it seems everything must be defined. It just told

me
that "i" in my do loop was undefined. How should I dimension this?

Thanks,
Grace






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Option Explicit

Bob Phillips wrote:

The beauty of this feature is that it can capture typos, because each
variable must be explicitly declared.

Consider this code

For iRowCounter = 1 To 500
If Cells(iRowCounter,"A").Value = "" Then
Cells(iRowCoanter,"B").Value = "X"
End If
Next i

IF you don't have Option Explicit, it will run okay, but not work as the
variable is mis-spelt in the action statement. If you have Option Explicit,
it will not compile, so you will immediately force you to correct it. Could
save hours of debugging.

In fact, the above code won't run okay even without Option Explicit,
first because the Next i line will cause the "Invalid Next control
variable reference" error (a compile error), second because the
iRowCoanter line will cause the "Application-defined or object-defined
error" (a runtime error). An example to make the point could be:

For iRowCounter = 1 To 500
If Cells(iRowCounter, "A").Value = "" Then
Cells(iRowCoanter + 1, "B").Value = "X"
End If
Next iRowCounter

Alan Beban
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Option Explicit

Nit-picking point that adds nothing to the point being made.

Bob


"Alan Beban" wrote in message
...
Bob Phillips wrote:

The beauty of this feature is that it can capture typos, because each
variable must be explicitly declared.

Consider this code

For iRowCounter = 1 To 500
If Cells(iRowCounter,"A").Value = "" Then
Cells(iRowCoanter,"B").Value = "X"
End If
Next i

IF you don't have Option Explicit, it will run okay, but not work as the
variable is mis-spelt in the action statement. If you have Option

Explicit,
it will not compile, so you will immediately force you to correct it.

Could
save hours of debugging.

In fact, the above code won't run okay even without Option Explicit,
first because the Next i line will cause the "Invalid Next control
variable reference" error (a compile error), second because the
iRowCoanter line will cause the "Application-defined or object-defined
error" (a runtime error). An example to make the point could be:

For iRowCounter = 1 To 500
If Cells(iRowCounter, "A").Value = "" Then
Cells(iRowCoanter + 1, "B").Value = "X"
End If
Next iRowCounter

Alan Beban



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
Option Explicit [email protected] Excel Discussion (Misc queries) 5 April 30th 08 11:19 PM
option explicit Dave F Excel Discussion (Misc queries) 2 September 5th 06 02:46 PM
Option Explicit Error Bob[_44_] Excel Programming 3 December 31st 03 08:16 AM
Implied Option Explicit in XP?? Trip[_2_] Excel Programming 3 November 13th 03 12:24 AM
Option Explicit and Arrays Harlan Grove[_5_] Excel Programming 3 July 22nd 03 12:51 AM


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