Jump to content

Replace value in textbox based on current value in textbox


Recommended Posts

image.png.a8da9ac2a0cb786ed02cdb010dcdc937.png

Hello, I have create a script to change the date and time value . It just send a mouseclick to adjust the value using the arrow up and down from the application interface. It is possible for me to to change the date based on current date in the box ? For example if the date is 1 Nov , change it to 31 October , if it is 2 Nov change to 1 Nov instead of send  arrow down to reduce the date . I have see replace string function but i not know how to script it.

;Click "Time Box"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 407, 142 )
Sleep(1000)

;Send UP Click 23x
Send("{UP} 23")
Sleep(100)

;Click "Date Box"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 344, 140 )
Sleep(1000)

;Send DOWN Click
Send("{DOWN}")
Sleep(1000)

Edited by wan
Link to post
Share on other sites
Link to post
Share on other sites

Yes but this mean i need to do 30 times as the text to set is not the same value . This is why i try figure on how auto it can recognized what value in the date field and change it accordingly

Link to post
Share on other sites

Hmm.

Maybe do this:

 

1st -  clear the clipboard.

Send a click into the date box.

Send ctrl a (should select all text, you can test it by manually clicking into the date box and pressing ctrl a)

 Then Send Ctrl C to copy the text into clipboard

Read clipboard out.

Check which date it is and change it.

Copy the new value into clipboard

Send Ctrl V - pasting the new text into the field.

Link to post
Share on other sites

Update on my problem . I have figure on how to change the date based on system current date and get the value (NewDate) . But how I want to copy the date value and paste 

it in my application to change the date in the date box? Because I use clipget , it copied something else 

Local $sDate = _DateAdd('d', -2, _NowCalcDate())
;Local $sDate = StringFormat("%02u/%02u/", @YEAR, @MON) & StringRight(@MDAY, 4) ; Format = MM/DD/YYYY
local $sNewDate = StringRegExpReplace($sDate, "[/]", "-")
MsgBox($MB_SYSTEMMODAL, "", "The following data is now stored in the clipboard: " & @CRLF & $sNewDate)


Local $sDate = ClipGet()
MsgBox($MB_SYSTEMMODAL, "", "The following data is now stored in the clipboard: " & @CRLF & $sDate)

Link to post
Share on other sites
Local $sDate = _DateAdd('d', -2, _NowCalcDate())
local $sNewDate = StringRegExpReplace($sDate, "[/]", "-")
MsgBox($MB_SYSTEMMODAL, "", "The date of 2 days ago is: " & @CRLF & $sNewDate) ; this is NOT in the clipboard yet.

ClipPut($sNewDate) ; puts the $sNewDate into the clipboard
MsgBox($MB_SYSTEMMODAL, "", "The following data is now stored in the clipboard: " & @CRLF & ClipGet()) ; use ClipGet to read the clipboard.

Alternatively, if ControlSetText or ControlSend works with the control, then you can bypass the ClipPut and ClipGet and send the $sNewDate directly.

Link to post
Share on other sites
On 11/3/2022 at 8:03 AM, abberration said:
Local $sDate = _DateAdd('d', -2, _NowCalcDate())
local $sNewDate = StringRegExpReplace($sDate, "[/]", "-")
MsgBox($MB_SYSTEMMODAL, "", "The date of 2 days ago is: " & @CRLF & $sNewDate) ; this is NOT in the clipboard yet.

ClipPut($sNewDate) ; puts the $sNewDate into the clipboard
MsgBox($MB_SYSTEMMODAL, "", "The following data is now stored in the clipboard: " & @CRLF & ClipGet()) ; use ClipGet to read the clipboard.

Alternatively, if ControlSetText or ControlSend works with the control, then you can bypass the ClipPut and ClipGet and send the $sNewDate directly.

This one works for me, but after several days. The script fail to paste the value to the date box

Link to post
Share on other sites

You may need to use WinActivate, WinWaitActive and ControlGetHandle to make sure you are targeting the correct window and control. 

I am sure if you meant that it worked for several days and then quit working, but if that is the case, you may have instances of the program still running in the background. Try restarting your PC to ensure everything is cleared.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...