Jump to content

Send automatic text from to input box or edit inputbox text


Recommended Posts

Hi I'm sorry for my English, I'm a newbie in autoit, and I made a script for my work, the scrip sends two dates $currentdate and $expirationdate.
But I have a problem, I need that selecting the auto radio will send those dates;
but selecting the manual radio I need write two dates in the inputbox and send them, thank you for you help 😄

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("Form1", 289, 198, 192, 124)
Local $Input1 = GUICtrlCreateInput("", 129, 50, 105, 21)
GUICtrlSetData(-1, "aaaa-mm-dd", "")
Local $Input2 = GUICtrlCreateInput("", 130, 87, 105, 21)
GUICtrlSetData(-1, "aaaa-mm-dd", "")
Local $Button2 = GUICtrlCreateButton("Send", 171, 139, 75, 24)
Local $Label1 = GUICtrlCreateLabel("Date1", 73, 53, 33, 17)
Local $Label2 = GUICtrlCreateLabel("Date2", 73, 89, 33, 17)
Local $Radio1 = GUICtrlCreateRadio("Auto", 77, 17, 78, 17)
GUICtrlCreateCheckbox("", 304, 98, 36, 17)
Local $Radio2 = GUICtrlCreateRadio("Manual", 157, 17, 113, 17)
GUICtrlCreateCheckbox("", 304, 98, 36, 17)
Local $Button1 = GUICtrlCreateButton("Save", 53, 139, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button2
            _Load ()
         Case $Button1
            Select
               Case GUICtrlRead($Radio1) = 1

               Case GUICtrlRead($Radio2) = 1

            EndSelect
    EndSwitch
 WEnd


 _load ()
Func _load ()

Local $currentdate, $expirationdate, $month
Sleep(20)
$month = @MON
$month += 1
$currentdate = StringRight(@Year, 4) & ("-") & StringFormat("%02u-%02u", @MON, @MDAY)
$expirationdate = StringRight(@Year, 4) & ("-") & StringRight($month, 2) & ("-") & StringRight(@MDAY, 2)

Sleep(20)
   WinActivate ("Untitle - Notepad", "")
Sleep(20)
   WinWaitActive ("Untitle - Notepad", "", 0)
Sleep(20)
    Send ($currentdate)
Sleep(20)
    Send("{TAB}")
Sleep(20)
    Send ($expirationdate)
Send("{ENTER}")
EndFunc


 

Link to comment
Share on other sites

Hello, 

I’ll try to help you.

1) you need to complet what’s happen for your sélect case radio1&2

2) not sûre for the ctrlread 

3) you can remove the second call : _load () because he won’t be called anyway here.

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Something like this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("Form1", 289, 198, 192, 124)
Local $Input1 = GUICtrlCreateInput("", 129, 50, 105, 21)
GUICtrlSetData(-1, "aaaa-mm-dd", "")
Local $Input2 = GUICtrlCreateInput("", 130, 87, 105, 21)
GUICtrlSetData(-1, "aaaa-mm-dd", "")
Local $Button2 = GUICtrlCreateButton("Send", 171, 139, 75, 24)
Local $Label1 = GUICtrlCreateLabel("Date1", 73, 53, 33, 17)
Local $Label2 = GUICtrlCreateLabel("Date2", 73, 89, 33, 17)
Local $Radio1 = GUICtrlCreateRadio("Auto", 77, 17, 78, 17)
GUICtrlCreateCheckbox("", 304, 98, 36, 17)
Local $Radio2 = GUICtrlCreateRadio("Manual", 157, 17, 113, 17)
GUICtrlCreateCheckbox("", 304, 98, 36, 17)
Local $Button1 = GUICtrlCreateButton("Save", 53, 139, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
         Case $nMsg = $Button2
            _SendDates(GUICtrlRead($Input1), GUICtrlRead($Input2))
        Case $nMsg = $Radio1 And GUICtrlRead($Radio1) = $GUI_CHECKED
             _SendDates ()
    EndSelect
 WEnd

Func _SendDates($_vCurrentDate = "Auto", $_vExpirationDate = "Auto")
    Local $iMonth = @MON + 1
    Local $vCurrentDate = $_vCurrentDate = "Auto" ? StringRight(@Year, 4) & ("-") & StringFormat("%02u-%02u", @MON, @MDAY) : $_vCurrentDate
    Local $vExpirationDate = $_vExpirationDate = "Auto" ? StringRight(@Year, 4) & ("-") & StringRight($iMonth, 2) & ("-") & StringRight(@MDAY, 2) : $_vExpirationDate
    Sleep(20)
        WinActivate ("Untitled - Notepad", "")
        Sleep(20)
        WinWaitActive ("Untitled - Notepad", "", 0)
    Sleep(20)
        Send ($vCurrentDate)
    Sleep(20)
        Send("{TAB}")
    Sleep(20)
        Send ($vExpirationDate)
        Send("{ENTER}")
EndFunc

 

Link to comment
Share on other sites

18 hours ago, Subz said:

Something like this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("Form1", 289, 198, 192, 124)
Local $Input1 = GUICtrlCreateInput("", 129, 50, 105, 21)
GUICtrlSetData(-1, "aaaa-mm-dd", "")
Local $Input2 = GUICtrlCreateInput("", 130, 87, 105, 21)
GUICtrlSetData(-1, "aaaa-mm-dd", "")
Local $Button2 = GUICtrlCreateButton("Send", 171, 139, 75, 24)
Local $Label1 = GUICtrlCreateLabel("Date1", 73, 53, 33, 17)
Local $Label2 = GUICtrlCreateLabel("Date2", 73, 89, 33, 17)
Local $Radio1 = GUICtrlCreateRadio("Auto", 77, 17, 78, 17)
GUICtrlCreateCheckbox("", 304, 98, 36, 17)
Local $Radio2 = GUICtrlCreateRadio("Manual", 157, 17, 113, 17)
GUICtrlCreateCheckbox("", 304, 98, 36, 17)
Local $Button1 = GUICtrlCreateButton("Save", 53, 139, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
         Case $nMsg = $Button2
            _SendDates(GUICtrlRead($Input1), GUICtrlRead($Input2))
        Case $nMsg = $Radio1 And GUICtrlRead($Radio1) = $GUI_CHECKED
             _SendDates ()
    EndSelect
 WEnd

Func _SendDates($_vCurrentDate = "Auto", $_vExpirationDate = "Auto")
    Local $iMonth = @MON + 1
    Local $vCurrentDate = $_vCurrentDate = "Auto" ? StringRight(@Year, 4) & ("-") & StringFormat("%02u-%02u", @MON, @MDAY) : $_vCurrentDate
    Local $vExpirationDate = $_vExpirationDate = "Auto" ? StringRight(@Year, 4) & ("-") & StringRight($iMonth, 2) & ("-") & StringRight(@MDAY, 2) : $_vExpirationDate
    Sleep(20)
        WinActivate ("Untitled - Notepad", "")
        Sleep(20)
        WinWaitActive ("Untitled - Notepad", "", 0)
    Sleep(20)
        Send ($vCurrentDate)
    Sleep(20)
        Send("{TAB}")
    Sleep(20)
        Send ($vExpirationDate)
        Send("{ENTER}")
EndFunc

 

 

 

its useful to me thank you 👍👍

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...