Remove quotes from string - matlab

I have a MATLAB GUI that shows all variable names in the base workspace in a popupmenu. The user can then choose a variable. This variable is then passed into a function. My problem is that I cannot find a way to grab the variable's value from the popupmenu. I am getting a cell, which I convert into a string.
data = get(handles.popupmenu1,'String');
data = data{1};
The problem is that if the variable is named n, then this will return 'n', with quotes, when I need it to return it without quotes. So, when I try to get the value, it does not work.
data = evalin('base','data');
How do I remove the quotes from the string?

It's probably not the most efficient way, especially if you have a lot of variables in the popup menu, but could you store your variables in the handles structure of the GUI, and when the user selects a variable name from the popup menu it triggers a switch/case scenario in which you use strcmp, for example, to evaluate what the variable is and thus get its value form the handles structure?
Or maybe create some kind of lookup table in the UserData property of the popup menu, so that each 'String' displayed in the popup menu can be related to the corresponding variable, after which you get its value and can then pass to other callbacks?
I can't test it with a simple script right now and that's only ideas; I'll check tomorrow unless someone comes up with an idea in the meantime!

Ok, you can try this:
data = get(handles.popupmenu1,'Value');
Use 'Value' instead of 'String'.

Related

Change 'Var' function of assignin based on user input

I'm trying to write a GUI in MatLab that enables me to take the data it is outputting and move it to the work-space.
I'm currently achieving this with the assigning function but what I would like to happen is have the name of the variable change depending on what the user inputs in a edit box
Here is my current script:
function Save_Callback(hObject, eventdata, handles, vavargin)
a=str2num(get(handles.VariableA,'String'));
b=str2num(get(handles.VariableB,'String'));
c=str2num(get(handles.VariableC,'String'));
d=str2num(get(handles.VariableD,'String'));
regionname=(get(handles.RegionName,'String'));
assignin('base','regionname' ,[a;b;c;d]);
Every time the save button is pressed it just calls it region name instead of grabbing the user inputted text.
Does anybody have any ideas? Since I'm fairly new to MatLab, please try to make the explanation as simple as possible.
Leave off the quotes around regionname when you run the assignin command, as follows. Then it will use the value inside the variable regionname as the new variable name.
assignin('base', regionname ,[a;b;c;d]);

Dynamically add fields to input dialog

Is it possible to somehow add input fields to an input dialog (inputdlg()) in MATLAB when a specific event occurs, e.g. the user types in a certain value in one of the existing fields...?
Or is there any other 'hacky' way to achieve this so that the user doesn't have to click "OK" and I have to code to reopen another input dialog which contains more input fields..
Thanks!
inputdlg is not a built in function, so you might as well copy it, call it by another name and change its functionality.

Get form field value via module [VBA]

I have a program built with VBA, in access.
I have a form with the field chDate and I need to get the value of the field in a module file named Global (not class module).
I tried to access it but I think I get empty value, string. not error.
I'm no expert with VBA, its new to me (I have experience with VBS).
Can someone please help me and tell me how can I access the value of a form field via module file?
Thanks!
If you can provide some sample code, it might help us in trying to get you a solution.
Here's what might work:
Dim an object as an instance of your form, and set the instance to a new instance. These two lines will do that (assuming the form is called frmForm)
Dim theForm as frmForm
Set theForm = new frmForm
then Show that Form:
theForm.show
The form will get the focus, so you can populate the fields. At that point, once the form is hidden, your code should be able to pull the field as such:
var1 = theForm.txtFormField.Text
However, if you unload the form in code, all variables directly tied to the form will be lost. In that case, you might want to follow Oneide's example, and set a global variable to the value of the form field. You can do this in one of the form's event handlers.
Let me see if I can recall my Access days. In your global module you should access the form field be prefixing the form name i.e.
var1 = Form1.txtFirmField.Text
As far as I know, you're trying to get the data the wrong way.
Anytime you would try to get your form data, from a standard module, your form probably will already be closed or, if you're not opening it as a restricted window, the value will not be ready yet.
Anyway, if you could get pass through all the difficulties above, you're probably coding in a not standard / right way.
Remember that VBA is an event driven language, and you would be better using it's strenghts rather than fighting against them.
As a final word, if this is just a casual coding, I suggest you using a global variable and make de Code Behind Form have set it up on control's change event.
If you're not sure what I mean, please leave a comment and I'll try to explain it better.
And, if you don't mind, let us know more about your starting code to get better answers.

Perl/Tk : Getting the selected value of option menu

I am developing one interface in Perl/Tk.
In that I am using one optionmenu to list the names of the users.
And while selecting the user from optionmenu it should display corresponding date of birth of the employee.
And I should be able to update the date of birth of the selected user.
I have written the following code.
$dob_label = $form_name -> Label(-text=>"BirthDay")->place(-x=>150,-y=>200);
$dob=$form_name->DateEntry(-width=>11,-parsecmd=>\&parse,-formatcmd=>\&format)->place(-x=>250,-y=>200);
$ename = $form_name->Optionmenu(-variable=>\$select_value,-options => [#names],
-command=>sub {&get_id_date($hash_ref,$eid,$dob,$_[-1])})->place(-x=>250, -y=>100);
$post_button=$form_name->Button(-text=>"Add",-command=>[\&Add_Birthday,$select_value,$dob,"edit"])->place(-x=>250,-y=>275);
The function get_id_date is used to get the id and dob of employee using the name of the employee.
It is returning the correct id and dob.
Then I edited the dob of the employee.
And I am calling Add_Birthday function to save the changes into database.
But what is the problem in this is,the variable $select_value is always having the value of first name in the optionmenu.
Actually it should have the value of the last selected item in the optionmenu.
So what is the problem in this code,
Please give the solution for this also.
Thanks in advance.
When you create the Button, you are passing the current value of $select_value to the button/command set up. By the time you press the button, the old value of $select_value has already been evaluated and set in the command argument list. You need to make your command a closure, so that $select_value is not evaluated until the button is pressed, e.g.:
-command => sub { Add_Birthday($select_value, "dob", $edit) }
For completeness, I should also mention that another way of doing this is to pass in references:
-command => [\&Add_Birthday, \$select_value, "dob", \$edit]
But that requires rewriting the function to accommodate the references in the argument list.

Axapta: Edit form field values

Using a 'clicked' override on a button, I'd like to modify values in an Axapta form.
I'm able to get data from the form field using:
str strOld = Form_FieldName.valueStr();
I'm able to prepend text to the field using:
Form_FieldName.pasteText(strNew);
I can't seem to find a .clear method or .value= method. I'd like to replace the entire value in the field with new information.
Thanks
If the field is bound to a datasource, you have to modify the value in the datasource. If the field is bound to a variable, then modify the value of the variable itself. It is the easy an smart way to do it.
You can modify the value in the form control by using the .text() method. (The control have to be the AutoDeclaration property set to Yes). This is a setter-getter (parameter) type method used in AX. If no parameter is passed, it is user as getter (read). If you pass a value, this is a setter (write).
Hope this helps.