cancel
Showing results for 
Search instead for 
Did you mean: 

UserForms - Checkbox always returning true.

SOLVED
Occasional Contributor

UserForms - Checkbox always returning true.

Hey there, I'll preface this by saying I'm a total newb when it comes to coding and basically am learning as I go along.

I've been trying to set up two forms, one basic form where one can only enter base parameters, and one advanced form for more detailed parameters, and said advanced form is supposed to be accessible via a checkbox - if you check the box, the advanced form opens, and if you uncheck it, an additional flag will trigger for the script to disregard the data in the advanced form.

function DataForm_tpAdvanced_OnChange(Sender)
{
  if(UserForms.DataForm.tpAdvanced.Checked)
    UserForms.AdvancedForm.Show();
}

Either way, here's the problem: No matter if the box is checked or unchecked, the Advanced Form will always show. I've changed the script to display in the log whether the box returns true or false, and it returned true and false respectively as expected. However, the if-statement simply ignores it and always returns checked, regardless of the actual state of the box.

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Occasional Contributor

Re: UserForms - Checkbox always returning true.

Everyone who gave me your helpful responses, I solved it by realizing I was very stupid and looking at JScript and not JavaScript - I adjusted the code to be

function DataForm_tpAdvanced_OnChange(Sender)
{
  if(UserForms.DataForm.tpAdvanced.Checked == True)
    UserForms.AdvancedForm.Show();
}

and it works like a charm now! Thanks for all the advice and sorry for possibly wasting anyone's time!

View solution in original post

8 REPLIES 8
Community Leader

Re: UserForms - Checkbox always returning true.

Hi,

 

Did you try to use the solutions from these docs?

 

https://support.smartbear.com/testcomplete/docs/app-objects/specific-tasks/standard/check-box/determ...

 

and see if the object you're using is on the "on_change" list.

 

"

Applies To

The event applies to the following components:

TcxButtonEdit, TcxCalcEdit, TcxCheckBox, TcxComboBox, TcxCurrencyEdit, TcxDateEdit, TcxMemo, TcxMRUEdit, TcxRadioGroup, TcxSpinEdit, TcxTextEdit, TcxTimeEdit

 

"

 

https://support.smartbear.com/testcomplete/docs/reference/user-forms/events/onchange.html

Occasional Contributor

Re: UserForms - Checkbox always returning true.

Thanks for your quick response! From what I understood, the "Determining a Check Box's State" article only applied to checkboxes on the site I am testing, and not to user forms.

 

The object in question is a TcxCheckBox, and I basically just copied the function from the sample User Forms.

Community Hero

Re: UserForms - Checkbox always returning true.

I think @Wamboo is right that you're going to want to use the "OnChange" event for the checkbox and, in that event, check the state of the checkbox to determine activity.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Occasional Contributor

Re: UserForms - Checkbox always returning true.

But - and correct me if I'm wrong, I'm really really new to this whole stuff - isn't that what I already showed in my code snipped in the original post?

Highlighted
Community Hero

Re: UserForms - Checkbox always returning true.

Yes, the code is there for an OnChange event, but I think it's an event on the form, not on the checkbox itself.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Occasional Contributor

Re: UserForms - Checkbox always returning true.

I just tested a few other alternatives, and I came to the conclusion that the "Checked"-call returns the correct case, but if used in an if-statement always defaults to true.

 

I wrote the following little script:

function AdvancedForm_apTestButton_OnClick(Sender)
{
    if (UserForms.AdvancedForm.apAdvancedResults.Checked)
      ShowMessage("1")
    else
      ShowMessage("2");
    Log.Message("Checked = " + aqConvert.VarToStr(UserForms.AdvancedForm.apAdvancedResults.Checked));  
}

No matter whether the checkbox is checked or unchecked, it always shows "1", however, the state of the checkbox is successfully and correctly logged.

Community Hero

Re: UserForms - Checkbox always returning true.

Hi,

 

Is this check-box two- or three-states one? (I.e. can it be 'greyed'?)

What if you try

if (aqConvert.VarToBool(UserForms.AdvancedForm.apAdvancedResults.Checked))?

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Occasional Contributor

Re: UserForms - Checkbox always returning true.

Everyone who gave me your helpful responses, I solved it by realizing I was very stupid and looking at JScript and not JavaScript - I adjusted the code to be

function DataForm_tpAdvanced_OnChange(Sender)
{
  if(UserForms.DataForm.tpAdvanced.Checked == True)
    UserForms.AdvancedForm.Show();
}

and it works like a charm now! Thanks for all the advice and sorry for possibly wasting anyone's time!

View solution in original post