Jump to content

Some problems with send command


Recommended Posts

Hi Guys! Me thankful to you people on helping me whenever i face some problem. Well this time i am facing two problems.

My first problem is that i m making a script to be used on a variety of pcs. So i am getting some minor problem with the Send Command. My code is as

WinActivate ( "New Microsoft Word document.doc - Microsoft Word", "")

WinWaitActive ( "New Microsoft Word document.doc - Microsoft Word", "")

sleep (300)

Send ( "+{END}" );Right here me trying to select already written Month 0, 2010 text

;but sometimes on some pcs it selects the whole text while on some pcs it is selecting incomplete text

;as you can see that i have used sleep command as well after the winwaitactive command but still it sometimes doesnot select the full text on the very first line in my word document. I am now sure that it is due to the delay of the document, which Microsoft Word takes to activate the document.

Send ( "+{LEFT}" )

Send ( "{DEL}" )

The second problem is again with send command, it is related with GUICtrlCreateDate . Again the code is as:

;inserting date by asking you.

Opt('MustDeclareVars', 1)

Example()

Func Example()

Local $Button_1, $msg, $calender

GUICreate ("Select Visit Date", 300,200)

; BUTTON

;Create an "OK" button

$calender = GUICtrlCreateDate ( "", 10, 20, 200,20)

$Button_1 = GUICtrlCreateButton("OK", 220, 19, 50, 20)

GUISetState(@SW_SHOW)

;sleep (2000)

WinWaitActive ("Select Visit Date", "")

Send ("{RIGHT}")

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_1

WinActivate ( "New Microsoft Word document.doc - Microsoft Word" , "")

WinWaitActive ( "New Microsoft Word document.doc - Microsoft Word", "")

Send (GUICtrlRead($calender)); Right here it is sending the date in following format

;Like Thursday, November 18, 2010 whereas i just want to send date as November 18, 2010

ExitLoop

EndSelect

WEnd

EndFunc ;==>Example

Link to comment
Share on other sites

Allisonline,

For the first problem, you're probably better off using the _Word* UDF functions, check out the Help File for some examples :graduated:

Second problem is that the Date control formats the date differently to how you want it. You'll need to strip out the first part of it.

Local $strRegex = "(^.*?\W\s)" ; Removes the first word including spacing characters
Local $strDirty = "Thursday, November 18, 2010";
Local $strClean

$strClean = StringRegExpReplace($strDirty, $strRegex, "") ; Replace the matched text with nothing

ConsoleWrite($strClean & @CRLF)

James

Link to comment
Share on other sites

Thanks for the quick reply. As regards to the second problem does the solution you mentioned applies only to the date which i wrote in the post or will it apply to the general date when inserting by send command.

Actually the GUI is letting the user to select the date from pop up and when the user selects the date, the script has to insert date like Month(Full Name) Date(Two Digits but if less then 10 than one Digit), YEAR(Four Digits).

But by default the script is sending like Day(Full), Month(Full) Date(two digits either less than 10), Year((Four digits).

Link to comment
Share on other sites

Thanks for the quick reply. As regards to the second problem does the solution you mentioned applies only to the date which i wrote in the post or will it apply to the general date when inserting by send command.

But by default the script is sending like Day(Full), Month(Full) Date(two digits either less than 10), Year((Four digits).

It will only work with the date you provided since that's the only output you'll get from the *Date control I believe.

James

Link to comment
Share on other sites

It will only work with the date you provided since that's the only output you'll get from the *Date control I believe.

James

Thanks again for clearing the confusion but now first i can't judge that where should i write the code, which you provided, in my script.

And secondly please i can't understand that why have you mentioned specifically Thursday, November 18, 2010 in your very first reply.

Local $strDirty = "Thursday, November 18, 2010";

I was thinking that my script needs something like this:

$calender = GUICtrlRead($Date)
$calender = StringMid($date, 6, 3) & StringRight($date, 2) & "/" & StringLeft($date, 4)
Send ($Date);RIGHT HERE I want to send the date (which was clicked) in format:
; Month FULL NAME then SPACE then DD then COMA then space then YYYY
;E.G
;October 3, 2008 OR August 10, 2001
  ;MONTH DD,(2 Digits but 1 if less than 10)YYYY format.


;But by default it is sending in format 
;Means writing full DAY name then COMA then SPACE then FULL MONTH NAME then SPACE DD
;then COMA then SPACE then YYYY
;E.G Monday, October 20, 2010
Edited by Aliisonline
Link to comment
Share on other sites

And secondly please i can't understand that why have you mentioned specifically Thursday, November 18, 2010 in your very first reply.

Because you used it as an example here:

;Like Thursday, November 18, 2010 whereas i just want to send date as November 18, 2010

But it will work with any date that is in the same format.

Try "Monday, October 12, 2010" for example. You'll get the data you need.

James

Link to comment
Share on other sites

Allisonline,

Try this,

Opt('MustDeclareVars', 1)

Example()
Func Example()
    Local $Button_1, $msg, $calender
    Local $strRegex = "(^.*?\W\s)" ; Removes the first word including spacing characters
    GUICreate("Select Visit Date", 300, 200)

    ; BUTTON
    ;Create an "OK" button
    $calender = GUICtrlCreateDate("", 10, 20, 200, 20)
    $Button_1 = GUICtrlCreateButton("OK", 220, 19, 50, 20)
    GUISetState(@SW_SHOW)
    ;sleep (2000)
    WinWaitActive("Select Visit Date", "")
    Send("{RIGHT}")
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg = $Button_1
                WinActivate("New Microsoft Word document.doc - Microsoft Word", "")
                WinWaitActive("New Microsoft Word document.doc - Microsoft Word", "")
                $strDate = GUICtrlRead($calender)
                $strDate = StringRegExpReplace($strDate, $strRegex, "") ; Replace the matched text with nothing
                
                Send($strDate); Right here it is sending the date in following format
                ;Like Thursday, November 18, 2010 whereas i just want to send date as November 18, 2010
                ExitLoop
        EndSelect
    WEnd
EndFunc   ;==>Example

James

Link to comment
Share on other sites

Allisonline,

Try this,

Opt('MustDeclareVars', 1)

Example()
Func Example()
    Local $Button_1, $msg, $calender
    Local $strRegex = "(^.*?\W\s)" ; Removes the first word including spacing characters
    GUICreate("Select Visit Date", 300, 200)

    ; BUTTON
    ;Create an "OK" button
    $calender = GUICtrlCreateDate("", 10, 20, 200, 20)
    $Button_1 = GUICtrlCreateButton("OK", 220, 19, 50, 20)
    GUISetState(@SW_SHOW)
    ;sleep (2000)
    WinWaitActive("Select Visit Date", "")
    Send("{RIGHT}")
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg = $Button_1
                WinActivate("New Microsoft Word document.doc - Microsoft Word", "")
                WinWaitActive("New Microsoft Word document.doc - Microsoft Word", "")
                $strDate = GUICtrlRead($calender)
                $strDate = StringRegExpReplace($strDate, $strRegex, "") ; Replace the matched text with nothing
                
                Send($strDate); Right here it is sending the date in following format
                ;Like Thursday, November 18, 2010 whereas i just want to send date as November 18, 2010
                ExitLoop
        EndSelect
    WEnd
EndFunc   ;==>Example

James

ME a lot thankful to you for your close attention. I tried your suggestion but me getting this error

It only left behind , 2010

Edited by Aliisonline
Link to comment
Share on other sites

ME a lot thankful to you for your close attention. I tried your suggestion but me getting this error

It only left behind , 2010

Are you sure?

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()
Func Example()
    Local $Button_1, $msg, $calender, $strDate
    Local $strRegex = "(^.*?\W\s)" ; Removes the first word including spacing characters
    GUICreate("Select Visit Date", 300, 200)

    ; BUTTON
    ;Create an "OK" button
    $calender = GUICtrlCreateDate("", 10, 20, 200, 20)
    $Button_1 = GUICtrlCreateButton("OK", 220, 19, 50, 20)
    GUISetState(@SW_SHOW)
    ;sleep (2000)
    WinWaitActive("Select Visit Date", "")
    Send("{RIGHT}")
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg = $Button_1
;~              WinActivate("New Microsoft Word document.doc - Microsoft Word", "")
;~              WinWaitActive("New Microsoft Word document.doc - Microsoft Word", "")
                $strDate = GUICtrlRead($calender)
                $strDate = StringRegExpReplace($strDate, $strRegex, "") ; Replace the matched text with nothing
                MsgBox(0, "", $strDate)
;~              Send($strDate); Right here it is sending the date in following format
                ;Like Thursday, November 18, 2010 whereas i just want to send date as November 18, 2010
                ExitLoop
        EndSelect
    WEnd
EndFunc   ;==>Example

Works perfect for me.

Link to comment
Share on other sites

Allisonline,

What I did notice is that I didn't format the date as you first wanted it to be. This function however will output the date exactly how you want it.

ConsoleWrite(LongDateToShort("Thursday, November 18, 2010") & @CRLF)

Func LongDateToShort($s_Date)
    Local $strRegex = "(^.*?\W\s)(.*?\W\s)([0-9]*)" ; Long, I know...
    $s_Date = StringRegExp($s_Date, $strRegex, 3)
    Return $s_Date[1] & $s_Date[2]
EndFunc

Better yet,

Func LongDateToShort($s_Date)
    Local $strRegex = "(^.*?\W\s)(.*?\W\s)([0-9]*)" ; Long, I know...
    Return StringRegExpReplace($s_Date, $strRegex, "$2$3")
EndFunc
James Edited by JamesBrooks
Link to comment
Share on other sites

Are you sure?

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()
Func Example()
    Local $Button_1, $msg, $calender, $strDate
    Local $strRegex = "(^.*?\W\s)" ; Removes the first word including spacing characters
    GUICreate("Select Visit Date", 300, 200)

    ; BUTTON
    ;Create an "OK" button
    $calender = GUICtrlCreateDate("", 10, 20, 200, 20)
    $Button_1 = GUICtrlCreateButton("OK", 220, 19, 50, 20)
    GUISetState(@SW_SHOW)
    ;sleep (2000)
    WinWaitActive("Select Visit Date", "")
    Send("{RIGHT}")
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg = $Button_1
;~              WinActivate("New Microsoft Word document.doc - Microsoft Word", "")
;~              WinWaitActive("New Microsoft Word document.doc - Microsoft Word", "")
                $strDate = GUICtrlRead($calender)
                $strDate = StringRegExpReplace($strDate, $strRegex, "") ; Replace the matched text with nothing
                MsgBox(0, "", $strDate)
;~              Send($strDate); Right here it is sending the date in following format
                ;Like Thursday, November 18, 2010 whereas i just want to send date as November 18, 2010
                ExitLoop
        EndSelect
    WEnd
EndFunc   ;==>Example

Works perfect for me.

Hmmm. OK OK OK THANKS BRO IT IS WORKING NOW.

Now please can you tell me some thing more.

I m trying to create a word document till yet i have found that i can use

#Include <Misc.au3>
#include <GUIConstants.au3>
GUICreate( "Get date", 210,190)
$Date = GUICtrlCreateMonthCal ("",10, 10)
GUISetState()
While 1
Sleep ( 50 )
If _IsPressed("01") Then
#include <Word.au3>
$calldate = GUICtrlRead($Date)
$oWordApp = _WordCreate (@DesktopDir & \"Test.doc"); RIGHT HERE I WANT TO SAVE THE FILE with the date which is
;selected in the gui and want to add some other strings also but can't make sense how

ExitLoop
EndIf
WEnd

Actually i want to create a word document with filename in following format

20100529 -- 568921(this is a string) -- SomeName(this is a string also)

I can collect all strings but can't figure out how to write in _WordCreate syntax

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