can we use single excel object for 2 or more actions in UFT? - hp-uft

can we use single excel object for 2 or more actions in UFT?
example: I have created excel object in Action1 and can I use same object in another action like Action2.

Yes you can use a single object in multiple actions if you declare the object as Public (using a functional library).

Alternative is to import and export the sheet from inside the execution:
Datatable.Export "C:\temp\Script_data.xls"
Datatable.Import "C:\temp\Script_data.xls"
This could also be included in a function library as mentioned by Pankaj Jaju

Related

Get reference to cell containing function

Is there is way to access cell that contains my UDF?
I need to reset some cache when function with same parameters is run from different cell.
Didn't find anything suitable in exceldna utils.
Thanks,
Alex
You can call
ExcelReference caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference;
The result will be an ExcelReference if you're called from a sheet formula. It might be null if you're called via Application.Run or a few other ways.
ExcelReference is a wrapper for the C API sheet reference.

How to unimport a file from vbscript?

How do I unimport a file from vbscript? Because the file I imported has a lot of global variables, which coincides with the other file I want to import.
I just want to import 1 file at a time in order to prevent overlapping of global variables. How do I achieve that? Thanks.
All data made available to a current script context MUST be unique. If you use 'ExecuteGlobal statement' in the main context, routine or function then all data is available globally. Use 'Execute statement' to make data available in a current context.
http://msdn.microsoft.com/en-us/library/342311f1(VS.85).aspx

How to add components in to an existing GUI created by guide?

I just created a GUI using guide in MATLAB for a small project I'm working on. I have amongst other things two text fields for from and to dates. Now I'd like to get rid of them and use a Java date select tool. Of course this is not possible using guide so I need to add them manually.
I've managed to get them to show up by putting this code into my Opening_Fcn,
uicomponent(handles, 'style','com.jidesoft.combobox.DateChooserPanel','tag','til2');
using UICOMPONENT.
But even though it shows up I can't access the date select's attributes, for example
get(handles.til2)
returns
??? Reference to non-existent field 'til2'.
How can I fix this?
Unless you edit the saved GUI figure, the basic handles structure will not include your new component by default.
One way to access you component is to store the handle via guidata, by adding the following to your opening function:
handles.til2 = uicomponent(handles, 'style','com.jidesoft.combobox.DateChooserPanel','tag','til2');
guidata(hObject,handles)
Functions that need to access the handle need the line
handles = guidata(hObject)
to return the full handles structure that includes the filed til2

EnvDTE CodeClass.AddDelegate overload

I want to create 2 delegates with the same name but different parameters (overloaded delegate). When I try to add a delegate I get an error on the second try due to a delegate already existing. I tried to add it first with a temp name then add the parameters and then change the name so the signuature would be different but I still get an error stating that an item already exists with that name.
How can I add an overloaded delegate?
The capabilities of the code model to generate code are limited. You can try the to use EditPoint.Insert(...) to insert the code instead of using AddDelegate() method.

How to create dynamic Callbacks in MATLAB?

I have this line of code:
delete_btn = uicontrol(rr_ops, 'Style', 'pushbutton', 'String', 'Delete Graphic', 'Position', [13 135 98 20], ...
'Callback', 'delete_graphic');
and a little bit upper this function:
function delete_graphic
global rr_list
selected = get(rr_list, 'Value');
selected
return;
why this code is not working? I really dont understand...
What do I need? I create one button and a listbox, clicking on button - deleting selected element from a listbox.
Thx for help.
PS
Always getting this error:
??? Undefined function or variable 'delete_graphic'.
??? Error while evaluating uicontrol Callback
here is all my code: http://paste.ubuntu.com/540094/ (line 185)
The generally-preferred way to define a callback function is to use a function handle instead of a string. When you use a string, the code in the string is evaluated in the base workspace. This means that all the variables and functions used in the string have to exist in the base workspace when the callback is evaluated. This makes for a poor GUI design, since you don't really want the operation of your GUI dependent on the base workspace (which the user can modify easily, thus potentially breaking your GUI).
This also explains the error you are getting. The function delete_graphic is defined as a subfunction in your file rr_intervals.m. Subfunctions can only be called by other functions defined in the same m-file, so delete_graphic is not visible in the base workspace (where your string callback is evaluated). Using a function handle callback is a better alternative. Here's how you would do it:
Change the callback of your button (line 216) from 'delete_graphic' to #delete_graphic.
Change the function definition of delete_graphic (line 185) to:
function delete_graphic(hObject,eventdata)
where hObject is the handle of the object issuing the callback and eventdata is optional data provided when the callback is issued.
EDIT:
If you want to pass other arguments to delete_graphic, you can perform the following steps:
Add the additional input arguments to the end of the function definition. For example:
function delete_graphic(hObject,eventdata,argA,argB)
Use a cell array when you set the callback for your button, where the first cell contains the function handle and the subsequent cells each contain an input argument. For example:
set(delete_btn,'Callback',{#delete_graphic,A,B});
There is one caveat to this, which is that the values A and B stored in the cell array are fixed at what they are when you set the callback. If you change A or B in your code it will not change the values stored in the cell-array callback.
If you aren't able to use the above solution (i.e. if A and B need to change value), there are a few other options for how you can share data among a GUI's callbacks:
You can rework the organization of your code to make use of nested functions. This makes it very easy to share data between callbacks. Some nice examples of using nested functions to create GUIs can be found in the MathWorks File Exchange submission GUI Examples using Nested Functions by Steven Lord.
You can store data in the UserData property of a uicontrol object. To access or update it, you just need the object handle.
You can use the functions SETAPPDATA/GETAPPDATA to attach data to a handle graphics object (i.e. uicontrol).
Since it appears your code was created using GUIDE, you can make use of the handles structure GUIDE creates to store data using the GUIDATA function.

Resources