7

This is the most bizarre question I've ever asked. I'm not even sure how to phrase it. I remember something like this happening way back in the VB6 IDE, but I've forgotten the fix. If this is the case, then this is a really old bug in the VB IDE.

Here's the problem:

I'm writing a simple MS Word macro when I accidently typed:

Dim cell as Cell

This activated the dreaded IDE bug. Now, no matter what I do; remove the module, edit it outside the IDE or whatever, the IDE's intellisense formats the variable type "Cell" as "cell"

If I name a new variable:

Dim tcell as Cell

The IDE changes it to:

Dim tcell As cell

This infuriates me to no end. I've tried everything to no avail. This happens even if I edit the module file (.bas) outside of the IDE and reimport it back.

How can I stop this madness?

Updated

Apparently this behavior is not a bug, but by design. See answer.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
GeneQ
  • 7,485
  • 6
  • 37
  • 53
  • Possible duplicate: [How does one restore default case to a variable in VBA (Excel 2010)?](http://stackoverflow.com/questions/4852735/how-does-one-restore-default-case-to-a-variable-in-vba-excel-2010/4852999#4852999) – mwolfe02 Jun 02 '11 at 14:40
  • 1
    @mwolfe02 You got a point there. But unless the Excel question is tagged and asked differently, it's be hard to find the answer. I couldn't find that answer because I looked for Inteliisense, case, IDE, Word and VBA; not Excel, Editor and VBA. Also, I suggest rephrasing the Excel question so that it becomes a general VBA question instead of simply an Excel one. – GeneQ Jun 03 '11 at 02:00
  • I tend to agree with you. In fact, that's why I posted the link but did not vote to close. – mwolfe02 Jun 03 '11 at 13:10

2 Answers2

6

Try putting a

Dim Cell as Cell

somewhere, then delete it and try again... I seem to recall that variable declarations take precedence in setting the casing, thus this should force the casing back to how it should be...

Simon Cowen
  • 1,903
  • 16
  • 20
  • 1
    That's brilliant. It works. It never occurred to me to try that. Wish I knew about this during my previous life as VB6 coder. No SO back then. ;-) Thanks. – GeneQ Jun 02 '11 at 14:10
0

VB/VBA variable names are not case sensitive so cell and Cell are the same. I would suggest you name your variables something else - I personally use a letter in front: e.g.

Dim sString as String 's for string
Dim iInt as Integer 'i for integer
Dim oCell as Cell 'o for objects

Hope this helps

Harag
  • 1,532
  • 4
  • 19
  • 31
  • 4
    Not everyone enjoys Hungarian notation though (I'm counting myself in there), Microsoft's own style guidelines now recommend against it, and referring to and answer on Q111933: "vUsing adjHungarian nnotation vmakes nreading ncode adjdifficult." (credit to Mark Stock for that one) – Simon Cowen Jun 02 '11 at 11:48
  • He said he _accidentally typed_ Dim cell as Cell. – ray Jun 02 '11 at 13:26
  • Just to clarify. By accident, I meant that I knew of this annoying behavior and have been consciously avoiding to trigger it, until today that is, when I got careless and triggered it. – GeneQ Jun 02 '11 at 14:12
  • 1
    @Simon - I understand that everyone doens't enjoy Hungarian notation and that MS now recommend against it. but for language that isn't case sensitive I personally think reading "Dim Cell as Cell" just looks weird, but putting Dim c as Cell - then makes it difficult for anyone else to follow your code as the variable "c" isn't descriptive enough. I'm now personally trying to get away from the Hungarian notation, but find it difficult to get out of the habit. – Harag Jun 02 '11 at 15:22
  • 1
    [Making Wrong Code Look Wrong](http://www.joelonsoftware.com/articles/Wrong.html): A great read on the difference between the *original* Hungarian notation (aka, Apps Hungarian) and its much more mainstream, much less useful ugly sibling, Systems Hungarian. – mwolfe02 Jun 03 '11 at 13:18
  • @mwolfe02: If only people actually used it this way... poor Simonyi. (although less so since I read that he's married to a millionaire's daughter 32 year his junior, has been to the ISS, and spends 6 months a year on his 233 foot super-yacht)... – Simon Cowen Jun 03 '11 at 15:03
  • @harag: At least your trying to break the habit, I'm pretty sure that's more than many are doing! – Simon Cowen Jun 03 '11 at 15:03
  • @Simon cowen thanks, though I am finding it difficult to break and find myself automatically typing s, i and o's in front of variable names. I'm also finding that when I look over code that I don't put the letters at the front doublechecking that strings convert into ints etc - but the compiler is much better these days... – Harag Jun 03 '11 at 15:23