DDERequest and Poke, Excel

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
treniets
Newbie
Posts: 4
Joined: Fri Oct 05, 2007 12:52 am

DDERequest and Poke, Excel

Post by treniets » Sun Oct 28, 2007 2:24 am

I have started on a script that will get poker cards (text) from Excel, put it into a second program called PokerStove and then have that program calculate the Win Percent. Eventually I'll get the results from PokerStove and place it back into Excel.

I have had two problems:

1) The DDEPoke and DDERequest seemed to work well when I was using a blank Spreadsheet called My Test. It the cards AsKs, etc, showed in the cells R6C15, etc. The cards also showed in the variables hand1, etc, in the Watch List window.

When I changed the file to c:\Poker\Deal Hands.xls it failed to work. The cards didn't show in the Deal Hands cells even though they showed in the variable hand1, etc. And when I changed some of the cells in DDERequest to cells that already had cards in them (R6C7 to R9C7) the hand1 etc variables were blank.

I had an earlier version of this script that took text from another Workbook. It got the wrong cells (from a worksheet that wasn't on top I think). When I changed the file to Deal Hands.xls (which only has one sheet) the hand1 etc variables still had wrong data and it was the same data from the wrong sheet from the original file!! It seemed as though DDERequest or the variables had data in it that wouldn't update.

2) The cards (AsKs, etc) show in PokerStove (PS) when I use SetControlText>PokerStove - [PStove1],Edit,2,hand1 etc. The problem is that PS doesn't recognize them. When I copy he hands from PS and paste them into Word there is no problem that I can find. There are no errant spaces or CRLFs in the card text. Even more confusing: when I copy and paste the same card text back into PS it recognizes it and does the calculations. It also works when I copy/paste from excel.

Is it possible that the SetControlText command sends some strange text that is not recognized? I've tried variations on font with no success.

PS doen't have the underlined commands such as Paste so the Press Alt send>ea won't work. Any other options?

Any/All help is appreciated.

Code: Select all

//Specify the path of the Excel filename here
Let>filename=c:\Poker\Deal Hands.xls
//MessageModal>%filename%
IfFileExists>filename

IfWindowOpen>Microsoft Excel - Deal Hands.xls,GetCells,OpenExcel

Label>OpenExcel
ExecuteFile>filename
WaitWindowOpen>Microsoft Excel - Deal Hands.xls

//: Minimize the window
//WindowAction>2,Microsoft Excel - Deal Hands.xls


Label>GetCells
SetFocus>Microsoft Excel - Deal Hands.xls
Wait>1
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R6C15,AsKs
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R7C15,QsJs
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R8C15,Ts9s
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R9C15,AdKd
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R10C15,QdJd
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R11C15,3d4d
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R12C15,AhKh
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R13C15,QhJh
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R14C15,Th9h
DDEPoke>Excel,c:\Poker\Deal Hands.xls,R15C15,AcKc

SetFocus>Microsoft Excel - Deal Hands.xls
Wait>1
DDERequest>Excel,filename,R6C7,hand1,60
DDERequest>Excel,filename,R7C7,hand2,60
DDERequest>Excel,filename,R8C7,hand3,60
DDERequest>Excel,filename,R9C7,hand4,60
DDERequest>Excel,filename,R10C15,hand5,60
DDERequest>Excel,filename,R11C15,hand6,60
DDERequest>Excel,filename,R12C15,hand7,60
DDERequest>Excel,filename,R13C15,hand8,60
DDERequest>Excel,filename,R14C15,hand9,60
DDERequest>Excel,filename,R15C15,hand10,60

//remove the CRLF that Excel adds
StringReplace>hand1,CRLF,,hand1
StringReplace>hand2,CRLF,,hand2
StringReplace>hand3,CRLF,,hand3
StringReplace>hand4,CRLF,,hand4
StringReplace>hand5,CRLF,,hand5
StringReplace>hand6,CRLF,,hand6
StringReplace>hand7,CRLF,,hand7
StringReplace>hand8,CRLF,,hand8
StringReplace>hand9,CRLF,,hand9
StringReplace>hand10,CRLF,,hand10


IfWindowOpen>PokerStove - [PStove1]
PushButton>PokerStove - [PStove1],Clear All
PushButton>PokerStove - [PStove1],Monte Carlo

Wait>1
Else
Run Program>C:\Program Files\PokerStove\PokerStove.exe
WaitWindowOpen>PokerStove - [PStove1]
PushButton>PokerStove - [PStove1],Clear All
PushButton>PokerStove - [PStove1],Monte Carlo
EndIf

SetFocus>PokerStove - [PStove1]
SetControlText>PokerStove - [PStove1],Edit,2,hand1
SetControlText>PokerStove - [PStove1],Edit,3,hand2
SetControlText>PokerStove - [PStove1],Edit,4,hand3
SetControlText>PokerStove - [PStove1],Edit,5,hand4
SetControlText>PokerStove - [PStove1],Edit,6,hand5
SetControlText>PokerStove - [PStove1],Edit,7,hand6
SetControlText>PokerStove - [PStove1],Edit,8,hand7
SetControlText>PokerStove - [PStove1],Edit,9,hand8
SetControlText>PokerStove - [PStove1],Edit,10,hand9
SetControlText>PokerStove - [PStove1],Edit,11,hand10
Wait>1
PushButton>PokerStove - [PStove1],Evaluate
Wait>5
PushButton>PokerStove - [PStove1],Stop

Else
  MessageModal>Could not find: %filename%
Endif

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Oct 28, 2007 7:01 am

Could you post a link to your xls file or send it to support so that we can debug your script and see what is happening?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Oct 29, 2007 8:17 am

Thanks for sending your XLS file to me. The problem is that your workbook has a number of worksheets. The first worksheet is "BestStartHands" although it appears hidden by default. Your DDE commands are not specifying the worksheet name. So they are retrieving data correctly from the "BestStartHands" sheet, where you appear to be expecting them to come from "Deal Hands" (I assume). Your DDEPoke commands are therefore overwriting data in "BestStartHands" with data you want to appear on a different sheet.

Solution. Specify the required sheet name:

DDEPoke>Excel,%filename%:Deal Hands,R6C15,AsKs
DDEPoke>Excel,%filename%:Deal Hands,R7C15,QsJs
DDEPoke>Excel,%filename%:Deal Hands,R8C15,Ts9s
DDEPoke>Excel,%filename%:Deal Hands,R9C15,AdKd
DDEPoke>Excel,%filename%:Deal Hands,R10C15,QdJd
etc

And:
DDERequest>Excel,%filename%:Deal Hands,R6C7,hand1,60
DDERequest>Excel,%filename%:Deal Hands,R7C7,hand2,60
etc
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

treniets
Newbie
Posts: 4
Joined: Fri Oct 05, 2007 12:52 am

Post by treniets » Tue Oct 30, 2007 1:08 am

GOT JOY!!

I wasn't aware of specifying the worksheet name. It's flawless now.

The Deal Hand workbook was made by renaming a workbook that had several sheets and deleting them. I had no idea that they were only hidden. When I opened the VB Editor, they still showed as Objects. They can be deleted by right-clicking and deleting again! But there is no need to do this now!

If you could tell me why the "SetControlText>PokerStove - [PStove1],Edit,2,hand1" sends text that can't be recognized by PS, I would be over Joyed.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Oct 30, 2007 8:10 am

If you could tell me why the "SetControlText>PokerStove - [PStove1],Edit,2,hand1" sends text that can't be recognized by PS, I would be over Joyed.
SetControlText does not "send" text. Send Character/Text (usually abbreviated to Send) sends text. There's a big difference to the ways these two commands work.

Send, simulates keystrokes, to do what a user does. It simulates a user typing text. We can therefore pretty much guarantee that this will work with any application - since if a user can type into it, so can the Send command.

SetControlText works at a lower level. Many window controls have caption properties. In theory if you can get a handle to these controls you can SET the caption text. It is set programmatically by sending a message to the control. It works beneath the user interface layer. So it is not the same as "sending" characters. In theory, if the control has a standard caption property, it should set the text. I say in theory because (unless we built it) we cannot guarantee how a control will behave when it receives a message to set it's text. Many objects may not be standard windows objects and may behave differently. It may do extra processing and require other events before the text will change. Or maybe the control simply doesn't have a caption property. Perhaps the programmer built it to only accept messages coming from a certain process or object. It may look like a regular text control. But it may not be.

SetControlText is convenient where it can be used. But if all else fails we can use Send to simulate keystrokes and "type" into the control.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

treniets
Newbie
Posts: 4
Joined: Fri Oct 05, 2007 12:52 am

Post by treniets » Thu Nov 01, 2007 11:57 pm

I AM Over Joyed! Your response saved me untold frustrating hours.

The app doesn't accept the SetText command or the commands such as Press ALT, Send>fa, Release ALT (it doesn't have the underlined commands like Paste).

I tried several methods of manually putting text into the app and found if I right clicked on one of the Edit Class Controls that take the text a window opened with the Paste command. Pressing "p" (no Caps) pasted the text from the clipboard.

I used MouseMove, RClick and Send to simulate it.

It may just be Best Unintentional Recommended Pratice (BURP) but it works great.

Thanks

Code: Select all

PutClipBoard>%hand1%
SetFocus>PokerStove - [PStove1]
Wait>.1
MouseMoveRel>125,160
Wait>.1
RClick
Wait>.1
Send Character/Text>p

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Nov 02, 2007 8:21 am

Instead of MouseMove and RClick try this:

Press>MenuKey

The menu key (it's usually on the right of the spacebar and looks like a little menu) usually opens the popup menu that is invoked by right clicking the mouse.

So you may just need:

SetFocus>PokerStove - [PStove1]
Press>MenuKey
Send>p

Which is more reliable that using MouseMove. If you must use MouseMove I would recommend you use MouseMoveRel instead so that the movement is relative to the window, not absolute. Then if the window is moved, it will still work.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts