Forum Discussion

dlsmith's avatar
dlsmith
Occasional Contributor
13 years ago

If statement for Checked or Unchecked

I am looking for assistance with programming. Below is a few lines from my script.

I have a checkbox (chkToll) that I would like to check the status of and when it is Checked, I want to uncheck it.  And when it is UnChecked, I want it left unChecked.  I am looking to put this between lines 17 and 19.



Thanks in advance.



1   w5 = p1["frmPRSelectSOInv"];

2   w6 = w5["panel1"]["xtraTabControl1"];

3   w7 = w6["xtraTabPage1"]["grpFilter"];

4   w7["ecbFinish"]["cbo"]["Keys"]("FinishA[Tab]");

5   w7["ecbGrade"]["cbo"]["Keys"]("GradeA[Tab]");

6   w7["ecbSpecificSO"]["cbo"]["Keys"]("CompanyASO[Tab]");

7   w8 = w7["groupControl3"]["chkInvType"];

8   w8["CheckItem"]("P/O Release", cbChecked);

9   w8["CheckItem"]("Upline", cbChecked);

10  w8["CheckItem"]("Finished Goods", cbChecked);

11  w6["ClickTab"]("Advanced Criteria");


  

12   w7 = w6["xtraTabPage2"]["groupControl4"];

13   w7["ecbCustomer"]["cbo"]["Keys"]("CompanyA[Tab]");

14   w7["ecbPart"]["cbo"]["Keys"]("CoAPart[Tab]");

15   w7["ecbLocation"]["cbo"]["Keys"]("2[Tab]");

16   w7["ecbType"]["cbo"]["Keys"]("TypeA[Tab]");

17   w7["ecbProduct"]["cbo"]["Keys"]("ProductA[Tab]");


18    w7["chkToll"]["wState"] = cbUnChecked;


19   w5 = p1["frmPRSelectSOInv"];

20   w5["BarDockControl"]["DockedBarControl"]["ClickItem"]("Run Query");

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    How about this:



    18    w7["chkToll"]["wState"] = !(w7["chkToll"]["wState"]);




    Basically, this will set the value of the wState to be the opposite of what it is currently.  I have not tested this out directly but theoretically this should work.
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Debbie,


    Try using the following code:



    w5 = p1["frmPRSelectSOInv"];

    w6 = w5["panel1"]["xtraTabControl1"];

    w7 = w6["xtraTabPage1"]["grpFilter"];

    w7["ecbFinish"]["cbo"]["Keys"]("FinishA[Tab]");

    w7["ecbGrade"]["cbo"]["Keys"]("GradeA[Tab]");

    w7["ecbSpecificSO"]["cbo"]["Keys"]("CompanyASO[Tab]");

    w8 = w7["groupControl3"]["chkInvType"];

    w8["CheckItem"]("P/O Release", cbChecked);

    w8["CheckItem"]("Upline", cbChecked);

    w8["CheckItem"]("Finished Goods", cbChecked);

    w6["ClickTab"]("Advanced Criteria");

    w7 = w6["xtraTabPage2"]["groupControl4"];

    w7["ecbCustomer"]["cbo"]["Keys"]("CompanyA[Tab]");

    w7["ecbPart"]["cbo"]["Keys"]("CoAPart[Tab]");

    w7["ecbLocation"]["cbo"]["Keys"]("2[Tab]");

    w7["ecbType"]["cbo"]["Keys"]("TypeA[Tab]");

    w7["ecbProduct"]["cbo"]["Keys"]("ProductA[Tab]");

    if (w7["chkToll"]["wState"] == cbChecked)

       w7["chkToll"]["wState"] = cbUnChecked;

    w5 = p1["frmPRSelectSOInv"];

    w5["BarDockControl"]["DockedBarControl"]["ClickItem"]("Run Query");


    Does it help?

  • dlsmith's avatar
    dlsmith
    Occasional Contributor
    I ended up with the following code:



    w5 = p1["frmPRSelectSOInv"];

    w6 = w5["panel1"]["xtraTabControl1"];

    w7 = w6["xtraTabPage1"]["grpFilter"];

    w7["ecbFinish"]["cbo"]["Keys"]("FinishA[Tab]");

    w7["ecbGrade"]["cbo"]["Keys"]("GradeA[Tab]");

    w7["ecbSpecificSO"]["cbo"]["Keys"]("CompanyASO[Tab]");

    w8 = w7["groupControl3"]["chkInvType"];

    w8["CheckItem"]("P/O Release", cbChecked);

    w8["CheckItem"]("Upline", cbChecked);

    w8["CheckItem"]("Finished Goods", cbChecked);

    w6["ClickTab"]("Advanced Criteria");

    w7 = w6["xtraTabPage2"]["groupControl4"];

    w7["ecbCustomer"]["cbo"]["Keys"]("CompanyA[Tab]");

    w7["ecbPart"]["cbo"]["Keys"]("CoAPart[Tab]");

    w7["ecbLocation"]["cbo"]["Keys"]("2[Tab]");

    w7["ecbType"]["cbo"]["Keys"]("TypeA[Tab]");

    w7["ecbProduct"]["cbo"]["Keys"]("ProductA[Tab]");


    if (w7["chkToll"]["wState"] == 1)


         w7["chkToll"]["wState"] = 0;


    w5 = p1["frmPRSelectSOInv"];

    w5["BarDockControl"]["DockedBarControl"]["ClickItem"]("Run Query");



    The code does remove the check mark if box is checked and ignores if the box is not checked. This is how it should perform.

    However, on line   w7["chkToll"]["wState"] = 0;

    ,

    I receive the following:

     An error occurred:

    Possible reasons:

    1. The application stopped responding.

    2. The application was compiled incorrectly (see the Open Applications topic in the help system).

    3. An error occurred in TestComplete.



    Technical information:

    303 0x80020009 (Exception occurred.)

    mscorlib 0

    System.Runtime.Remoting.RemotingException: Cannot create channel sink to connect to URL ''. An appropriate channel has probably not been registered.

       at System.Runtime.Remoting.RemotingServices.Unmarshal(Type classToProxy, String url, Object data)

       at System.Activator.GetObject(Type type, String url)

       at SharedApps.CommonForms.GlobalFunctions.GetIDataLayer()

       at SharedApps.CommonForms.EnhancedLookupEdit.RefreshData(Boolean fireEvents, DataTable dtb)

       at SharedApps.CommonForms.EnhancedLookupEdit.RefreshData(Boolean fireEvents)

       at SharedApps.CommonForms.EnhancedLookupEdit.RefreshData()

       at SharedApps.frmPRSelectSOInv.chkToll_CheckedChanged(Object sender, EventArgs e)

       at DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit.RaiseCheckedChanged(EventArgs e)

       at DevExpress.XtraEditors.CheckEdit.set_EditValue(Object value).



    Tested object:

    Aliases["Sys"]["SharedApps"]["frmPRSelectSOInv"]["panel1"]["xtraTabControl1"]["xtraTabPage2"]["groupControl4"]["chkToll"]

    (Sys["Process"]("SharedApps")["WinFormsObject"]("frmPRSelectSOInv")["WinFormsObject"]("panel1")["WinFormsObject"]("xtraTabControl1")["WinFormsObject"]("xtraTabPage2")["WinFormsObject"]("groupControl4")["WinFormsObject"]("chkToll"))

  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi



    I see you're using the DevXpress CheckEdit control in your app.  I too am testing an app with such controls and have to perform similar checks.  Unfortunately, I am using VBScript, so you'll forgive me for using that syntax....



    Basically, I've found that working with the wState property works sometimes, but on other occasions, for no apparent reason, if I wish to check the box, the setting is lost when I move on to perform other actions.  The way in which I got around this was not to use the wState property at all.



    What I do is to call the control's Click method and then use the Checked property, in VBScript it looks like this:



        Call chkCtrl.Click(chkCtrl.Width / 2, chkCtrl.height / 2, 0)    'This clicks the centre of the control - giving it focus.

        chkCtrl.Checked = True    'This checks the checkbox - use False to un-check it.



    If you build this into your IF statement, you might find that it works!!



    Good luck.



    Best Regards

    Stephen.

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Debbie,


    Please try replacing the w7["chkToll"]["wState"] = 0; line with another line, for example, with the following one: w7["chkToll"]["Click"]();


    If the problem remains, please contact the developers of the application you are testing. Most likely, the problem is caused by the application.

    If the problem disappears, please send a sample application to our Support Team, so we could investigate the problem and find a solution faster.


    Thanks.