Visual Basic (VB) Forms: wait for a user click? - vb.net

I'm making a simple form that is to step through a program iteratively.
How can I get it to run a method each time a user clicks a button and wait once it is finished for the next click?

Maybe I'm not understanding your question very well, but is it like the "Next" button on a Wizard?
You can have a State variable to store the current "state", so at starup its has the value 1. when click "Next" then do the code for State=1 and then change to State=2 and so on.
Inside you Click event you can have a case statement to proceed according

You want to create a method that gets called when it sees the OnClick event.
The simplest way to do this is to double-click the button in the GUI Form Designer, and it will go to the code page and start the method for you with the correct syntax.

Related

How to prevent button clicks in a MS Access Form_A when Form_B is correctly displayed modal over Form_A

I realized while I was typing up this question what the problem might be and was then able to solve it. So, I have posted the question and then the answer in case it helps someone else.
I am using MS Access 2016. I have a Form_A that displays a menu of buttons--each button takes the user to a distinct form to perform whatever functions the user needs to perform. For example, one Form_A menu button could be [Add Clients] while another button could be [Add Staff], etc.
When the user first logs into the system, I use VBA code to do a number of "housecleaning" functions. Form_A and the buttons are visible, but I have made a Form_B that is a small dialog that shows the word "Working" with animated "..." while the VBA in Form_A does the housecleaning.
The problem that I cannot solve is that even though I have set Form_B's "Pop Up" property to "Yes" and its "Modal" property to "Yes", the user can still click buttons on the Form_A menu which then execute while Form_B is still doing its housecleaning.
I thought setting Form_B to modal should prevent button clicks on Form_A from getting registered.
More details:
In the Form_Load event, Form_A calls "housekeeping" code that resides in a Module. That module has a Public Sub called "RemakeTables." The RemakeTables code uses DoCmd.OpenForm "Form_B" to display the "Working" dialog.
The RemakeTables code calls several other Public subs. Between each call to the other Public subs, a DoEvents is called which allows for the "Working" dialog to animate the "..." (i.e., cycle between "Working", "Working.", "Working..", and "Working...").
My hunch is that the DoEvents is what is allowing clicks to get registered in Form_A.
How should I be doing this so that clicks cannot be registered while the Form_B "Working" dialog is showing but can still be animated?
As I was typing up the question, it occurred to me that the main problem was that the subs and functions I was calling during "housekeeping" used the DoEvents action to allow the Form_B "Working" dialog to update/animate. However, DoEvents also allows mouse clicks to register.
So, how to prevent the problem?
Include the "housekeeping" calls in the Form_Open event rather than the Form_Load event because the Form_Open event occurs first, before the Form_Load and before the form is displayed, so, there will not be any buttons visible to click if the "housekeeping" code is called in Form_Open.
Hope this helps someone else who might have had a similar problem.

Apex 5.0: Show a progress bar while Database Action is performed

Implementing a Waitbar or Progressbar
In my Apex 5.0 application I have a SQL Update which is taking very long to process, and I want to implement an indicator to show that it is still running, so that the user won't start the action again.
A progressbar would do the trick, can anyone suggest a way of doing so?
(plugins aren't possible)
Just Change the action of your SUBMIT button to Dyanamic Action
On dynamic action choose ON CLICK as Event .Choose Button for Selection Type and Choose Name of your submit Button to Button
Then on Action, Choose SUBMIT PAGE
Then on Request /Button Name, put your SUBMIT button's Name.
Then set SHOW PROCESSING to YES
Use the JavaScript function apex.sumbit to submit the page and include the showWait option to display the progress bar. Here is an example...
apex.submit({ request:"DELETE", set:{"P1_DEPTNO":10, "P1_EMPNO":5433}, showWait:true});

Triggering Visual Basic Keydown events without a specific function

I'm building on top of code that a previous developer has left me, and he left something that intrigued me quite a bit.
Basically on his menus, he has a TextBox to take in user input and a button next to it to submit the value of the TextBox (for example if the user wanted to select option 1, he would input 1 into the TextBox and click the button). However, the user could also press the Enter key while focusing the TextBox, and it would be treated as the submit button was clicked.
Now this is simple enough to do, but when I check the VB code behind the menu, there's no TextBox_Keydown(...) Handles TextBox.Keydown function anywhere, only the button click event. How is he doing this? He has several menus that are similar and I can't figure out how.
A standard dialog box, if not told to act otherwise, enter does default command button and escape does cancel. In VB look at the properties Default for the command button.
I discovered how he was doing it. He basically mapped the AcceptButton and CancelButton properties of the entire Windows Form to various button functions.

Keep form on top of another form in modal fashion, but continue execution

I have a form in a vb.net windows form application called PolicyRefreshStatus.vb that has a ProgressBar control on it. From the main form called EditPolicy.vb I need to show PolicyRefreshStatus.vb over top of EditPolicy.vb - but the way things are wired I'm controlling the the ProgressBar and it's steps from logic inside EditPolicy.vb.
If I display the PolicyRefreshStatus.vb bar using the .show() method things work fine. The problem is if the user clicks back on the main form then PolicyRefreshStatus.vb losses focus. If I show PolicyRefreshStatus.vb as a modal form using .ShowDialog() then execution halts in EditPolicy.vb after the .ShowDialog() statement.
so for example in the code:
mPolicyRefreshStatus = New PolicyRefreshStatus
mPolicyRefreshStatus.pbMax = mPolicy.ClaimsUpdateMax
mPolicyRefreshStatus.ShowDialog()
mPolicy.UpdateFromFIS()
The line mPolicy.UpdateFromFIS() never executes because it's waiting for the PolicyRefreshStatus form to close.
How can I show PolicyRefreshStatus in a modal form but let execution continue in EditPolicy.vb?
You've got a couple of related options.
This first is to pass the unit of work to the progress bar in the form of a delegate or a class implementing an Interface. Something like this (not checked for correctness, just a rough example):
mPolicyRefreshStatus = New PolicyRefreshStatus
mPolicyRefreshStatus.pbMax = mPolicy.ClaimsUpdateMax
mPolicyRefreshStatus.UnitOfWork = AddressOf(mPolicy.UpdateFromFIS())
mPolicyRefreshStatus.ShowDialog()
Then within the progress form you can call back to the routine that actually does the work.
Another approach is to define events on your ProgressForm and then the owning/launching object can handle those events to do the work in. With this option you can create a fairly detailed set of events to be able to handle incremental work or cancels, but the concept is the same, youu are calling back from the progress form into launcher to perform the actual business logic.
You cannot show the form modally and let your routine continue. You must show the form Non-modally and then do your other stuff, closing the form when you've finished. Maybe a loop until the task has finished?
Using Show() with a parent form parameter will give you better usability. More like a tool window.

Visual Basic 2010 Event Listeners on a List

I have a list of buttons in VB2010.
What is the best way to assign a function to their click event.
So every button has the same function, e.g.:
On Button Click
FireFunction(1)
End On Button Click
Without having to add a click event for every button.
The goal is to produce something similar to what is done with the Control Array idea in Visual Basic 2006.
Define a click function as in:
http://visualbasic.about.com/od/learnvbnet/a/eventhandler.htm
and react based on Sender. There may be a cleaner way to setup delegates in VB.NET, but I use it not.