Jay Freedman wrote: ↑05 Jan 2023, 20:24
... using colons to create multi statement lines. In real code, I wouldn't use them either.
......the mention was in the context of the Immediate window.
I saw it in the context of the
Immediate Window.
I think that could be useful, for example, as you suggest with looping. I expect I may notice some other advantages, now I have that added to my “
Immediate Window toolbox”. So I am glad you mentioned it.
I don’t think anyone would have thought from what you wrote that you were encouraging using the colon extensively to create a lot of
multi statement lines in real code.
( Perhaps something I wrote in response to your post mislead Chris a bit. I was showing the similarity in the constructs using the colon in the Immediate Window and real coding. I responded to him to clarify that I was not particularly keen either on using the colon in real coding to construct multi line statements, at least not just for the sake of reducing the amount of physical lines. )
I think once in a while there could be an advantage of using the colon to create a
multi statement line or two in real code, but I have rarely seen anyone use them extensively in real coding.( I have occauisionally seen a newbie mistakenly think they had compacted
I am not sure what the line limit is in a code module, but for the typical macro use I don’t think very often anyone comes near to hitting the limit. I think the philosophy around macros is that they are for automating some things in an Office application so by definition are not going to be massive usually. Really long stand alone coding I expect would not be done with VBA very often.
So I doubt anyone would be forced to use colons to create multi statement lines in order to reduce the number of phsical lines in a macro.
( I have occasionally seen a newbie mistakenly think they had compacted and made a coding more efficient by putting all the code lines on one line , each line separated with a colon. Of course that is stupid. Mostly all they have done is to transpose the list of code lines from a vertical list to a horizontal list. In other words they have made a
multi statement line ,
Hopefully its clear now that most of us regard the
multi statement line as usually not desirable in real coding, at least not just for the sake of it. There might once in a while be an advantage of one or a few in a coding that is otherwise mostly constructed using single statement lines )
_.__________________
If I was forced to give just one tool to recommend when learning VBA, then I expect it would be the Immediate window, ( and then I would cheat and try to say something like, …. Of
course learn also to step through the coding in Debug (F8) mode as well when using it ……)
(
Ref: Immediate Window Blog: https://eileenslounge.com/viewtopic.php ... 21#p247121 )
_.____
BTW, just for completeness, back to that
little demo I did ….. – I just noticed that to get multiple output from a single physical line typed in the
immediate Window then I can indeed also use the colon. I am not restricted to building a string for output using the semi colon as I demonstrated. I had just overlooked on that occaision that I will need to include again the ? or
Debug.Print once again after the colon. ( I will get the values though listed vertically using the colon way: The semi colon way I showed previously will get them listed horizontally )
https://i.postimg.cc/sDD81kTT/Immediate ... -Colon.jpg