![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Just read this: http://thedailywtf.com/Articles/Feng-Shui.aspx ...and some commenters said that variable declarations of this form: Dim lng1, lng2 As Long ...would create a variant and a long. Now, I'd always thought that people said that it would make all the variables Longs, but I tested and it's correct that this doesn't work, i.e., that only the last variable is properly typed. |
#3
| |||
| |||
|
|
It's been that way as long as I can remember ... back to the mid 90s that is :-) David-W-Fenton wrote: Just read this: http://thedailywtf.com/Articles/Feng-Shui.aspx ...and some commenters said that variable declarations of this form: Dim lng1, lng2 As Long ...would create a variant and a long. Now, I'd always thought that people said that it would make all the variables Longs, but I tested and it's correct that this doesn't work, i.e., that only the last variable is properly typed. |
#4
| |||
| |||
|
|
...and some commenters said that variable declarations of this form: Dim lng1, lng2 As Long ...would create a variant and a long. |
|
Now, I'd always thought that people said that it would make all the variables Longs, |
#5
| |||
| |||
|
|
Just read this: http://thedailywtf.com/Articles/Feng-Shui.aspx ...and some commenters said that variable declarations of this form: Dim lng1, lng2 As Long ...would create a variant and a long. Now, I'd always thought that people said that it would make all the variables Longs, but I tested and it's correct that this doesn't work, i.e., that only the last variable is properly typed. Am I misremembering that people have recommeded that? It's not actually something I would ever do in my own code (I'm a one line per variable type of coder), but I always thought it was something you COULD do. Am I misremembering? It's certainly the case that it doesn't work! Public Sub test() Dim lng1, lng2 As Long Dim lng3 As Long, lng4 As Long Debug.Print VarType(lng1) = VarType(lng2) Debug.Print VarType(lng1) Debug.Print VarType(lng2) Debug.Print VarType(lng3) = VarType(lng4) Debug.Print VarType(lng3) Debug.Print VarType(lng4) End Sub (and in regard to the DailyWTF article, the programmer should turn on Option Explicit before starting any search and replace operation...) -- David W. Fenton http://www.dfenton.com/ contact via website only http://www.dfenton.com/DFA/ |
#6
| |||
| |||
|
|
One line per var declaration would be my recommendation too because it's less error prone to scan lists than sentences. |
#7
| |||
| |||
|
|
On Wed, 19 Jan 2011 03:27:09 -0000, "Stuart McCall" smccall (AT) myunrealbox (DOT) com> wrote: One line per var declaration would be my recommendation too because it's less error prone to scan lists than sentences. I declare as many as I can get on a line and still stay on the VBA code window. Which usually isn't many as I TendToUseLongVariableNames. And I use CamelCaseToCheckForTypos. |
|
Tony -- Tony Toews, Microsoft Access MVP Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/ For a convenient utility to keep your users FEs and other files updated see http://www.autofeupdater.com/ |
#8
| |||
| |||
|
|
Just read this: http://thedailywtf.com/Articles/Feng-Shui.aspx ...and some commenters said that variable declarations of this form: Dim lng1, lng2 As Long ...would create a variant and a long. Now, I'd always thought that people said that it would make all the variables Longs, but I tested and it's correct that this doesn't work, i.e., that only the last variable is properly typed. Am I misremembering that people have recommeded that? It's not actually something I would ever do in my own code (I'm a one line per variable type of coder), but I always thought it was something you COULD do. Am I misremembering? It's certainly the case that it doesn't work! Public Sub test() Dim lng1, lng2 As Long Dim lng3 As Long, lng4 As Long Debug.Print VarType(lng1) = VarType(lng2) Debug.Print VarType(lng1) Debug.Print VarType(lng2) Debug.Print VarType(lng3) = VarType(lng4) Debug.Print VarType(lng3) Debug.Print VarType(lng4) End Sub (and in regard to the DailyWTF article, the programmer should turn on Option Explicit before starting any search and replace operation...) -- David W. Fenton http://www.dfenton.com/ contact via website only http://www.dfenton.com/DFA/ |
#9
| |||
| |||
|
|
One line per var declaration would be my recommendation too because it's less error prone to scan lists than sentences. I declare as many as I can get on a line and still stay on the VBA code window. Which usually isn't many as I TendToUseLongVariableNames. And I use CamelCaseToCheckForTypos. I also use camel-case, but for readability, not typo checking. There's Option Explicit for that. |
#10
| |||
| |||
|
|
On Wed, 19 Jan 2011 18:28:49 -0000, "Stuart McCall" smccall (AT) myunrealbox (DOT) com> wrote: One line per var declaration would be my recommendation too because it's less error prone to scan lists than sentences. I declare as many as I can get on a line and still stay on the VBA code window. Which usually isn't many as I TendToUseLongVariableNames. And I use CamelCaseToCheckForTypos. I also use camel-case, but for readability, not typo checking. There's Option Explicit for that. Immediate feedback. If the VBA editor doesn't change the variable name to camel case instantly after hitting the space bar or return/enter then I know I've made a typo. I don't have to wait to hit the compile button. Tony |
![]() |
| Thread Tools | |
| Display Modes | |
| |