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;