How to call a Dialogue box from Menu using Matlab? - matlab

I want to Make a Help Dialogue Box. When we Press Help Menu then Dialogue box will appear.
Current code is
h_opt3 = uimenu('Label','&Help');
uimenu(h_opt3,'Label','How to Use','Callback','dialog','separator','on');
It only show empty dialog.
In place of dialog i want to put a dialogbox which will describe how to use my software.
How to code this all. Please help.
Requirements: How to Add stuff in DialogBox and how to call it in above mention scenario.

Try writing an additional callback function, and look at helpdlg instead of dialog.
I can't test any code now, but something like the following should work.
function help_callback
h = helpdlg('Directions','title');
end
Then change your uimenu call to this code
uimenu(h_opt3,'Label','How to Use','Callback',#help_callback,'separator','on');

Related

Programmatic Method of Handling Matlab Dialog Windows

I have a rather large Matlab program that is GUI based. I am looking into creating automated tests for it, as the current way of checking for bugs before a release is simply using all its functionality like a user would.
I would rather not use a GUI testing program that just records clicks and what not, so I was thinking of adding testing code that would call the button callbacks directly. The problem that I have run into with this is that we have a lot of warndlg and msgbox popups, and I would like my tester code to be able to see these.
Is there any way for Matlab code to tell if a function it called created a warndlg or msgbox? If so, is there any way to click 'ok' on these popups?
In a similar vein, is it possible to handle popups that block code execution (using uiwait or an inputdlg)?
If it matters I didn't use GUIDE, and all the GUI elements are created programmatically
Two ways. The first one is more elegant
Let the functions return an extra variable and return the status of the function. For example, 1: success, 2: success with warning, 3: error...
Create some global variables and make the function change them if a warndlg or msbgbox shows up. The main window would then check if the status of the global variable.
You can tell if a warning dialog was created by looking for it's tag using the findobj function. A warning dialog created using warndlg will have the tag "Msgbox_Warning Dialog". So code like this would tell you if the warning dialog exists:
set(0,'ShowHiddenHandles', 'on')
h = findobj('Tag', 'Msgbox_Warning Dialog');
warn_exists = ~isempty(h)
set(0,'ShowHiddenHandles', 'off')
to close the warning dialog, you can call delete, like this:
delete(h)
For the message box, I would store the handle when you create a message box, then look at the children to find the buttons, then look at their callbacks. You should be able to call the callbacks to simulate picking a button.

How do I display data/information with Matlab App Designer?

I would like to display some information to the user via Matlab App Designer's GUI. I am new to this program and can't seem to find a widget that provides what I feel should be a simple function. Am I missing something? Examples would include showing the user:
The path of the file that he/she selected
Errors such as "No files detected" that are printed in a Matlab script called on by the GUI code.
Other print statements in code such as "Done!", etc that will inform the user when a process is complete.
Is there a way to capture the output in the Matlab command line and report these in a window of some sort in the GUI? Thanks in advance!
You can use a TextArea to display information for the user. Here's how I made a simple example:
Drag a button to the app in design view.
Drag in a text area also. I changed the label to Feedback.
Select the button and use the Callbacks tab in the bottom right of app designer to add a callback with the default name it gives you.
Edit the callback to contain
answer = 'what your want to display';
app.FeedbackTextArea.Value = answer;
When you push the button the text area gets filled. In your code, instead of just setting 'answer' to some string, set a variable using whatever code is dealing with your user's information. The key is to store what you want the user to see in a variable and then assign that to the "Value" parameter of the text area or other widget where you want them to see the results.

MATLAB - callback excecution of edit box

As it is referenced in MATLAB documentation for edit box uicontrol or stated in this
post, when another component or menu bar or background GUI is clicked, the edit box callback gets executed. But in my attempts to use this functionality, I haven't been able so far to see the callback execution unless there is a change of edit box text or Enter key is pressed. What I'm trying to achieve is to execute edit box callback whenever there is focus loss from edit box even when nothing has been entered. Please enlighten me about what I'm missing here and how I can do this?
Thanks in advance.
The underlying Java object has a callback called FocusLostCallback that'll do what you want - execute when the object's focus is lost, even if you changed nothing.
You'll need findjobj from the MATLAB File Exchange. Then, get the Java handle and set the callback as usual (make sure the uicontrol is visible when you try to get the Java handle):
jh = findjobj(myEditBox); % myEditBox is a uicontrol handle
set(jh, 'FocusLostCallback', #myCallback);
A more complete list of the undocumented uicontrol callbacks can be found at Yair Altman's Undocumented MATLAB blog.
This method work perfectly with single-line textbox, but it has any effect with multi-line textbox (uicontrol, style edit, max = 2)

Access VBA: Form command button to do something/call function

I have created a basic form in access that has a couple of buttons and text fields.
I want the button to do something along the lines of when I click it, it should bring up a browse file dialog and when I select a file, change the text field to the path of the file.
My question is how can I program this? Specifically, do I create a module that goes like?
sub command1_onClick()
..bla bla...
end sub
Or are forms programmed differently? How can I tie a function to a button?
You can add actions to the button. In the properties window of the button is an Event-Tab. Click on On Click and select Event Procedure. You are then taken to the VBA Editor (ALT+F11) into following procedure:
Private Sub Command1_Click()
End Sub
In that procedure, you can use an API call to open the standard file dialog:
API: Call the standard Windows File Open/Save dialog box
The TestIt function in above link shows you hove to open the dialog and get the path. You can set your textbox to that path like this:
Me!Text1 = strPath
strPath has to be populated with the path you get from the file dialog.
You will want to look at the file dialog property.
Dim fDialog As Office.FileDialog
MSDN File Dialog
The above shows an example that is performed on a button click
The example adds the selected file to a listbox, for your situation you would want to use a simple textbox instead of the listbox.
You may want to set AllowMultiSelect to false to ignore the looping part if you only want one item. (this would simplify the code in the example for you.
.AllowMultiSelect = false
I may be a lil rusty but then you would want to do something like this(someone edit or correct me if I am way off)
Assuming you used varFile
(Dim varFile As Variant)
Me.TextBox1.Text = varFile
EDIT: After encountering error
It seems the error can come froma few things. Check to make sure the reference is there.
Also you may need to add the Microsoft DAO 3.6 Object Library reference.
See the "More information" section of this Link (Hopefully 2002 is close enough to 2003)
. It may have a few more helpful tips if that doesn't solve the problem.

Submit form from greybox window to main window

I'm using greybox and trying the following thing: I want to make a form inside the pop-up so when the users submit's it, the request goes to the main window and the pop-up closes.
I know the way to close the window is by using onclick="parent.parent.GB_hide()", but I really haven't been able to find a way to make the pop-up close and the data sent to the corresponding controller when the form is submitted.
I'm using Zend FW.
Thanks in advance,
I really appreciate what this community does.
Just use this code given below at the end of the loop
parent.parent.GB_hide();