-
Hallo
I have a small problem with the MsgBox function of VB. My program receives input from an electronic eye. If the user enters invalid values in the textbox, a msgbox with error message pops-up. As soon as this happens, the program stops because the message box is by default modal.
Is there anyway to remove the modal mode so that the rest of the program can keep on running? I need help desperately?
Thanx
-
-
Hi,
The only way you can get round this is to create your own MsgBox using a form. You can then use this to show up and let your program to continue processing code by using MsgBoxForm.Show vbModeless (or whatever you call the form!).
Hope this helps
Shaun
-
Guys, from MSDN:
-BEGIN-
Modeless dialog boxes let you shift the focus between the dialog box and another form without having to close the dialog box. You can continue to work elsewhere in the current application while the dialog box is displayed. Modeless dialog boxes are rare; you will usually display a dialog because a response is needed before the application can continue. From the Edit menu, the Find dialog box in Visual Basic is an example of a modeless dialog box. Use modeless dialog boxes to display frequently used commands or information.
-END-
I'm pretty sure that its impossible to make the standard MsgBox non-modal. If you want to do that you'll have to make a dialog box from scratch. I have to code to make them (MsgBox's) disappear automatically though. so if you want it, mail me & i'll send you the project.
-
Why don't you make your own msgbox. Just take an empty form and put a label on it. Then call the form true a function witch sets the tekst of the label and the title and thats it.
You can also use an API call to get a msgbox. I don't know what is possible with this call but you can find it at http://www.vbapi.com.
Good luck.
-
I was hoping to get around the idea of doing it from scratch. The problem is that we have a central function that calls the msgbox for different events. There are hundreds of possibilities why the msgbox was activated.
Thanx all
-
Use the MessageBox API
Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
it doesn't block and is the same as Msgbox
Why don't one of u guys go take a look at my post :
Strange Table lock behavior
Thanks
-
Message-Box Modality CWnd::MessageBox
MB_APPLMODAL The user must respond to the message box before continuing work in the current window. However, the user can move to the windows of other applications and work in those windows. The default is MB_APPLMODAL if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.
MB_SYSTEMMODAL All applications are suspended until the user responds to the message box. System-modal message boxes are used to notify the user of serious, potentially damaging errors that require immediate attention and should be used sparingly.
MB_TASKMODAL Similar to MB_APPLMODAL, but not useful within a Microsoft Foundation class application. This flag is reserved for a calling application or library that does not have a window handle available.
Applies to the MessageBox API and MessageBoxEx API functions
-
Sorry but what I meant is that Events are still triggered...
for sure the code stops tracing. If your input code is in a timer or a Mscomm or winsock Event, you should continu receiving and decoding your inputs...
-
Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
I would like to know if you can use this meesagebox when the respond is for example vbYesNo. For some reason it only shows OK even if you specified something else. Am I using it incorrectly?
-
herman,
If you use the API messagebox you will need to use these constants for it instead of the standard VB ones i.e. VbYesNo.
Public Const MB_ABORTRETRYIGNORE = &H2&
Public Const MB_DEFBUTTON1 = &H0&
Public Const MB_DEFBUTTON2 = &H100&
Public Const MB_DEFBUTTON3 = &H200&
Public Const MB_DEFMASK = &HF00&
Public Const MB_ICONASTERISK = &H40&
Public Const MB_ICONEXCLAMATION = &H30&
Public Const MB_ICONHAND = &H10&
Public Const MB_ICONINFORMATION = MB_ICONASTERISK
Public Const MB_ICONMASK = &HF0&
Public Const MB_ICONQUESTION = &H20&
Public Const MB_ICONSTOP = MB_ICONHAND
Public Const MB_OK = &H0&
Public Const MB_OKCANCEL = &H1&
Public Const MB_RETRYCANCEL = &H5&
Public Const MB_SETFOREGROUND = &H10000
Public Const MB_SYSTEMMODAL = &H1000&
Public Const MB_TASKMODAL = &H2000&
Public Const MB_YESNO = &H4&
Public Const MB_YESNOCANCEL = &H3&
hope this helps
-
http://www.netfokus.dk/vbadmincode/code/msgbox.zip
This project is a replacement for the standard VB messagebox function. It allows the programmer to assign, re-assign the owner/parent of the messagebox, thus allowing code processing to continue even though message boxes are on screen. It also accepts parameters to position the messagebox anywhere on the screen. Excellent solution for event driven code, allowing
events to be raised when message boxes have the focus.
Author: John Timney