Detect and copy multiple entries in a single field?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Detect and copy multiple entries in a single field?

Post by RNIB » Tue Jan 11, 2011 12:12 pm

Following from an earlier thread I'm stuck at the final hurdle.

We have a database that contains records of every book that we record in audio (for reasons that are too complicated to go into we can't query the database directly and so have to simply copy and paste data from fields from it's front end) and some of this data we need to paste into the metadata of our recordings.

One such piece of data is the name of the actor that narrated the book but there are a couple of problems here. The name is stored in the database as surname, forename and I need to enter it as forename surname. Thanks to someone on here I've solved this problem with a piece of vbscript but some books are narrated by more than one actor and I need to copy both names inserting a comma and space between them.

This is my code so far:
// Sets Narrator
//Meta Data is the window I'm pasting the data into
SetFocus>Meta Data
WaitWindowOpen>Meta Data
Press Down * 3
Press Enter
WaitWindowOpen>Edit meta "ncc:narrator"
Wait>1
//Recording Management System is our database of books
SetFocus>Recording Management System - [View/Amend Title]
WaitWindowOpen>Recording Management System - [View/Amend Title]
Wait>1
//Navigates to the field in the database containing the narrators names
Press Tab * 29
Wait>1
WaitClipBoard
Press Ctrl
Send>c
Wait>1
Release Ctrl
//Goto the Restructure subroutine
GoSub>Narrator_Name_Restructure
SetFocus>Edit meta "ncc:narrator"
WaitWindowOpen>Edit meta "ncc:narrator"
Wait>1
Press Ctrl
Send>v
Release Ctrl
Wait>1
Press Enter
WaitWindowClosed>Edit meta "ncc:narrator"
Wait>2
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
MessageModal>Complete! %CRLF% %CRLF%Please verify that the Meta Data is correct before you build the book.


SRT>Narrator_Name_Restructure
VBSTART
VBEND

//example here:
//Let>name=COOPER, Mandy

//Get the copied name from the clipboard
GetClipBoard>name

Let>comma=,
Separate>name,comma,parts

Let>firstname={lower(%parts_2%)}
Let>surname={lower(%parts_1%)}

VBEval>Trim("%firstname%"),firstname
VBEval>Trim("%surname%"),surname

Let>firstname={upper(copy(%firstname%,1,1)) + copy(%firstname%,2,length(%firstname%))}
Let>surname={upper(copy(%surname%,1,1)) + copy(%surname%,2,length(%surname%))}

Let>fullname=%firstname% %surname%
//MessageModal>fullname

//Put the restructured name back onto the clipboard for pasting
PutClipBoard>fullname
END>Narrator_Name_Restructure
This works perfectly for a single narrator however if there are more than one narrators in that field it only copies the first one.

In the narrators field in Recording Management System (RMS) if more than one narrator read a book their names are listed under each other and can be selected by pressing the down arrow. As the number of narrators will vary from book to book the only way I could think of doing it would be to copy the first narrator as per the script above, then perform a down arrow to move to the next narrator on the list if there is one and copy again. Then it should compare the new name with the old one and if they are the same it should stop, if they are different it should switch back to Meta Data, enter a comma and a space and then paste in the new name before switching back to RMS and checking if there is a 3rd name etc etc. Trouble is, I can't figure out how to write it. I know I need to store the name in GetClipBoard>name but don't know to stop that from being overwritten when it gets the 2nd name nor if there is a second name to compare the 3rd name to that and not back to the first name again. I'm also not too sure on the best way of getting it to run this function x times as it's not really a loop because the number will be different for every book so it seems that it needs to know how many names there are before it does anything else :?: :?: :?:

Basically I've confused the hell out of myself, anyone know how to achieve this?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Jan 11, 2011 12:31 pm

Is the front end you are using a compiled desktop application or does it run inside a browser?

If it's a compiled desktop app, I would try to use GetControlText> to get at the data directly.

If it is a browser based app, I would start to try parsing the HTML output directly.

You are starting to encounter problems with navigating a GUI which make this method unreliable and difficult.

You say you cannot query the database directly, but rather than beat your head against the GUI problems wall, If it were me, I would try harder to make the queries option work.

What database backend is being used?

RNIB
Macro Veteran
Posts: 198
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Post by RNIB » Tue Jan 11, 2011 12:39 pm

The front end is a compiled desktop application which connects to an SQL server but we are not allowed to directly query the database because our I.T. department won't/can't provide us with the permissions to do so. This is partly due to security reasons, partly technical but mostly 'political' in that the database is no longer officially supported as it's being ported over to a new system but that's going to be at least 2 years before we receive it....don't ask it's a long and painful story :lol:

I'll look into GetControlText> (not used that before)

Cheers

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