How To Correctly Display A Dialog Box During Long Processing - VB.NET - vb.net

Running into a situation when user searches for orders of customer for past 4 years. As the DB query takes a long time, I want to show a pop up box just stating 'please wait. quering for results'. so when they start their search I want to show the message box until the results are obtainned and at that point I want to close the message box.
My current way, I know is incorrect as the pop up box locks up and states (not responding).
Would using a background worker be an over kill, or should I go with a progress bar?
My current way:
Dim frmProcessing As New ShowWaitForm
'/ set location to open the form
'/ set any custom message
frmProcessing.Show()
'//do db query and other stuff with result-> i CANNOT CHANGE THIS CALL NOR CAN I MODIFY HOW IT IS CALLED/FUNCTIONS
frmProcessing.Close()
frmProcessing = Nothing

I personally find the background worker to be a better choice most of the time. It allows me some more flexibility later if I want to add more information. I can use the ProgressChanged event to update a progress bar, and later if my needs change I can do other things as well.

Related

Allowing User to Select off of Partial Records in a Continuous Form in Access

I am creating a form in access to allow users to input multiple production records for a day.
The form is set as a continuous data entry form and has data validation in place to ensure the information being entered is consistent.
I am having a problem where if a user starts typing something on a new entry, they essentially have no way to back out of it or cancel the entry without completely filling out the form.
I want to keep the data validation to ensure the data being recorded is accurate, but also do not want to lock users into an entry unless it is completely filled out.
I think the ideal would be to allow users to create a new record or select other records without needing to save the current record.
If it would be possible to make it so records only save when a button at the top of the form is pressed I think that would be ideal, but I have not found a good way to do this without requiring it on every single entry.
I have attached a picture of what I am talking about, there could be various error messages but essentially if you try to click off when a record is incomplete it will give an error until the entire form is filled out.
Example of Error Message and Image of Continuous Form
'deselect' without saving but still save what had been entered up to
that point.
That you can simulate by setting the DefaultValue of each control in the AfterUpdate event of each control:
Me!SomeTextBox.DefaultValue = Nz(Me!SomeTextBox.Value)
However, I'm not sure that will be a good idea. And you may have to reset the default values when opening the form.

Stuck in infinite loop. Any way to break vba into Code when Control+Break doesn't work

I have code stuck.
It might be in an infinite loop.
Not sure.
Is there a way to break the program to stop at the current line of code that it is running on?
I'd like to avoid shutting down excel because I want to be able to catch where in the loop it is, and by going into the code, I will be able to tell how much processing was done. I would like to break into the code, if possible.
It is stuck on hour glass.
Ctrl+Break doesn't seem to work
Seems like the running code has hijacked all the quota that cpu is giving to excel.
If there is nothing I can do now, is there something in the future I can do to where I can more easily break into the code?
I'm thinking that an intermittent wait within a loop might be a feasible solution.
In the future, include a DoEvents inside the loop. It will run a little slower, but you will be able to use Ctrl+Break to stop it from running.
Create a progress dialog when entering the loop and include a Cancel button. Within your loop check for the Cancel signal/event. This also gives you some flexibility on how you react to the Cancel - you could stop the loop and display key information in a new dialog box (for example).
Basic steps to achieve what I have described (not necessarily the most elegant or the most re-useable, but simple enough for those of lesser experience):
create a modeless (not modal) Form with either suitable labels or a progressbar item (for
visual effect). Include a public property (Boolean) for Cancel (e.g.
boolCancel)
Place a button on form and onClick set boolCancel = True
In your main code, show the form just before your problem loop.
while in your loop you can update some label or progress bar on the
form so that you have a visual indication of whether the loop is
doing something of value or if it is now simply spinning its wheels.
How you do this depends on what your loop is doing.
Also while in your loop check your boolCancel value. If true then
display any state information you want and break from the loop.
If your loop ends normally, hide/unload the progress dialog.

How to manage event for made a load bars in Access

I created an application with Access (2013) with VBA. This application crawls a website and inserts some records into database. But it takes too much time.
My solution is to make load bars for waiting. But currently I use the event Form_Current(); and when I set the load bar's value (it's my function) setBarLoadValue (25) Nothing is displayed on the screen. Why ? Because my function run yet.
My question is: How I can manage the event to simulate a load bar in real time ? (Don't want to wait till the end of function to see 100%).
The following link has a beautifully designed Progress status bar. http://www.access-programmers.co.uk/forums/showthread.php?t=265537
The author of the code has provided a Class where you have a Form that acts as a Meter and you basically set the values. It could be real time enough, have a look. I use it in my application and works great.
Finally I found an solution !
Solution
Step1
You must enter this code in your code
DoCmd.SelectObject acForm, Me.Name
Me.Repaint
DoEvents
With this code, you display immediately the form
Step 2
Now, when you want to display something, you must just do that: DoEvents.
When you use DoEvents the form refresh and you can display the new state of the progress bar.
Note: This solution work with Access 2013. Maybe it's not supported with other version.

Best way to save status of dynamic web interface

Basically in my website I have a sidebar with a stack of boxes; each box can be collapsed or expanded by the user. I need to save the status of each box for the currently logged in user.
I don't want to use cookies because if an user changes browser or computer, all the boxes will go to the default status.
Should I save this information on the database making a query every time the user collapses/expands a box? How would you handle this? Thanks.
Edit: What if an user clicks on the toggle button repeatedly, like ten times in two seconds, just because he enjoys the boxes' animation? He will make ten queries in two seconds. So maybe the question should be: when should I save this data?
Call a (client-side) "changed" function every time a box changes.
Keep two items of (client-side) state: the time the last update to the server was sent and whether a timer has been set.
Write a (client-side) "update" function that sends the update and updates the state to mark that the last update was just now.
When the changed function is called: if a timer is set, then return immediately; if an update has never been sent or the last update was sent more than ten seconds ago, then call the update function and return. Otherwise set a timer to send the update after ten seconds.
The timer callback should simply clear the timer flag and call the update function.
Also on an unload event check if a timer was set and if it was then clear the timer and call the timer callback function.
So the result is that you send the update immediately except when the user is flapping, in which case you only send an update every ten seconds at most.
There might be some cases where you lose an update, but this is likely to only happen if the user was playing with the toggling and then closed the page before the timer fired, in which case he probably won't notice anyway.
If you need to persist these options from multiple computers you will need some form of server side storage.
This could be database or flat file. The choice depends on what you have available, skill set, and the need to scale. If you are going to have just a few users, a flat file may be your best choice.

Informing the user that a DataGridView is being populated

I am writing a program in VB.Net to manage text messages sent through an API. It allows you to view messages in a datagridview and filter by date, sent/unsent etc...
To load the messages I'm executing an SQL statement and retrieving a DataTable which then gets set as the DataSource for my DataGridView control.
The problem is that depending on the filters selected the user could be selecting a lot of records and it would take some time for the DataSource to update. I want to inform the user of this load time by providing a progress bar or label of some kind.
I have used progress bars before when looping through data but this is loading it all at once. I thought of displaying a label when the user clicks to load the data and then hiding it when the data is loaded. But this happens instantaneously even when the data is still loading.
Is there an event on the DataGridView I can use perhaps? Something like .DataSourceLoadStart and .DataSourceLoadFinished.
I know I'm just making those events up... but hopefully it makes it clearer as to what I want.
You could set the label to be visible when load is clicked and try the: DataGridView.DataBindingComplete Event to hide it, this event gets called when the binding is complete.
MSDN Link - DataBindingComplete
A little off topic but... I wonder if you could attach a AJAX update panel with activity/loading image to a gridview? I don't think I've ever seen it done but here's a great application for it.