Message boxes (VBA): how can I include/use them in my Excel Macros? - debugging

I'm teaching myself (read hacking) through some old Excel Macros that are quite long. However, as I change quite a few lines I want to be sure that I know when and where my new and re-hashed elements are occuring - or not. So my question/s is:
How do I insert a simple message box function that will pop up when a loop/procedure/event has finished?
Add text to it explaining what happened (hard coded ofcourse)?
Also, include an "OK button" that makes it start the next procedure?
The breakpoint process may be the most effective way of doing this, but I would like to use the message box approach so that I can show my colleagues what is happening. Also it would be something that I'd like to incorporate into future projects.
Many thanks for any examples, links or helpful hints.
Michael.

Just use
MsgBox ("message here")
And if you want to go to the code so that you can debug from there on use CTRL + BREAK

Related

In Visual Studio Code, is it possible to Edit the MiniMap View with settings

I'm updating some legacy code, because of my unfamiliarity to it, Its very difficult to find structures, especially if I step away for a week for other projects.
To alleviate this problem I've gone back to my old-school roots and started adding ascii text-art as comments above sections of code, using this tool:
http://patorjk.com/software/taag/#p=display&h=3&v=1&f=Big%20Money-ne&t=Reveal%0ACheck
This allows me to see via my MiniMap the titles of functions or sections of code I might need to come back to
The Thought then occured.. well surely someone else has this problem, and since VSCode seems to be written by the community, maybe someone has already written a plugin that would search the code for function titles (like Javadocs?) and display the title in a readable size?
If not, would it be easily coded? i.e. is the minimap just a very shrunk down copy(not easy) or is it structured and can be parsed and tweaked?
As long as your language plugin supports it, you can use cmd + shift + o to go to function definition.
All functions should also be listed in the Side Bar under "Outline"

putting image and text in a "scrollable box" for use with contextmenu

I am junior i C# coding, learned things in console output.
Now i am trying to understand the forms better and trying to make an app in windows form.
My goal is to do a foreach( do enumration) loop what is pinging some hosts from file.
This part i succeeded.
Now i want to present this in a form wiht the next layout.
hostname(text) ipadress(text)
i want the line to be selectable for a contextmenu.
I tried to do it in a textbox, but no succes, so i wanted to try it in a richtextbox but i am not sure if this is the proper choice.
Does anyone know what kind of control i have to use to achieve my goal, and which methods i should use.
I am not asking for writing me the whole code, just help me to think in the right way.
Your help would be very appriciated.
thanks.

Excel VBA - Is there a TextChanging / TextChanged or a similar event? Or how to move a selection without using Enter?

I have recently been asked if I could make a macro in Excel VBA that will allow a user to type in two numbers and have it automatically drop to the next row. The purpose of this is so they can type in grades for a test two numbers at a time without pressing enter since they aren't great at typing.
When I first heard this he mentioned it was Visual Basic, so I figured I'd just use a TextChanging or TextChanged event in the cell range and have it work off that. However, I haven't been able to find any such event or anything resembling it in the documentation thus far. The first thing that I came across was Workbook_Change, but that only changes after you press enter which is useless to me. Someone else mentioned there is such an event, but couldn't name it directly and I haven't been able to find what they were talking about.
If anyone has any information on if such an event exists or is possible I'd love to know.
The Excel version is 2007 as far as I'm aware.
This, in my opinion, requires a non-programming solution. I absolutely sympathize - it is tough to watch people get old - but you have to draw the line somewhere - for their sake and yours. The enter key is the most basic part of a computer. You could probably write a macro that would automatically hit enter on every even(or odd depending) keystroke in excel - but you're going to run into other problems like not being able to use delete normally. And what if you do want to put a string of text in a cell(like the student's name)? Perhaps it is time to find a non-programming solution. By that I mean someone should have a candid conversation with him about how he wants to solve the problem. Personally, I would offer to type the numbers in for him, as I am accustomed to the number pad - but it is probably better to be more direct and start to discuss retirement.
See this discussion about the limitations of cell edit mode in excel:
http://www.mrexcel.com/forum/excel-questions/524860-call-macro-every-keystroke.html
If you're really heart-set on a programming solution, I would recommend some kind of keystroke logging add-in.
Good Luck.
You could use the Worksheet_SelectionChange event. It is triggered without enter, but it would be triggered a lot.
You could however also create a special user-form for typing in the data, but this might be more work than necessary.
The main problem with using my suggested event is, you will need it as trigger and trigger it yourself, when selecting the next row, so disable event handling before changing the selection.
Edit:
This is a quick solution (paste this into the vba-code of the desired worksheet):
Private Const clngColumnRightToLastGrade = 5
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = clngColumnRightToLastGrade Then
Application.EnableEvents = False
'offset selection, one row down, two cols to left
Target.Offset(1, -2).Select
Application.EnableEvents = True
End If
End Sub
This will set you one row down and to column C, everytime your selection changes to column E (=5).
You don't have to use a constant of course, you could specify the column to sense in the workbook, so your user might modify it easier by himself.
To make this as an optional feature, you could extend it to autogenerated code. What I have in mind is like a Ribbon-Button, which opens a setupForm to configure, and a Ribbon-Button to activate the configuration, which would place this code in the configured sheet. But this might be a bit over the top.
In Excel 2003, (may be different in Excel2007 ?!) the WorkSheet_Change event is triggered every time the value of a cell is changed wether it is by pressing enter, delete, selecting an other cell after modifying a cell or even when a vba script changes the value of a cell.
I would do something like that:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RefRange As Range
Set RefRange = Intersect(ActiveSheet.Columns("??????????"), ActiveSheet.UsedRange)
If Not Intersect(Target, RefRange) Is Nothing Then
Target.Offset(0, 1).EntireColumn.Range("A1").Select
'Target.Offset(0, 1).EntireColumn.Range("A65536").End(xlUp).Offset(1,0).Select
End If
End Sub

Is "tip-of-the-day" good? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Many programs (often large ones, like MS Office, The GIMP, Maxthon) have a feature called "tip-of-the-day". It explains a small part of the program, like this one in Maxthon:
"You can hide/show the main menu bar by pressing Ctrl+F11"
You can usually browse through them by clicking next. And other options provided are "Previous", "Close", "Do not show at startup".
I think I like the way Maxthon used to handle this; in the browser's statusbar (down at the bottom usually, together with "Done", the progress-bar etc), there would sometimes be a small hint or tip on what else you could do with it.
As Joel Spolsky wrote in his article-series "User Interface Design for Programmers", people don't like reading manuals. But we still want them to use the program, and the features they could benefit from, don't we? Therefore, I think it is useful to have such a feature, without the annoyance of the pop-up on startup.
What do you think? Pop-up? Maxthonstyle? No way?
I really only like the idea of a "tip of the day" if it is displayed when I can't do anything else anyway. For example, when the program is loading a large file. Suppose it has to load some large amount of data when the program is first started. Along with the "loading" splash screen, show a small tip, and have it disappear when the program starts. It's simple, unobtrusive, and can sometimes be very helpful to some users.
I hate to bring up "World of Warcraft" as an example in a programming discussion, but it uses this technique when you first login. Here is an example loading screen. Along with the loading bar and a full screen piece of art, it displays a small tip at the bottom of the screen. Usually these tips lead users to things they can explore further (such as a settings window, character customization tools, etcetera). For example, "Pressing ESCAPE will bring up a menu that lets you customize the the look and feel of the game".
Above all else: allow the user to easily close the tips and stop them from appearing each time. Make every key close the tip dialog when pressed. Have two buttons: "Close Tip" and "Close Tip and Never Show Again", or something to that effect.
It must be easy to banish the tips---but when learning a new GUI, I use them often. If it's a tip at startup I usually turn it off after at most a dozen runs, but if tips are well designed this gives me a sense of the application space.
Ways tips could be improved:
Don't tip a user about a feature that user has used recently.
Making tips sensitive to context can be helpful (the new Vista bars are an example --- pause to get the vapors; I have just said something nice about Vista).
Tips that are unobtrusive or appear during otherwise wasted time are good.
Tip during loading screen is good, but it must be findable after loading is over. Some popular game, maybe it was Baldur's Gate, would give you a tip during loading, and then afterward you could go back and review the tips in your journal. So if you had a vague memory of a useful tip a few screens back, you could find it quickly, in the same place you were accustomed to look for other recent information. A 'recently tipped' item on the help menu perhaps?
Actually, I've never heard of Maxthon. But I actually like those as long as there is a checkbox to make them stop. I like the tips to actually tell me something interesting instead of something very obvious in the UI. But this is really preference. I don't think it is bad design to use them.
No - I dislike them pretty strongly. When I am starting a software application, I almost always have a specific task in mind. The TOTD just interrupts this flow and tries to get me to think about the software rather than the task.
This might not be a direct answer to your question, but personally, I like the way StackOverflow handles this. The badge system essentially acts as a manual, rewarding users for discovering and utilizing the functionality it has to offer. Granted, this isn't really an option for most apps but it works beautifully for StackOverflow.
I think this goes along with the issues against modals -- it's something in a user's way, despite how helpful it may be. Which is why the "Do not show at startup" is needed.
Though I've never used Maxthon before, the way it showed tips sounds like a really good idea. It's unobtrusive and entirely optional as to if users even have to pay them any attention.
IMO, it's not good idea to have a feature that has to ask the user if it should "keep quiet." ;)
And, while some tips can seem blatantly obvious, even these tips can still be useful to users that aren't quite as familiar. Those that already know it can just continue on with their day.
A tip is a good idea, users can discover things they didn't know they didn't know. But rather than using a pop up getting in the way of working, I like how World of Warcraft does it. They put the tip on the loading screen, when you have nothing better to do then stare at the progress bar anyway.
Norman Ramsey made some great points about how tips could be improved. My problem with tips of the day (and I'm speaking as someone who's implemented them in my own apps) is that they are not timely and a bit too intrusive. The typical tip of the day comes up when you start the program, and requires a button click to make it go away. When I actually see a useful tip, my train of thought is usually "I'll have to remember that when I do option ". Of course, it's forgotten by the time I get around to using . And clicking OK during program startup gets old fast, I'll usually disable the tips after the first dozen or so.
My suggestion would be to go the next step and make the tip of the day much more context sensitive. For example, if the program detects that the user is constantly going to Edit | Copy and then Edit | Paste, a good tip would be "Not for nothing, but CTRL+C followed by CTRL+V accomplishes the same thing" and tell them right when they are clicking away at the menu like a lost monkey, not during program startup. Oh, and don't interrupt their work by forcing them to click OK.
What I just suggested - is that what that damn paperclip dude used to do?
IMO Tip of the day (popup) is only within programs that have a certain level of complexity, that you use frequently. So when you open the program you learn a new trick that will help you.
Usually people either like it or hate it, so definitely have an option to disable it.
What I'm worried about with the other type is that it will go unnoticed, you wont believe the areas of programs people never look at.
Maybe put it in something like a "tool tip" (or down at the bottom like the OP described) and make it contextual. A few seconds after you change to a new mode it slides in some text about the current mode.
And YES make the OFF button easy to find!!!
Personally, I prefer software that’s simple enough to not need “Tip of the Day”.
Tip of the day can be good if it's
non-modal, and never in the way
has a "history" I can access
is context sensitive to what I do
Unfortunately, the crappy initial Office implementation Clippy of has completely killed the last idea.
So IMO a good implementation would:
Show up at startup
Make "don't show at startup" the obvious choice
Indicate (with an animation?) that TOTD is accessible from e.g. the toolbar
MouseOver the toolbar icon would give the title/abstract of the "current tip"
clicking on it would give me the tip, give forward/backward navigation through tips,
link to "show all tips" in the manual.
For a large tip database, a "related tips" link might encourage me to explore the manual
Context-sensitive
Later incarnations of Clippy were almost helpful actually: it was nonmodal and stayed out of the way not requiring interaction (the jumping around was attention-grabbing, though), and I remember a few instances where the suggestion was good - e.g. a keyboard shortcut for a command I had accessed repeatedly through the menu.
A simpler method could still be effective:
"Did you know... you can customize the print templates to look like a pie chart on LSD - the manual shows you how! [clickety]" on a print dialog
Did you know... I can remember your custom searches. Just click 'Goof/Barf/Hidden/Create Index for last Query' - and they'll show up in the 'Search' menu. They'll run much faster, too! whe working with a search/query form

Captchas to force user interaction?

I'm currently working on a program that has many of those "the user SHOULD read it but he'll click OK like a stupid monkey" dialogs... So I was thinking of adding something like a captcha in order to avoid click-without thinking...
My ideas were:
Randomly change buttons
Randomly position buttons somewhere on the form
The user must click on a randomly colored word within the text he should read
add captcha
add captcha that includes the message for the user
Has anybody made any experience with such a situation. What would you suggest to do?
Well, you asked for opinions and here goes mine, but I don't think this is what you would like to hear...
Users like programs that they can depend on. They don't like when things change and they don't like to do extra work.
Randomly change buttons and Randomly position buttons somewhere on the form will only make them either press the wrong button or become annoyed with your application, because as you say, they don't read the text, and if you think about it, neither do we. As an example think of an Ok/Cancel dialog, you allways expect the ok button to be on the left, and most times i press it without reading it. It Will happen exactly the same with your users.
The user must click on a randomly colored word within the text he should read
add captcha
add captcha that includes the message for the user
With these 3 option you will add extra work to your application, your users will curse you for that. Just think of something that you would have to do 10x per day, let's say check in your code to source safe. How would you feel if your boss told you that from now on you will have to fill a captcha for each file you try to check in?
I think it's our jobs to make the lives of the people that use our software easier. If they must read some kind of text and they don't want to, there is absolutely no way you can make them do it.
You can´t make people work right, all you can do is provide them with the best possible tools and hope that they are professional enough to do their jobs.
So basically all i'm saying is, do your best to ease their work. If this is really important than you(or whoever is in charge) should talk to them and EXPLAIN WHY this is important.
You would be surprised on how people commit to things they understand.
I suggest that you don't; and that, unless you know better, you emulate respectable well-known, well-tested UIs like <big online retailer's> or <online banking site>.
Playing games with the user in order to get them to read messages is doomed. Users will focus mental resources on completing your game, rather than understanding the message. Your users may be less likely to actually understand the important part of the message if you have things like moved buttons, relabeling, scavenger hunts, captchas, or delays. They’ll focus on the instructions for the game, not on the real issue. Errors are likely to increase.
Users’ refusal to read message boxes is due to users wanting to get things done quickly rather than take the time to read stuff, and it is also due to message boxes being overused and misused so badly in so many apps. Including silly games in message boxes will just make users resent them all the more, compounding the problem.
Here’s what you can do:
Rule 1. Don’t use messages boxes. They should only appear for exceptional circumstances. An app should not have “many” message boxes. It should not be necessary to read a whole lot of documentation each time the user uses an app. If normal use of your app results in a message box, then your UI is wrong. Find another way.
Instead of verification messages, show clearly in the main window what has happened and provide a clear way to Undo it.
Use auto-correction, pictured/masked fields, and disabling rather than error messages.
Use good defaults and automation to avoid messages. For example, rather than showing an error message saying the user can’t upload because they’re not connected to the server, simply reconnect automatically.
Break commands along options. Rather that a message box to ask if the user wants paste with or without format, provide two different commands in the menu.
Don’t have information messages spontaneously popping up telling the user everything worked fine (e.g., “Preferences Saved!”)
Don’t have pop-ups providing helpful hints or documentation. Provide a tutorial or balloon help if you can’t make your UI self-documenting.
Don’t have nagging “upgrade me” messages.
Consider providing message text in the main window rather than in a separate message box (e.g., “Page may not look or act right because ActiveX is off for security.”). Pop-ups from web surfing have conditioned users to automatically dismiss anything that pops up as irrelevant.
Rule 2. If you have to use a message:
Make the text as brief as possible to get the key information across. More text is not equivalent to more helpful. Use “No match to [filemask] in [path].” Don’t use “Nonfatal Error 307: Search action aborted. [Appname] is unable to complete your string search for the regular expression you provided because the file mask you gave, namely [filemask], does not result in any matching files in the directory that you specified (which was [path]). Please check your filemask or path selection and again re-enter it or them in the Files to Search dialog box. Click the OK button below on this message box to return to the Files to Search dialog box. Click the Cancel Button on the Files to Search dialog when you get there to cancel your search for strings.” If there are some users who will need more explanation than can be achieved in a brief message, provide a Help button or a “How do I…” link in the message box.
Use plain language and no jargon in the message. That includes “innocent” words like “dialog,” “database,” and “toner.” Do not take raw exception text and throw it in a error message. Do not include any error numbers or dumps; log these instead. Purge your app of any debugging message boxes left by developers. Better to simply let the app disappear on a fatal error than to put up a message full of jargon and then the app disappears.
Label the buttons of a message box with what the action does, not “OK.” At the very least, the users have to focus on the activating button to dismiss a message box. If that button is labeled something like “Delete” or “Install,” it should give them pause. You should never have to explain in your message text what each button does. BTW, such labeling is a GUI standard on most platforms.
Redesign your application so that it does not use message boxes.
My suggestion, live with it or redesign your dialogs/interface. Do not add randomness to dialogs or otherwise treat the user like an idiot, even though you may think most are :-).
I just recently read a Joel on Software article, Designing for People Who Have Better Things To Do With Their Lives. It makes the point that most people won't read anything and discusses ways to work around that or at least not make it worse.
You could try with a timer which waits for the "supposed reading time" before enabling the submit button. You can even calculate the supposed reading time from the number of words.
I think that subtle ways to force the user to read your text (like moving around buttons or asking them to read a captcha) can make them feel like stupid monkeys.
You could use a choice question based on what the user should read.

Resources