Best way to check if a Button is missing (C#).

Ask general questions here.
bebenin_s
Posts: 6
Joined: Sat Nov 08, 2008 11:43 pm
Location: Boston, MA

Best way to check if a Button is missing (C#).

Post by bebenin_s » Sat Nov 08, 2008 11:56 pm

Hello,
I am wondering if there is a way to check if the button exists on the Form.
I tried:
if (m_MyButton == null)
but I get Error CS0029: Cannot implicitly convert type 'Ranorex.Button' to 'bool'

Thanks!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Mon Nov 10, 2008 9:06 am

Hi,

Could you please clarify your request? I need to know how you're searching for a button object. In addition I'd have to know if you're using Ranorex V1.5 or Ranorex V2.0.

Would it be possible to provide me a more detailed code snippet?

best regard,

Christoph,
Ranorex Support Team

bebenin_s
Posts: 6
Joined: Sat Nov 08, 2008 11:43 pm
Location: Boston, MA

Post by bebenin_s » Mon Nov 10, 2008 2:25 pm

Hi, thanks for respond.
Here's the code (using Ranorex 1.5):

Form m_MessageBox = Application.FindFormTitle("FOO");
Button m_ButtonOk = m_MessageBox.FindButton("btnEnter");

if (m_ButtonOk == null)
{
........
}
else
{
.......
}

Would it be better to use Ranorex 2.0?
Thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Tue Nov 11, 2008 9:45 am

Your code works perfectly well for me. If button m_ButtonOk is not found, null is returned and the if branch is executed. Do you still get a compile error?
bebenin_s wrote:Would it be better to use Ranorex 2.0?
Ranorex 2.0 introduces new features that make automation a lot easier. Ranorex 2.0 code is more compact and even more readable than Ranorex 1.5 code. However, Ranorex 2.0 is not released, yet. There is a Technology Preview available, but it is not intended to be used in a productional environment due to stability issues.

Regards,
Alex
Ranorex Support Team

bebenin_s
Posts: 6
Joined: Sat Nov 08, 2008 11:43 pm
Location: Boston, MA

Post by bebenin_s » Tue Nov 11, 2008 2:22 pm

I know what happened. I used a single '=' instead of a double '=' in the IF statement.
Sorry for misinformation, it was very late.
Thank you very much.