My Little Pony, sorry, my first little macro

User avatar
LineLaline
2StarLounger
Posts: 194
Joined: 19 Sep 2022, 16:51

Re: My Little Pony, sorry, my first little macro

Post by LineLaline »

ChrisGreaves wrote:
04 Jan 2023, 20:11
LineLaline: Would you like to write a little Word/VBA exercise that will deliver you
(1) A general-purpose function that can be stored in a library
(2) Will be usable and useful in every VBA application that you write
(3) Is easy to write
(4) Requires no complicated code

I know that you have a lot on your plate right now, but since you are just starting in VBA, such an exercise might be a good exercise because it is independent of any work, in VBA or out of VBA, that you are tackling right now.
That is, you could pick it up, work on it, then put it down for, say half an hour three times a week.
Cheers, Chris
Yes yes yes yes yes!
I am very curious 😊
Since I've really never done this before you'd have to be very clear. Plus: as a teacher I may be a pain in the neck :laugh: For which I apologise in advance and if I am not a pain in the neck doing this, I may at some point be anyway so you can use the apologies whenever you feel you need to implement them.
Ceci n'est pas une signature.

User avatar
LineLaline
2StarLounger
Posts: 194
Joined: 19 Sep 2022, 16:51

Re: My Little Pony, sorry, my racing Thoroughbred horse

Post by LineLaline »

DocAElstein wrote:
04 Jan 2023, 21:21
Going a bit off course, "Hijacking" a Thread as its called, usually sends a lot of Moderators at large forums into a narcissistic rage and they kill the Thread, and I think they would kill the participants as well if they could. Going too far off course can be bad, and starting from scratch a totally different subject is of course stupid, and often done by mistake so a Moderator should catch that. But quite often, just as in real life, IMO, furthering a discussion and being a bit open minded often gets useful results, that is the way the human brain works. At least mine has got some pretty impressive results that way. (Politics can be a bit tricky though. As Politicians just go around in circles like arguing children getting nowhere, it’s probably best to avoid those discussions too much as they might fall into a pointless never ending pit)
I also would have thought that adding solutions to a thread, or asking similar questions is preferable to swamping yet more duplicated stuff into an already overcrowded internet. I notice the situation getting worse at most forums. The short answer merit star chasing Zombies will kill themselves off eventually I expect. I know the owner of one major forum that is heavily monetised is about to flick the switch to read only as he only pretends to like his moderator and volunteer Admin teams that have taken over and run the place, after a fashion. For business, ( views of the Ads), its better if people visiting stay there a bit longer looking for the answer, or trying to get with help the answer themselves, rather than dropping off a quick question , going away and waiting for one of the question answering zombies to answer. For questions of any significance you can forget the places anyway these days.
Eileen’s Lounge seems a bit more tolerant to useful and enjoyable furthering of discussions. Could be the smaller size. Less infected with people with Narcissistic personality disorder – the larger forums seem to attract them and I know of one very prominent and senior member officially diagnosed with this disorder being sent to a forum to keep her out of the real world..
I wanted to remove much of this quote to save space but it's so useful and wonderful that i decided to let all the above in.
I have seen a Moderator Ego in action, as well. People were just having fun in the 'leisure department' when a mod removed some comments, which perplexed us, we asked why (no answer), then we had fun making fun of that decision, and the mod went on a rampage. They removed and blocked members, others left after having been on that forum for years and years, and at some point the faithful old members created a new forum which was much more tolerant. And more fun.

I joined this forum not really knowing a lot about it; I just read a few topics and thought 'Hey, they know what they're talking about' and it almost felt like it consisted of a bunch of people who knew one another and had for years. So, I joined. I only now even discovered the setting to change the font size, and I added an avatar which I will regularly change. And while things sometimes go off topic, they are just a little meandering to flow back to the river as just happened with Chris suggesting sending me some VBA instructions. Meandering helps. It's how the human brain works.
DocAElstein wrote:
04 Jan 2023, 21:21
Chris’s existence here is also helpful factor, (I mean to encourage furthering a discussion, he is very welcome in the real world as well)
I don't know Chris as well as you do but I feel you are right, welcome here and in the real world. His personality shines through in his words and I am glad he is in this forum.
Ceci n'est pas une signature.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: My Little Pony, sorry, my first little macro

Post by ChrisGreaves »

LineLaline wrote:
05 Jan 2023, 12:09
... Plus: as a teacher I may be a pain in the neck :laugh: ...
LineLaline, we will talk.
Be aware that practically everyone has their own ideas of what constitutes "proper VBA" or even "proper programming" for that matter.
As far as "pain in the neck" goes, you may want to dabble in Polls in Eileen's Lounge to gauge which of us gets a higher rating as Pain-In-The-Neck.
Cheers, Chris
Untitled.png
You do not have the required permissions to view the files attached to this post.
He who plants a seed, plants life.

User avatar
Jay Freedman
Microsoft MVP
Posts: 1320
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: My Little Pony, sorry, my first little macro

Post by Jay Freedman »

I'm sorry, Chris, that I mentioned using colons to create multistatement lines. In real code, I wouldn't use them either.

In my defense, the mention was in the context of the Immediate window. I was thinking of something like this:

Code: Select all

For i=11 to 15:print ActiveDocument.Styles(i).NameLocal:Next i
Body Text First Indent 2
Body Text Indent
Body Text Indent 2
Body Text Indent 3
Book Title
There's no other way to execute a loop in the Immediate window.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: My Little Pony, sorry, my first little macro

Post by ChrisGreaves »

Jay Freedman wrote:
05 Jan 2023, 20:24
I'm sorry, Chris, that I mentioned using colons to create multistatement lines. In real code, I wouldn't use them either.
Oh Goody! Now I can apologize to YOU! :grin:

I have since gone back and found your original post "The Immediate window lets you execute ..." and must confess that I had not considered colons as the only means to allow a loop in the Immediate Window. Well done! :clapping:

More than anything I am glad that we are of the same mind when it comes to colonized-lines (segue to English usage here). Over the years I have found that they create more problems that they solve.
Cheers and thanks, Jay :hailpraise: :hugs:
Chris
He who plants a seed, plants life.

User avatar
DocAElstein
5StarLounger
Posts: 602
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: My Little Pony, sorry, my first little macro

Post by DocAElstein »

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
Image
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(