Loading a gnubg position with code

127 views
Skip to first unread message

BlueDice

unread,
Oct 20, 2016, 6:31:09 AM10/20/16
to
For any one who might be interested, after much fumbling, here is my VBA snippet for firing up gnubg with a position loaded, via an excel spreadsheet. VB would be similar for other front end apps:

Dim f as string, MyTask as double

f = "C:\Program Files (x86)\gnubg\gnubg.exe -c MyPosition.txt"
MyTask = Shell(f, 1)

MyPosition.txt is a file containing the "set gnubgid" gnu command, for example:
"set gnubgid bdsGMADYvQMjAA:cAkOAAAAAAAE"

I am building a spreadsheet based 'quiz' containing positions I find interesting or difficult. A double click on the gnubgID cell fires up gnu with the position loaded. Alongside a form appears with a pick list of the top 10 moves (hidden equities). The equity losses are saved and used to weight the appearance of quiz questions. This is purely a self educational tool.

It would be interesting to know if XG can be fired up in a similar way with position loaded from an xgid text string?
--
BD

michae...@gmail.com

unread,
Oct 20, 2016, 11:09:06 AM10/20/16
to
Nice. but do the cells support the double click?
also the executable might no be in C:\Program Files (x86)\gnubg\gnubg.exe
I think it would be better to allow users a cell where they would enter the path of the executable, and maybe design a button to read positions after one select the cell rather than double click on it.

BlueDice

unread,
Oct 20, 2016, 12:15:54 PM10/20/16
to
Thanks for your response.
Everything you see in my post is working code
Excel worksheets have worksheet specific code (right click on a sheet tab and select 'View Code') It is in there whether you use it or not.
Available within every sheet code is the native "Private Sub Worksheet_BeforeDoubleClick" event. There are many different native sheet events. The BeforeDoubleClick event will be triggered only on cells specified by you within that event code. I could give you the method for this if required.
I find it is very convenient to use the pre-existing column of gnubgIds in my spreadsheet to trigger the code - a button could be used but I find it quicker without.

Regarding the location of the .exe file - of course, you point to where the file is located with your code. It could be located anywhere you wish on your system! I'm giving a simple literal example of my working code to convey the method to anyone interested.

I am still interested to find the answer to my question in the OP about auto loading an XG position using the XG ID text string, from previous posts I know you do not run XG yourself but you may have some knowledge on this?
--
BD

michae...@gmail.com

unread,
Oct 20, 2016, 4:28:39 PM10/20/16
to
initiate XG from shell and send him keys
Suppose your spreadsheet has some XG id on cell A2 this code should start XG and paste the ID on it.

Sheets("Sheet1").Select
Range("A2").Select
Selection.Copy

MyAppID = Shell("the full path of the XG executable", 1) '1 for maximized window
AppActivate MyAppID
Application.Wait (Now + 0.0005) ' depending on the system 1=1 day 0.0005 is about 1 minute on my PC
Application.SendKeys ("%FIC, 1") '1=1 sec to let XG catch up

michae...@gmail.com

unread,
Oct 20, 2016, 4:34:10 PM10/20/16
to
Clarification: "the full path of the XG executable" -->it needs the quotation
marks e.g "C:\program files\XG\XG.exe"

BlueDice

unread,
Oct 20, 2016, 5:21:03 PM10/20/16
to
Michael,
I have no problem to fire up the XG.exe from VBA or any other .exe for that matter.
FYI you cannot paste the XG iD from the spreadsheet to the XG app - try it - you'll see it can't work.
If you look at my OP you see the "-c" extension to the command line instruction, and then a file name - the file contains the gnubgID - this is how I can fire up gnubg and auto load a position (gnubgid = position)
This is working code - works fine - no problem with it
There is no need to "wait" for my purposes. BTW - Lookup Chip Pearson for a slick shell & wait routine to cover all requirements.

To clarify, I am looking for a way to fire up XG and auto load an XG ID
Another way of putting it would be: <How to load XG from the command line and at the same time set the board up with an XG position from an XG ID> This needs to be all in one instruction from the command line (This is what happens via the shell command in my OP for gnubg)
--
BD

BlueDice

unread,
Oct 20, 2016, 5:55:33 PM10/20/16
to
Ahhhh! I'll give the 'SendKeys' method a try - Thanks
--
BD

BlueDice

unread,
Oct 20, 2016, 5:59:07 PM10/20/16
to
ie: I'll try the method with gnu - I do not have XG yet
BTW does anyone know when XG3 is likely to launch?
--
BD

michae...@gmail.com

unread,
Oct 20, 2016, 6:03:43 PM10/20/16
to
On Thursday, October 20, 2016 at 11:55:33 PM UTC+2, BlueDice wrote:
>
>
> Ahhhh! I'll give the 'SendKeys' method a try - Thanks
> --
> BD


It works man I am 99.99% sure. I have tried this so many times... Some programs don't like the CTL+V for paste which in VBA is ^V that's why I proposed you the ALT+F+... method that in VBA is %F...

michae...@gmail.com

unread,
Oct 20, 2016, 7:29:51 PM10/20/16
to
Just tested it on GNU, which by itself is too messy. With some minor corrections on the code it works fine.
here's the code:

On Error Resume Next
Sheets("Sheet1").Select
Range("A2").Select
Selection.Copy

MyAppID = Shell("C:\Program Files\gnubg\gnubg.exe", 1)
AppActivate MyAppID
Application.Wait (Now + 0.00001)

Application.SendKeys ("%ep, 1")

Application.SendKeys "{ESCAPE}"



michae...@gmail.com

unread,
Oct 20, 2016, 7:35:31 PM10/20/16
to
NB. I suggest you adjust the waiting time for GNU to suit your computer.Start from slow, say 0.0001 and increase it accordingly. XG starts very slowly though.

BlueDice

unread,
Oct 21, 2016, 7:38:09 AM10/21/16
to
On Friday, October 21, 2016 at 12:35:31 AM UTC+1, michae...@gmail.com wrote:
> NB. I suggest you adjust the waiting time for GNU to suit your computer.Start from slow, say 0.0001 and increase it accordingly. XG starts very slowly though.

re SendKeys("%ep, 1")
I'm guessing that the keystrokes equivalent are [Alt] + Edit>Paste off the excel XP/2003 menu system.
I'm using a later version with the so called 'ribbon' which has replaced the old menu and no sign of any menu shotrcuts as before. Maybe it will still work. Otherwise I'll try [Ctrl]+[V] .. (^V)

gnubg can be opened & loaded with a gnubgid with a single command all under the control of the gnu app as per my OP - no danger of pasting stuff where it's not wanted if the app takes longer than expected to open. This way it does not matter how long it takes or how variable the time to open.

I will try the SendKeys as an experiment with gnu in anticipation of having to use that method when I get XG.
Gnu is versatile due to it's command panel - most things that you do on the GUI can also be done via a gnu command typed into the gnu command box or, better still for programing purposes, via an instruction to open a text file and read & execute a gnu command (as per my OP)
I was hoping that XG has a similar built in XG command method as gnu or something equivalent. Some way of sending commands to XG via the windows command line.
I'll try mailing Xavier with this specific question.

Many Thanks for your help
--
BD

michae...@gmail.com

unread,
Oct 21, 2016, 1:27:48 PM10/21/16
to
On Friday, October 21, 2016 at 1:38:09 PM UTC+2, BlueDice wrote:
>
> I'm guessing that the keystrokes equivalent are [Alt] + Edit>Paste off the excel XP/2003 menu system.
> I'm using a later version with the so called 'ribbon' which has replaced the old menu and no sign of any menu shotrcuts as before. Maybe it will still work. Otherwise I'll try [Ctrl]+[V] .. (^V)

No they are not off the excel menu. They are off the keyboard.The AppActivate command makes the application active waiting for commands either from the mouse or the keyboard. It's the equivalent of the focus command in Visual Basic.

Anyway my experience with programs made on Excel's VBA is that they usually don't work on other computers, because Excel's VBA code itself is neither backward nor forward 100% compatible.Better use the Visual Basic.Neither VB's code is 100% compatible between versions, but once you compile it, everything works on any Windows computer.


BlueDice

unread,
Oct 21, 2016, 4:16:04 PM10/21/16
to
I was referring to the SendKeys arguments
I was assuming that %ep is the keyboard equivalent of pressing keys:
[Alt] + [e] + [p]
Is this correct?
--
BD

michae...@gmail.com

unread,
Oct 22, 2016, 4:40:32 AM10/22/16
to
Yes for GNU no for XG. Because XG does not have the edit paste menu.

BlueDice

unread,
Oct 22, 2016, 6:32:04 AM10/22/16
to
Neither does Gnu! Copy a gnubgid from, say, notepad and then give gnubg the focus. Then try the keystrokes [Alt] + [E] + [P] - nothing happens. If you then select an excel spreadsheet cell and again repeat those key strokes, Bingo! - the paste works. The reason it works I think, is because the keystrokes are excel menu shortcuts, ie: Alt > Edit > Paste.
I think the SendKeys method is effectively taking an edit paste instruction from excel and converting it to gnu speak.
Interesting stuff...
--
BD

michae...@gmail.com

unread,
Oct 22, 2016, 8:25:17 AM10/22/16
to
Correct. You have to release ALT and then press P when you do it manually.
But when you use code it somehow works after you send it the escape key. How's that I have no idea.

michae...@gmail.com

unread,
Oct 22, 2016, 5:58:33 PM10/22/16
to
Out of curiosity I wrote a small standalone program on VB.
You may download it and test from here:
http://www.filedropper.com/asamplepositionforgnu
It works like a charm. Yet the code in question still is:
My.Computer.Keyboard.SendKeys("%ep", True)





mu...@compuplus.net

unread,
Oct 22, 2016, 11:23:27 PM10/22/16
to
On Thursday, October 20, 2016 at 3:59:07 PM UTC-6, BlueDice wrote:

> ie: I'll try the method with gnu - I do not have XG yet
> BTW does anyone know when XG3 is likely to launch?

Some months ago you were asking for XG reviews and trial.

I didn't see any other than my own comments but have you
found any other reviews? Have you been able to try XG
yourself?

How about contributing your own review/comments about XG?

The latest version seems to be 2.19.211.2671.Pre-release
Will that will become XG3?

Are there specific reasons, annunced new features, etc.
for you to be waiting for XG3?

MK



BlueDice

unread,
Oct 23, 2016, 4:08:28 AM10/23/16
to
Thanks Michael, I'll take a look :)
--
BD

BlueDice

unread,
Oct 23, 2016, 6:06:00 AM10/23/16
to
On Saturday, October 22, 2016 at 10:58:33 PM UTC+1, michae...@gmail.com wrote:
I'm using someone else's pc at the minute so I could not run it blind but I would be interested in looking at the code
Thanks again
--
BD

tetraHydro saved my life

unread,
Mar 24, 2023, 7:20:44 AMMar 24
to
thank you for this post BlueDice. Why such a simple solution eluded me for years I will never know. A GreedyGammon update that works with Windows 10 will be uploaded within 48 hours
Reply all
Reply to author
Forward
0 new messages