Perl/Tk : Getting the selected value of option menu - perl

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.

Related

MS Access: Enter a specific text in a form using command button from another form

I would like to ask for your help on the following issue in MS Access.
I had created a form "CustomerListF", filled with command buttons for each client. For each button, I had created the following code:
Private Sub cmd_outlets_ABC_Click()
DoCmd.OpenForm "OrderFormF"
Forms!OrderFormF!Outlets = "ABC"
End Sub
The button would then open another form "OrderFormF" and enter "ABC" in the textbox named "Outlets". However, I realized the second line of code (Forms!OrderFormF!Outlets = "ABC") would always create a phantom record in my subform, which is located in "OrderFormF", and this record would travel to other clients' forms. This phantom record is usually created when the commandbutton is clicked twice (double clicks or subsequent clicks). It is a headache when the record starts to shift around.
enter image description here
I would like to seek your advice for vba code to edit the second line of code.
Thank you.
This approach for filling the field in opened form is not good. OrderFormF initialization and second line of your code with assigning value to the field may be executed in different sequence, they are not synchronized.
In order to avoid this, you should pass the argument to OrderFormF by another way. I would recommend to use OpenArgs parameter:
DoCmd.OpenForm "OrderFormF",,,,,,"ABC"
And then in Load event of OrderFormF assign the value to textbox:
Me.Outlets = Me.OpenArgs
In this case the "ABC" value will be assigned to first row in the form or to new record, if form is empty. Before assigning you can select the row if you need to assign value not to the first row. Also this way will protect you against double click on button, Load event executed only once during first form opening

install4j: Configurable form change visibility from drop-down list

I have a Configurable Form and i want to change the visibility of another field based on the value of a Drop-down list.
For example I have a Drop-Down list with entries A,B and the variable name for it is testDD.
I have a Text field smtpMailServer that I want to display only if testDD's value is A.
I have tried the following approaches in smtpMailServer's visibility without success:
return ((String) context.getVariable("testDD")).equals("A");
return (context.getVariable("testDD")).equals("A");
and I've also tried to add a script to testDD Change Selection Script with The following code
context.setVariable("ThisFormConfiguration", selectedItem);
And use the code above with ThisFormConfiguration instead of testDD. But it's not working.
Could you please help me?
Thanks!
I have tried the following approaches in smtpMailServer's visibility without success
The visibility script of a form component is only evaluated when the form is shown. You should keep it, but it only handles the initial condition.
and I've also tried to add a script to testDD Change Selection Script with
The following code context.setVariable("ThisFormConfiguration", selectedItem); A
Using the "Selection change script" property is the right idea, but your script has no effect. There is no live binding from the variables to the form components, the variable is read when the form is shown and updated when the user clicks "Next".
You have to use the following selection script:
formEnvironment.getFormComponentById("123").setVisible(selectedItem.equals("A"));
where "123" has to be replaced by the ID of the text field.

manually enter data to form

The user enters input to fill the form, but I want to manually complete one field. I've tried using document.getElementById(certificate_request_commonname__row).createAttribute("value","abc");
but it doesn't work. In the form i'm adding data to a table. certificate_request is the name of the table and commonname is the column name. After I've looked on the web2py book I saw that I have to write: tablename_columnname__row. I've done that but it doesn't work. it always says to me: Empty string passed to getElementById(). Can anyone help?
certificate_request_commonname__row is just a wrapper element that contains the input element. Instead, you must identify the input element itself. Also, don't use createAttribute -- just set the .value attribute:
document.getElementById('certificate_request_commonname').value = 'abc'

Remove quotes from string

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'.

Ligthswitch 2013 Set value ACB when launching from another screen

I have a search screen called TimesheetsByjob. This is based on a query called TSByJob and has one parameter called JobID. Normally the user will just open this screen and select a job. The ACB's JobID field is bound to the query parameter JobID.
I now want to add a button in the timesheet entry form to open this search screen from a button. Obviously, I know what the JobID is, so I want to (and the user will expect me to) preset the JobID instead of them having to select it from the ACB.
In the timesheet entry form my button as this is the Execute code:
int JobID = TimesheetProperty.Job.ID;
Application.Current.ShowSearchTSByJob();
I want to pass a param, but the method doesn't expect one.
Is there a way to overload the method to accept a param (if so where would I do that), or is there another way to do it other than making a 100% duplicate of the search screen and using a local property?
Regards
mark
In your SearchTSByJob screen, add a local property of the type you require. In that local property's Properties, check "Is Parameter".
Now you can pass a parameter to that screen. If you have multiple, Intellisense will tell you the order it expects.
int JobID = TimesheetProperty.Job.ID;
Application.Current.ShowSearchTSByJob(JobID);