I'm trying to declare and initialize a variable on the same line. Essentially I'm trying to combine these two lines:
Dim quantity As Integer
i = 10
...into a single line. I know it's possible by saying "Dim i As Integer: i = 6", but that's cheating; it's not really a single statement. Plus, it's not as readable, and it forces me to type "quantity" twice. With long variable names that's a pain.
I've read on http://msdn.microsoft.com/en-us/library/7ee5a7s1.aspx that you can say:
Dim quantity As Integer = 10
...but that doesn't work for me. There's a compile-time error. The VBA editor highlights the line in red as I type it, and if I try to run the code I get "Compile error: Syntax error." Anybody know what's going on? I assume msdn.microsoft.com should be a reliable source... why isn't their code sample working?
Bookmarks