Tuesday, August 16, 2011

The most undervalued StsMes() function

I found the ability to display small messages in the status bar to be very useful and employed it as a means of providing quick feedback to users.  Its something that requires a bit of training at first if they are not used to it but most people who have been surfing the web seemed to understand it.


Monday, August 15, 2011

Showing a count of items in the Console with SQL

At one point I needed to show a count of items in the console link provided.  To get there I used a format similar to the following and then mapped it accordingly:

"SELECT 'NAME', '(' + CONVERT(VARCHAR(4), COUNT(F.ITEMS)) + ') MY ITEMS' as Due,'',1 as Sort
   FROM TABLE
 UNION 
SELECT 'NAME', '(' + CONVERT(VARCHAR(4), COUNT(F.ITEMS)) + ') MY ITEM LIST TWO' as Due,'',2 as Sort
   FROM TABLE
Order by Sort"

'NAME' is the name of the console branch.
Obviously the convert to varchar is how I'm turning the numerical count into something textual to display.  The actual display with be (count) Name of branch item.  In this case, (#) My Items followed by (#) My Item List Two.

The Union adds the two queries together.  Order seems pretty self explanatory.  So it would look like this in the v9 console:

NAME
   (#) My Items
   (#) My Item List Two

Good for knowing something at a quick glance in the console, such as a number of records, pending tests, and so on.

Thursday, July 21, 2011

StopAction()

An old favorite in v9, this allowed for halting action expressions, including returning a value when stated criteria was met.

The help file uses it in relation to a Confirm function, which is nice.  I typically use it with those, and custom forms to act like a return keyword in most languages since it could return a value as well.

So you could call a StopAction(My Value) and halt a flow of logic and return a value.  Useful in a lot of situations. 

Everything is good with examples so let's look at one:


arrGotOne := SqlExecute("Select ORIGREC from HDHISTORY where MBNO = ?strMBNO?");

:IF len(arrGotOne) > 0;
    UsrMes("Can not Delete","This MB Number has been used.  We can not delete it from the list.  Retire it");
    stopaction();  
:ELSE;
    SqlExecute("Delete from HDDRIVES where ORIGREC = ?intORIGREC?");
:ENDIF;


Tuesday, July 19, 2011

Building a simple search form

Code for a very, and I do mean, very, simple search form.


:DECLARE oUserForm, sTXT, sSoftware,sOKButtonClick,sButton4, oCSFac;

X := LimsAPICall("GetSystemMetrics","LONG",,0);
Y := LimsAPICall("GetSystemMetrics","LONG",,1);

oUserForm := UserForm{(X-400)/2,(Y-190)/2, 400, 190, "Search Catalog"};
oUserForm:AddControl({"sTXT", 15, 90, 100,25, "TEXT","Number (including zeros):" });
oUserForm:AddControl({"sSoftware",110, 90, 100, 20, "SE","",""});
oUserForm:AddControl({"sOKButtonClick", 60, 20, 80, 25, "PB", "OK"});
oUserForm:AddControl({"sButton4", 180, 20, 80, 25, "PB", "Cancel"});
oUserForm:EnableMinBox(.F.);
oUserForm:EnableMaxBox(.F.);
oUserForm:Display(.T.);

The LimsAPICall to GetSystemMetrics is a nice way to get positioning information.

Otherwise the rest of the form is built on the fly (easy to adjust that way) and then displayed.

Tuesday, July 5, 2011

Export Coordinates workaround

I wrote the following as a kludge to get around individuals changing the coordinates of the starlims window.  Its neither pretty or the best example of coding but its functional.  Just put in in an action and call it where ever you need it.

It saves the previous form and browser locations to alternate fields (ALTFLD, ALTLINK: pre-existing fields reutilized).  It loads these values into memory, validates them against the exiting values and reapplies the original values.  The Process begins in the Preload event and ends in the ONclose event.  Pretty much required for all child windows as well as the container window or child windows lose their locations as well;

:DECLARE WindowID, nSize, check, ncheck, InitSize,chkName;

/*Allows changes made by admins but otherwise tosses input;
chkName := '<<USERNAME>>';

:IF (.NOT.chkName = 'sysadm');
/*Add more admins however necessary;

/*Originally used GetAPPID() but the function was not always consistent in returning the correct window when child windows are involved;
   WindowID:='SHELL';

    nsize := sqlexecute("Select FORMSIZE, wndorigin FROM WNDMAINT WHERE windowid = ?WindowID?", "DICTIONARY");
    InitSize := sqlexecute("Select ALTFLD, ALTLINK FROM WNDMAINT WHERE windowid = ?WindowID?", "DICTIONARY");

    :IF .NOT.comparray(InitSize, nSize);
        :DECLARE updateSize, UpdateOrig;
        UpdateSize := Initsize[1,1];
        UpdateOrig := InitSize[1,2];
            sqlexecute("Update WNDMAINT SET FORMSIZE = ?UpdateSize?, WNDORIGIN = ?UpdateOrig? Where WINDOWID=?WindowID?", "DICTIONARY");        
    :ENDIF;
:ENDIF;