Jump to content
Macro Express Forums

Seek Assistance With Two Macros


anand

Recommended Posts

I would like to create a Macro assigned to the Up Arrow and Down Arrow keys that will read the value from the screen, convert it to a number, would increment (Up Arrow) and decrement (Down Arrow) the values by a figure of 0.05 and then write it back to the screen. To make this work I have written the following Macros -

 

Up Arrow -

 

// Highlight the content of the input field

Text Type: <HOME><SHIFT><END>

 

// Copy it to the clipboard

Text Type: <CONTROL>c

 

// Get the value from the clipboard into a decimal variabl

Variable Set Decimal %D1% from Clipboard

 

// Increment the number

Variable Modify Decimal: %D1% = %D1% + .05

 

// Type out the value into the highlighted field

Text Type: %D1%

 

Alternately

 

// Highlight the content of the input field

Text Type: <HOME><SHIFT><END>

 

// Copy it to the clipboard

Clipboard Copy

 

// Get the value from the clipboard into a decimal variable

Variable Set Decimal %D1% from Clipboard

 

// Set the value of D2 variable

Variable Set Decimal %D2% to .05

 

// Increment the number

Variable Modify Decimal: %D1% = %D1% + %D2%

 

// Type out the value into the highlighted field

Text Type: %D1%

 

The Macro for the Down Arrow would be similar to the above except that the Variable Modify Decimal would be either

Variable Modify Decimal: %D1% = %D1% - .05 or Variable Modify Decimal: %D1% = %D1% - %D2% - depending on the script used.

 

The problem that I am facing is that this Macro isn’t a very robust and reliable one. I request other users to implement these two Macros in Macro Express and then open up a simple editor like Notepad or WordPad, type a number in it and then use these Hotkeys. You will notice that it does not consistently perform as it should.

 

Like for example – Assume we type 25 as a number. By pressing the Up Arrow key once the number should be incremented by 0.05 to 25.05, twice to 25.1, thrice to 25.15 etc. Similarly, by pressing the Down Arrow key the number should be decremented by 0.05 to 24.95, twice to 24.9, thrice to 24.85 etc.

 

Even though this does work it isn’t a consistent performance by the Macro. Very often other figures appear in between.

 

Can anyone please assist by telling how I can improve on my script so that it becomes 100% functional?

 

Thank you,

 

Anand Mehta

Link to comment
Share on other sites

Hi,

Probably the main thing is to check the clipboard has time ; you could just set a 1/2 sec delay, or add these others;

<REM2:Make sure your window has focus (or even the control if still problems with timing)><ACTIVATE2:notepad><WAITWIN2:000010:000000:notepad><TEXTTYPE:<HOME><SHIFT><END>><CLIPE><CLIPC><REM2:Make sure it has copied before proceeding (won't work idf the field could be empty, unless you accept only a certain number of checks)><TVAR2:01:01:><REP3:01:000001:000001:00020:0:01:><NMVAR:08:01:0:0000001:0:0000000><IMSD:25><TVAR2:01:03:><IFVAR2:1:01:2:><EXITREP><ENDIF><ENDREP><REM2:End of copy check><DVAR2:01:03:><REM2:Add a little leeway><IMSD:100><DMVAR:01:01:1:000000000000001.0000:2:.05><REM2:Make sure your window has focus (or even the control if still problems with timing)><ACTIVATE2:notepad><WAITWIN2:000010:000000:notepad><TEXTTYPE:%D1%>
// Make sure your window has focus (or even the control if still problems with timing)

Activate Window: "notepad"

Wait For Window Title: "notepad"

Text Type: <HOME><SHIFT><END>

Clipboard Empty

Clipboard Copy

// Make sure it has copied before proceeding (won't work idf the field could be empty, unless you accept only a certain number of checks)

Variable Set String %T1% ""

Repeat Start (Repeat 20 times)

  Variable Modify Integer: Inc (%N1%)

  Delay 25 Milliseconds

  Variable Set String %T1% from Clipboard

  If Variable %T1% <> ""

    Repeat Exit

  End If

Repeat End

// End of copy check

Variable Set Decimal %D1% from Clipboard

// Add a little leeway

Delay 100 Milliseconds

Variable Modify Decimal: %D1% = %D1% + .05

// Make sure your window has focus (or even the control if still problems with timing)

Activate Window: "notepad"

Wait For Window Title: "notepad"

Text Type: %D1%

Best, Randall

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...