Jump to content
Macro Express Forums

Control: checkbox, any way to judge the state of it?


mcorriga

Recommended Posts

For part of my macro, I want it to recognize a checkbox and only click it if the checkbox is unchecked at the time. If it is already checked, I want it to take no action. So the issue becomes, how do I get it to recognize whether the checkbox is checked or not? When I use "Get Control" it recognizes it as:

 

Checkbox (Index #)

Button (Index #)

 

So far I've only been able to get the macro to treat it like any button. How do I get it to observe the state of the checkbox?

 

Thanks in advance,

 

Michael Corrigan

Link to comment
Share on other sites

Here's a copy of an article in the Knowledgebase that explains how to do this.

 

 

27. How can I determine the state of a checkbox or radio button?

 

Macro Express does not have a macro command that allows you to determine the state of a checkbox or radio button, but there are ways to do this using existing macro commands.

 

This technique will work to determine the state of a checkbox or a radio button. To simplify, this description will only refer to a checkbox.

 

Several steps may be needed. First, get the position of the checkbox, second, use the Get Pixel Color command to determine whether the checkbox is checked and third, use an If Variable command to take specific action if the checkbox is checked or unchecked.

 

There are several ways to determine the position of the checkbox:

 

1. If the checkbox is in a fixed position on a dialog window, you can use the Mouse Locator when writing your macro to get the position of the checkbox and use those coordinates directly in your macro.

2. If the checkbox is not in a fixed position but it is a Windows Control, you can use the Window Control commands to get the position. Use the Get Control command to set a control variable and then use the 'Variable Set Integer from Control Left' and 'Variable Set Integer from Control Top' to get the screen position coordinates. (There is a tutorial in the Macro Express help that describes how to use the Window Control commands.)

3. If the checkbox is not in a fixed position and it is not a Windows Control, you probably will need to move the mouse to the checkbox and then use the Get Mouse Position command. To move the mouse to the checkbox, you may need to send keystrokes. For example, you might be able to use an Alt shortcut or you may need to send a series of <TAB>s.

 

 

Once you know the position of the checkbox, use the Get Pixel Color command to determine if the checkbox is checked. The Get Pixel Color command will set an integer variable (%N1%, for example) to the value of the pixel on the screen. Black has a pixel color value of 0.

 

You may need to adjust the position coordinates to make sure you are looking at a part of the checkbox that turns black when checked.

 

Then, using the 'If Variable' command, you can have your macro take a specific action such as clicking on the checkbox to uncheck it.

 

Example Macro:

 

Get Control %C1%

Variable Set Integer %N2% from Control %C1% Left

Variable Set Integer %N3% from Control %C1% Top

Variable Modify Integer: %N2% = %N2% + 4

Variable Modify Integer: %N3% = %N3% + 6

Get Pixel: Screen Coords: %N2%,%N3% into %N1%

If Variable %N1% = 0

// The box is checked

Else

// The box is unchecked

End If

Link to comment
Share on other sites

Thank you, that works beautifully. I'm excited to hopefully actually finish my macro now.

 

Here's a copy of an article in the Knowledgebase that explains how to do this.

 

 

27. How can I determine the state of a checkbox or radio button?

 

Macro Express does not have a macro command that allows you to determine the state of a checkbox or radio button, but there are ways to do this using existing macro commands.

 

This technique will work to determine the state of a checkbox or a radio button. To simplify, this description will only refer to a checkbox.

 

Several steps may be needed. First, get the position of the checkbox, second, use the Get Pixel Color command to determine whether the checkbox is checked and third, use an If Variable command to take specific action if the checkbox is checked or unchecked.

 

There are several ways to determine the position of the checkbox:

 

1. If the checkbox is in a fixed position on a dialog window, you can use the Mouse Locator when writing your macro to get the position of the checkbox and use those coordinates directly in your macro.

2. If the checkbox is not in a fixed position but it is a Windows Control, you can use the Window Control commands to get the position. Use the Get Control command to set a control variable and then use the 'Variable Set Integer from Control Left' and 'Variable Set Integer from Control Top' to get the screen position coordinates. (There is a tutorial in the Macro Express help that describes how to use the Window Control commands.)

3. If the checkbox is not in a fixed position and it is not a Windows Control, you probably will need to move the mouse to the checkbox and then use the Get Mouse Position command. To move the mouse to the checkbox, you may need to send keystrokes. For example, you might be able to use an Alt shortcut or you may need to send a series of <TAB>s.

 

 

Once you know the position of the checkbox, use the Get Pixel Color command to determine if the checkbox is checked. The Get Pixel Color command will set an integer variable (%N1%, for example) to the value of the pixel on the screen. Black has a pixel color value of 0.

 

You may need to adjust the position coordinates to make sure you are looking at a part of the checkbox that turns black when checked.

 

Then, using the 'If Variable' command, you can have your macro take a specific action such as clicking on the checkbox to uncheck it.

 

Example Macro:

 

Get Control %C1%

Variable Set Integer %N2% from Control %C1% Left

Variable Set Integer %N3% from Control %C1% Top

Variable Modify Integer: %N2% = %N2% + 4

Variable Modify Integer: %N3% = %N3% + 6

Get Pixel: Screen Coords: %N2%,%N3% into %N1%

If Variable %N1% = 0

// The box is checked

Else

// The box is unchecked

End If

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...