How to extend dialogue dynamically to add error msg in vb.net windows form application - vb.net

I have aLogin dialogue like the image below and I am showing the error messages on top of the dialogue.
As you can see I am leaving a rather big empty area on top of the dialogue for these messages(it can be up to 5 lines of text) which does not look good. I would like to remove the empty space on top and add the space in run time when there is an error line added.
I know that it is possible to move each element of the Dialogue down when a new error line is added(e.g. button1.Left += 200, for each element in dialogue), but is there an easier and more practical way to do it?

Related

Lock OfficeRibonLabel size

I have an Excel VSTO plug-in which displays error messages in a RibbonLabel.
Changing the label text causes it to resize which causes its containing RibbonGroup to resize which moves the last group separator right and left with each message. This looks very annoying.
Is there a way to freeze Ribbon control size or, alternatively, any other way to display immediately visible error message which will not block the document itself (i.e. NOT message box)?
You could write the label to the status bar.
excelApp.StatusBar = String.Format("Processing line {0} on {1}.",rows,rowNum);

How do I highlight the content of a TextBox/RefEdit control and set focus simultaneously?

I'd like to highlight the content of a TextBox/RefEdit control and set focus simultaneously when there is any invalid entry and after prompting a message box warning the error so that user knows where to fix the error. You can try Data>Analysis>DataAnalysis>Sampling and enter some invalid range/data, then you will be redirected to the invalid entry. The invalid entry is highlighted as well as with focus set (you can see a flickering cursor).
I tried to emulate this and I used,
aControl.SetFocus
aControlt.SelStart = 0
aControl.SelLength = Len(aControl.Text)
While the content inside the control is highlighted in blue, there's no flickering cursor as if I did not set focus of the control. How can I fix this? Or what's the best way to guide the user to the place where the invalid entry exists?
What if user inputs more than one invalid entries. How do you plan them all selected and setfocused at the same time.
There is no need to complicate things for you and for user. What you can do is create invisible labels with the right message you want to deliver to user, preferably in red color, and place them below each TextBox/RefEdit. Make them visible with Label1.Visible = Truewithin your conditional check.

Ms Access and SQL: how to identify where error occurs

I have a form in MS Access where a lot of queries are running to calculate all kinds of numbers using user input and using other queries ouput. All of a sudden I get the error below:
Error text is:
The record source ' ' specified on this form or report does not exist.
The name of the recordsource may misspelled, the recordsource was deleted or renamed, or the recordsource exists in a different database.
In the Form or Report's design view or layout view, display the property sheet by clicking the properties button, and then set the recordsource property to an existing table or query.
I don't remember exactly what I added/removed to have caused this and I can't find where the error occurs. How can I, I guess, debug my Access Form while it's running queries?
I don't see your image as it is blocked at work.
The only one way to debug the application when errors occurs is to break the execution using the keyboard combination :
CTRL + Pause/Break
Do it when the error message appears
This obviously doesnt work if the application is compiled in a mde/accde
When the CTRL-Break doesnt work, you have to add a break point in your code.
Bring the VBA window using
ALT + F11
Open the code of your form, go in the procedure that triggers the queries, select a line of code at the beginning and add a breakpoint using F9
Then run the form, it will stop the execution on the breakpoint and show you the VBA window, continue to execute the code step-by-step using F8 until the error occurs
When ever you change the name of a table in ms access for that has drop down list, go to the design view --> property Sheet--> Row Source and change the names to the corresponding names for the drop down selection for combo selection

Showing MsgBox() with nowait (no user input) is not the real issue

I had searched a lot how to display a Msgbox that will not wait the user input (pressing ok or cancel).
I found 3 solutiuons to this.
1- Display the MsgBox() in another thread or using BackgroundWorker()
2- Create a form that display the message, then closed the form by a timer and use it instead of Msgbox()
3- Using the API MessageBoxA()
Let say I have a loop from 1 to 100, and I want display a message for the i(counter)
When I test above 3 ways, I found that this is not the right way of doing it, I don't need a msgbox() to close by it self after showing the message, because that will display 100 dialog.
What I realy want is to display ONLY 1 MsgBox() and change the text accordingly.
I managed to do this using a a Form() as class and I did it using Application.DoEvents
I know it can be done using BackgroundWorker or Threading since alot of people advice against using Application.Doevents
Here is my code
Dim oWW As New WaitWindow With {.TopLevel = True,.TopMost = True,.StartPosition = FormStartPosition.CenterScreen}
oWW.Show(Me)
For i = 1 to 100
Threading.Thread.Sleep(500) ' Just to slowdown execution
oWW.SetMessage("Counter = " + i.ToString)
Next
oWW.Dispose()
Public Class WaitWindow
Sub SetMessage(ByVal Message As string)
lbl_message.Text = Message
Application.DoEvents
End Sub
End Class
WaitWindow is not more than a Form base class with a label (lbl_message)
That code works fine (display WaitWindowForm on center of currently displayed form only once, then I change the text)
I have 3 questions :
1- How to display the WaitWindowForm in the top right corner of my working form?
2- Is it possible to display the normal MsgBox() or MessageBox.Show() only once, then capture the text displayed and change it?
3- Which one is suitable for my issue (BackGroundWorker or Threading) and what the code in WaitWindow class I post will be if I decided to use Backgroundworker or Threading instead of Application.DoEvents (Changing the label text not showing new form with new text) ?
3 questions in one post.. humm.. who cares, I am not the one who will answer lol :)
Thanks in advance.
I think the issue that you're really encountering is that you're trying to use a message box for something it's not suited for. If you want to have text that constantly changes just add a text box in the upper right corner of your application and adjust it every time a new message needs to be shown.
You can also look up dialogu windows (search ".showdialog() vb.net" in google) might help as well.

How to change the Contents of a msg box

I have a form for creating a record, I also have a button on the top of the form for to return to a form called home. When the form is being viewed and half the information is put in and the home button is clicked an error pops up saying " you cannot add or change a record beacasue a related record is required in a table "Elements"." How do I Change what the content of the error message is ?
You can put checks in your button_click sub to circumvent -- check to make sure all fields are filled in, and if not, display your own message box followed by
Exit Sub
That will short circuit the rest of the method so you should not get the standard message.
Here is a resource on error-handling in VBA: http://allenbrowne.com/ser-23a.html
I'm not sure, however, if you can create a handler in VBA for standard program error messages.