July 31, 2008

Extract Filename and Folder from Path

Filed under: Scripting — Marcus Tettmar @ 1:34 pm

Here’s a quick way to extract just the filename from a full path:

Let>file_path=C:\Program files\Skype\Phone\Skype.exe

//get the file name on its own
Separate>file_path,\,parts
Let>exe_name=parts_%parts_count%

//now get just the folder path
MidStr>file_path,1,{length(%file_path%)-length(%exe_name%)},folder_only

This uses Separate to explode the path into an array using the ‘\’ character as the delimiter. We’ve called the array “parts”. “parts_count” contains the number of elements created. So parts_%parts_count% is the last element, which happens to be the filename.

Now, if we want just the folder path, use MidStr to extract length of file_path minus length of exe_name.

NB: For some reason the curly brackets in the last line of code above are causing the text to output on the next line. That should all be one line. Click on “view plain” to see the raw code if you want to copy it to Macro Scheduler.

July 24, 2008

Quoting Quotes

Filed under: Scripting — Marcus Tettmar @ 1:44 pm

VBScript and Complex Expressions use the ” (double quote) character to delimit strings. Native MacroScript code doesn’t need delimited strings. But if you need to use Complex Expressions or VBScript you need to remember that strings must be delimited in quotes.

One implication of this is that if the string already has a ” character within it you will get a syntax error, because the parser thinks this marks the end of the string.

To avoid this you need to add another quote, and you can use StringReplace to replace any occurences of the ” character with a second one before passing the string to VBScript or a Complex Expression:

//example input string:
Let>mystring=your name is "Sally"

//Double quote before using string in complex expression
StringReplace>mystring,","",mystring_2
If>{%mystring_2% <> ""}
  //Do something
Endif

Without that StringReplace call to double quote the quote characters, the complex If line would produce a syntax error.

The same goes for VBScript:

//example input string:
Let>mystring=your name is "Sally"

VBSTART
VBEND

StringReplace>mystring,","",mystring_2
VBEval>MsgBox("%mystring_2%"),nul

Note that the VBEval statement evaluates a pure VBScript expression. Since VBScript strings must be in quotes we surround the variable mystring_2 with them, and need to use % symbols to tell Macro Scheduler to use the value of mystring_2. See my last post for tips on when and where to use % symbols.

On a similar note, CR LF pairs (Carriage Return and Line Feed) in strings passed to VBScript will produce errors since they are hard line breaks and cause string termination problems. We can avoid this by replacing the real CR and LF characters with the VBScript placeholders:

StringReplace>myString,CRLF," & vbCRLF & ",myString

The quotes terminate and start the string again, splitting it where the CRLF was, and replacing the hard CRLF with the VBScript vbCRLF variable. There’s also vbCR and vbLF variables for carriage returns (CR) and line feeds (LF) on their own.

July 4, 2008

Using Variables and When to use Percent Symbols (%variable%)

Filed under: Scripting — Marcus Tettmar @ 9:38 am

By default in Macro Scheduler you do not have to do anything special to refer to a variable. The following will create a variable called Name:

Let>Name=Freddy

Name is now assigned the value of Freddy.

Referring to Variables:

The following will display a message box containing the word “Freddy”:

MessageModal>Name

Macro Scheduler knows that Name is a variable and finds its value. You do not need to tell it that Name is a variable. If Name did not exist as a variable the message box would simply display the word “Name”.

If you prefer you can tell Macro Scheduler that Name is a variable like so:

MessageModal>%Name%

But, by default (see below to see how to change this behaviour), there’s really no need since Name appears on its own.

However, supposing you wanted a message box that said “My Name is Freddy” and you wanted to use the variable “Name”. In this case you need to tell Macro Scheduler that Name is a variable, like so:

MessageModal>My Name is %Name%

Hopefully the reason is clear. If we did not put % symbols around the second “Name” the message box would simply display “My Name is Name”. Equally if Macro Scheduler tried to interpret every word as a variable we’d end up with “My Freddy is Freddy”.

Rule of thumb: % symbols really only need to be used when a variable appears within another string. When used on their own they are not needed.

Creating/Modifying Variables:

% symbols mean find the value of this variable. So when creating or modifying variables do not use them. E.g., the following assigns the value Freddy to the variable “Name”

Let>Name=Freddy

If you were to include Name in % symbols then you’d be saying “Assign Freddy to the value of Name”. This could get confusing. Consider the following code:

Let>Name=Sally
Let>%Name%=Freddy

Here we’d end up with two variables, one called Name assigned the value of Sally, and another called Sally assigned the value of Freddy. Now this can be quite powerful and there may be times you want to do this, but for most of us, it is usually not what we want.

Rule of thumb: Do not use % symbols when assigning to variables. This includes variables returned by other commands as well as variables on the left of the equals sign in Let commands.

There’s an interesting forum topic on this subject here.

Exceptions:

One time we DO want to use % symbols on the left side of a Let command is when we are creating/modifying array type variables and we are using an array counter. E.g.:

Let>x=0
Repeat>x
  Let>x=x+1
  Random>9,var
  Let>Array[%x%]=var
Until>x=10

Here x is the loop counter. We are creating an array of 10 random values. In this case we want the value of x inside the array name and end up with variables Array[1], Array[2], Array[3], …. Array[10]. This is one case where we want a variable inside a variable.

Explicit Variable Resolution:

Real programmers prefer to tell the programming language when a value is a literal and when it is a variable, and as you get more advanced you may find the need to do that. You can tell Macro Scheduler to only resolve variables that are contained in % symbols and leave everything else as literals by setting VAREXPLICIT to 1:

Let>VAREXPLICIT=1

With this setting the following code will display the word “Name” in the message box:

Let>VAREXPLICIT=1
Let>Name=Fred
MessageModal>Name

Unlike before where we’d see “Fred” in the message box. Now to see the value of the Name variable we’d have to do:

MessageModal>%Name%

Note that when assigning to variables the variable name still appears on its own. Nothing changes in regards to creating or assigning to variables; only when referring to their values. The rules above still apply.

For more information see the following topics in the help file:
* User Defined Variables
* Explicit Variable Resolution
* Ignoring Spaces

May 23, 2008

Macro Scheduler 10.1.15 is 40 Times Faster!

Filed under: Announcements,Automation,Scripting — Marcus Tettmar @ 8:08 am

With the latest release (10.1.15) we worked on optimizing the way variables are stored internally and were able to dramatically improve performance. Dick Lockey did some tests and writes that the latest version is 40 times faster than earlier versions!

If you’re working with scripts that create and process a large number of variables – say a script which reads and processes a large number of fields from a database – you’ll want to make sure you’re using the latest release, because your scripts will be noticeably faster with this version.

Macro Scheduler History

May 7, 2008

Attaching to an existing Internet Explorer instance

Filed under: Automation,Scripting — Marcus Tettmar @ 9:57 am

There are various scripts on the forums demonstrating how to automate Internet Explorer via VBScript and IE’s Document Object Model. Such as this one: Automate web forms with IE

These require that the script creates the Internet Explorer instance via a CreateObject call. The script then has access to the IE object and can access its methods and properties in order to automate navigation, clicking on links, filling forms and extracting data from the page, etc.

A question that has come up a few times is “How do I connect to an already running copy of IE, one that the script didn’t start?”. This is what the GetObject function is designed for, but Internet Explorer doesn’t support it.

Well I recently discovered a solution. The following script has a subroutine called GetIE which will find a running copy of IE and set the global IE object variable to that copy. This can then be used in other functions to control that copy of IE:

VBSTART

Dim IE

'Attaches to an existing instance of IE with matching URL
Sub GetIE(URL)
  Dim objInstances, objIE
  Set objInstances = CreateObject("Shell.Application").windows
  If objInstances.Count > 0 Then '/// make sure we have instances open.
    For Each objIE In objInstances
	  If InStr(objIE.LocationURL,URL) > 0 then
	    Set IE = objIE
	  End if
    Next
  End if
End Sub

'fills a form field and optionally submits form
Sub WebFormFill(fieldname,fieldvalue,submit)
  Dim FormNr
  Dim ItemNr
  Dim TheForm

  if IE.Document.All.Tags("FORM").Length = 0 then
    MsgBox("No form found in page")
  else
    for FormNr = 0 to IE.Document.Forms.Length - 1
      Set TheForm = IE.Document.Forms(FormNr)
      for ItemNr = 0 to TheForm.Elements.Length - 1
        if TheForm.Elements(ItemNr).Name = fieldname then
          TheForm.Elements(ItemNr).Value = fieldvalue
          If submit=1 then
            TheForm.submit
          end if
          exit for
        end if
      next
    next
  end if
End Sub

'Navigates IE to specified URL
Sub Navigate(URL)
  IE.Navigate URL
  do while IE.Busy
  loop
End Sub

'clicks specified link
Sub ClickLink(linktext)
  Dim anchors
  Dim ItemNr

  Set anchors = IE.document.getElementsbyTagname("a")
  For ItemNr = 0 to anchors.length - 1
    If anchors.Item(ItemNr).innertext = linktext Then
	  anchors.Item(ItemNr).click
	End If
  next

  do while IE.Busy
  loop
End Sub

'This function extracts text from a specific tag by name and index
'e.g. TABLE,0 (1st Table element) or P,1 (2nd Paragraph element)
'set all to 1 to extract all HTML, 0 for only inside text without HTML
Function ExtractTag(TagName,Num,all)
  dim t
  set t = IE.document.getElementsbyTagname(Tagname)
  if all=1 then
    ExtractTag = t.Item(Num).outerHTML
  else
    ExtractTag = t.Item(Num).innerText
  end if
End Function

VBEND

//Find existing IE window
VBRun>GetIE,www.google.com

//enter search query and submit
VBRun>WebFormFill,q,windows macro,1

//Click a link
VBRun>ClickLink,Advanced Search

//extract
VBEval>ExtractTag("td",5,0),tagText
MessageModal>tagText

The implementation of GetIE shown here accepts a string. GetIE then looks for a copy of IE whose location URL contains that string. So it allows you to find a copy of IE based on the URL it is currently at.

This example attaches to a copy of IE currently open at www.google.com. So to run this example first open IE and go to www.google.com. Then run the script and it will enter a search term, click the Advanced Search link and then extract some text from a TD tag.

April 28, 2008

Converting Office VBA to VBScript

Filed under: Scripting — Marcus Tettmar @ 1:20 pm

If you have macros in Microsoft Word, Excel or Access they will be written in VBA – Visual Basic for Applications. If you wish to use this code inside Macro Scheduler you can convert this code to VBScript. However you cannot just copy the code and paste it into Macro Scheduler – or even into a VBScript file – and expect it to work, because there are some key differences:

  1. Objects belonging to the application are automatically exposed to VBA in that application, but don’t exist outside of it.
  2. VBA supports “Named Argument Syntax”. VBScript does not.
  3. Named Constants are automatically defined in the container application but meaningless outside of it.

So, let’s deal with each of these in turn and look at what we need to do about them.

Application Objects, Methods and Properties

Objects belonging to the container application – e.g. Excel – are automatically exposed to VBA within that application. All objects belonging to Excel can be used directly by VBA and your VBA can refer to them directly without having to create them. But outside of Excel these objects do not exist, so the code will fail – Macro Scheduler/VBScript doesn’t know what they are. You need to create them. This is done with the CreateObject command. At the very least you will need to create the “root” object which is usually the .Application object:

Set ExcelApp = CreateObject("Excel.Application")

Now you can refer to objects and properties belonging to Excel by proceeding them with the object variable:

ExcelApp.Visible = true
ExcelApp.Workbooks.Open("d:\example.xls")
ExcelApp.Workbooks.Worksheets("Sheet2").Activate

If you record a simple macro in Excel which enters some values into some cells you might see code like the following created:

Range("E4").Select
ActiveCell.FormulaR1C1 = "fred"

This code is clearly relative to the active sheet. It doesn’t specify which sheet should be used. And the Sheet object is clearly automatically exposed. To do the above outside of Excel we’d need to reference the correct Sheet object, which belongs to a Workbook object, which of course belongs to the Excel application object. So you could do:

ExcelApp.ActiveWorkbook.Sheets("Sheet1").Range("E4").FormulaR1C1 = "fred"

But you might split things up a bit with:

Set ExcelApp = CreateObject("Excel.Application")
Set MyBook = ExcelApp.Workbooks.Open("d:\example.xls")
Set MySheet = MyBook.Worksheets("Sheet1")

MySheet.Range("E4").Value = "Harry"

Note that the first three lines create references to the Application, Workbook and Worksheet objects. It’s then easier to refer directly to the objects, properties and methods belonging to each of those objects.

So where in a VBA macro inside Excel you may just see Range(“E4″).Value=”1234” consider what the Range object belongs to and remember you need to create a reference to that object, and then prefix it with the name you give to that object reference.

Each Office application includes a Visual Basic reference in the help system. In there you can see how all the objects refer to each other. E.g. if you find the help topic for the Range object you will see that it belongs to the Worksheets object.

Named Argument Syntax

VBA supports something called “Named Argument Syntax” in function calls (ArgName:=ArgValue). E.g. record a macro to sort a column in Excel and you will see something like this in the generated code:

ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("F4:F1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= xlSortNormal

Note Key:=Range(… and SortOn:=xlSortOnValues etc. The benefit of this system is that if a function accepts lots of optional parameters but you only need to set a few of them and leave the rest to their default values, you specify just the arguments you want to include.

However, VBScript does not support this system and instead requires all the function parameter values only in the order in which they are declared. So the above would look like this in VBScript:

MySheet.Sort.SortFields.Add MySheet.Range(F4:F1048576"), xlSortOnValues, xlAscending, xlSortNormal

As mentioned, Named Argument Syntax means that not all the parameters need to be passed to the method and because they are named can be passed in any order. So when converting to VBScript be sure to view the help for the function and find out what parameters it expects and in what order.

Named Constants

Named constants that belong to the application will also mean nothing to Macro Scheduler/VBScript. Inside of the application they belong to they are exposed to VBA. They mean something to VBA inside of the application. But take the code outside of the application and the names are meaningless.

For example the code above uses three named constants: xlSortOnValues, xlAscending and xlSortNormal. As these are declared automatically within Excel they mean something to VBA. Outside of VBA, in VBScript/Macro Scheduler they will cause errors because they are undeclared.

We need to declare these:

xlSortOnValues = 0
xlAscending = 1
xlSortNormal = 0

I know what you’re thinking – how do I know that xlSortOnValues equals 0, xlAscending is 1 and xlSortNormal is 0? Well, you could look them up. But I don’t bother doing that. I use the VBA debugger. Open up the Visual Basic Editor and hit CTRL+G to open up the “Immediate” pane – it may already be visible. Inside the “Immediate” pane type:

?xlSortOnValues

And press Enter. You’ll see the value of xlSortOnValues appear on the next line. Handy eh?

Conclusion

The key thing to remember is that your Office VBA is referring to objects that exist only within the application in question. Your Excel code can say just Range(“E5”) because it knows what a Range object is. Macro Scheduler has no idea what “Range” is unless you tell it. Once you understand that you need to create references to these objects, and look at the VBA help to understand the hierarchy of objects, the process of porting your code to VBScript should begin to make more sense.

You’ll find an example script that controls Excel with VBScript installed with Macro Scheduler. This post contains similar code. You’ll also find lots of examples in the forums. Hint: try searching for “CreateObject”.

April 16, 2008

Retrieve Entire Excel Sheet Using DBQuery

Filed under: Scripting — Marcus Tettmar @ 9:00 am

UPDATE: 25/09/2012 – Macro Scheduler now includes some native Excel functions (XLOpen, XLGetCell, XLSetCell) etc. DDE is also no longer supported in the latest version of Excel. Using DBQuery, as described here, is still a very useful way to retrieve Excel data, especially for doing SQL style lookups.

Last July I wrote this post summarising three different ways Macro Scheduler can read/modify Excel data including using DDE to quickly retrieve/modify cells, and VBScript to script pretty much anything in Excel. Example scripts demonstrating both methods, and an example.xls file ship with Macro Scheduler.

Well, now with the native database functions there’s another way. DBConnect can connect to Excel and treat it as a database, using one of the following connection strings:

OLE DB:
Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\myfolder\workbook.xls; Extended Properties=”Excel 8.0; HDR=No;”

ODBC:
Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=c:\myfolder\workbook.xls;

Either should work if you have Excel installed. Note that HDR=No in the first connection string tells ConnectDB to retrieve the first row. Without it the first row is treated as column names and not retrieved. This is not supported in the second method. See Microsoft KB257819 for more info and other options.

So the following code will retrieve the entire contents of Sheet1 into an array:

Let>connStr=Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%SCRIPT_DIR%\example.xls;Extended Properties="Excel 8.0;Hdr=No;"
DBConnect>connStr,dbH

Let>SQL=select * from [Sheet1$]
DBQuery>dbH,SQL,rsSheet1,nR,nF

DBClose>dbH

This reads everything in Sheet1 from example.xls which is stored in the same folder as the macro (SCRIPT_DIR). Just modify the path in the Data Source= part of the connection string to point to a different workbook.

The entire sheet is now in the rsSheet1 array. nR contains the number of rows and nF the number of columns (records and fields). So rsSheet1 looks like:

rsSheet1_1_1 .. nsSheet_1_nF
..
rsSheet1_nR_1 .. nsSheet_nR_nF

A nice quick way of sucking an entire worksheet into a MacroScript array.

Note that you have to use [Sheetname$] as the table name. According to Microsoft you can also use named ranges, or unnamed ranges:

Named Range:

    SELECT * FROM MyRange

Unnamed Range:

    SELECT * FROM [Sheet1$A1:B10]

To insert/modify data you first need to name the columns in your worksheet. You can then do something like:

    INSERT INTO [Sheet1$]([First Name], [Last Name]) VALUES (‘John’, ‘Smith’)

Where “First Name” and “Last Name” are names given to columns. The data will be added at the first blank row.

See also:
Using Macro Scheduler’s Database Functions
Methods for Accessing Excel Data

Update: Here’s a connection string for Excel 2007:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%SCRIPT_DIR%\example.xlsx;Extended Properties="Excel 12.0 Xml;HDR=Yes";

April 15, 2008

Using Macro Scheduler’s Database Functions

Filed under: Automation,Scripting — Marcus Tettmar @ 10:38 am

Macro Scheduler 10.1 includes four functions for connecting to databases, querying and modifying data:

  • DBConnect
  • DBQuery
  • DBExec
  • DBClose

Connecting to a Database

Before you can connect to a database you’ll need to make sure you have the required OLE DB/ODBC drivers installed. You can see what drivers are already installed under Control Panel > Administrative Tools > Data Sources (ODBC). If you have Microsoft Office installed you’ll already have the standard Microsoft ones for Microsoft Access, Excel, dBase, Paradox etc. You may also already have the driver for Microsoft SQL Server installed.

If you want to connect to a third party database such as Oracle, Sybase, MySQL etc, then you may need to install the required drivers. Although if your computer is running other software which already accesses these databases, you probably already have the drivers installed. If not, visit your provider’s web site to find the required drivers, or dig out those install disks, or contact your system/database administrator!

DBConnect is used to create a connection to a database. It requires an ADO, OLE DB, or ODBC Connection String, and returns a handle to the database, which is used in the other database functions.

What is a Connection String?

A Connection String is just a string containing database connection information, telling Macro Scheduler how to connect to the database in question. The string contains a number of arguments and values separated by semicolons:

argument1=value1; argument2=value2;

What these arguments and values should be depends on the database you are using and the method of connection. More on that in a moment.

It is possible to create DSN (Data Source Name) connections in your Control Panel. All this does really is help you build a connection string and store it in your registry. Then the Connection String in DBConnect just has to be the DSN name you defined in Control Panel. While this method makes it easier to create the connection, it is obviously less portable. If you want to use this method to create a system DSN go to Control Panel > Administrative Tools > Data Sources (ODBC). You can then choose from the installed providers and the dialogs will ask for the connection information needed.

How do I Construct a Connection String?

The correct answer is to read the documentation for the database you want to connect to! But as people have been using connection strings to connect to databases since I still had a full head of hair, the web abounds with useful information. Google is your friend. Look what comes up top with this Google Search:

Position 1: http://www.connectionstrings.com

Why, some web site called nothing other than connectionstrings.com, created by some kind soul who clearly read your mind.

Click on the database type you want to connect to and you’ll be shown everything you need. For example, if you want to connect to Microsoft SQL Server you’d probably need:

Driver={SQL Server}; Server=myServerAddress; Database=myDataBase; Uid=myUsername; Pwd=myPassword;

You’ll note there are other options depending on what kind of security is required and how the server is configured and so on. In most cases the basic string is probably all you need, but if in doubt, or if it fails to work, contact your database administrator. Yes, contact your database administrator, not me. Seriously. Whoever set your database up will have more of a clue than I.

So, anyway, let’s put the above into a DBConnect call in Macro Scheduler. We’d do something like:

Let>connstr=Driver={SQL Server}; Server=myServerAddress; Database=myDataBase; Uid=myUsername; Pwd=myPassword;
DBConnect>connstr,dbH

Obviously, you’ll need to repace myServerAddress with the name or address of the server, myDataBase with the name of the database, myUsername with a valid username with permissions to do whatever you plan to do with database, and myPassword with your password.

Want to connect to a different type of database? First, make sure you have the right ODBC/OLE DB drivers installed. Second, read the documentation and if possible speak to your database administrator (if that’s not you!) and if still unsure try Googling “Connection Strings”.

Security Issues

Your administrator may have locked down the port that the ODBC driver connects through. Make sure your IP address can connect through that port. Some database servers require the database user to have special privileges to be able to connect remotely. Again, these are all things for your system administrator to help you with. You don’t have a system administrator? You’re the one who sets it all up? Well, I guess you’ll have to read the docs again then. Sorry 🙂

Retrieving Data

To retrieve data from the database we use the DBQuery command. This accepts a valid SQL statement which returns a recordset, e.g. a SELECT statement. Now, I am not going to try to teach SQL here. There are heaps of resources out there that do that already. A quick Google search reveals this tutorial. Also, most databases provide utilities which help you build queries graphically and chuck out the SQL for you.

The most basic SELECT statement is: “SELECT * FROM TABLENAME”, e.g.:

SELECT * FROM CUSTOMERS

Which just says “select all records from the CUSTOMERS table”.

As well as a SQL statement DBQuery needs a database reference returned by our previous DBConnect call, so that it knows which database you want to perform the SELECT on. We also give DBQuery an array variable to store the returned data in, a variable to store the number of records returned and a variable to store the number of fields per record. So:

Let>SQL=SELECT * FROM CUSTOMERS
DBQuery>dbH,SQL,rsCustomers,numRecs,numFields

Here, rsCustomers is the array in which the data should be stored. The array takes the format:

rsCustomers_RECNUM_FIELDNUM

So, let’s say the above DBQuery returns a recordset containing two records, each with three fields, we’d end up with:

rsCustomers_1_1
rsCustomers_1_2
rsCustomers_1_3
rsCustomers_2_1
rsCustomers_2_2
rsCustomers_2_3

numRecs tells us the number of records returned and numFields tells us how many fields there are.

We could loop through every field with:

Let>r=0
Repeat>r
  Let>r=r+1
  Let>f=0
  Repeat>f
    Let>f=f+1
    Let>this_field=rsCustomers_%r%_%f%
    Message>this_field
  Until>f=numFields
Until>r=numRecs

Modifying Data

To perform any SQL statement that does not return data use the DBExec command. E.g. DBExec can be used for a DELETE, INSERT or UPDATE query. DBExec again takes a database reference returned by DBConnect, the SQL statement, and returns the number of rows affected:

Let>SQL=DELETE FROM CUSTOMERS WHERE CUSTID=1532
DBExec>dbH,SQL,rowsAffected

In this example rowsAffected will contain the number of rows that were deleted.

If it doesn’t work it could be that your lovely database administrator may not have given you DELETE privileges. He’s probably worried you’re going to try something like this:

Let>SQL=DELETE * FROM CUSTOMERS
DBExec>dbH,SQL,rowsAffected

Closing the Database

Just as you shouldn’t leave doors open after you, you really ought to close any connection to the database also. Do this with DBClose which just wants the database reference returned by DBConnect:

DBClose>dbH

And that’s pretty much it.

April 3, 2008

How to use Include

Filed under: Scripting — Marcus Tettmar @ 6:57 am

Dick Lockey has written a nice example in Scripts ‘n Tips showing a good use of the Include statement. Include allows you to include other scripts in your code. A good use of this is to keep commonly used subroutines, VBScript code, or dialogs in scripts that you can then Include in your macros, rather than duplicating the code across all the macros that use it. If you ever need to fix or modify this code you then only need to do it once. It also makes your main scripts smaller and easier to read.

Dick’s example provides a function for validating dialog field lengths. Useful in itself.

Read the example here.

March 21, 2008

Round-up of Learning Resources

Filed under: Automation,Scripting — Marcus Tettmar @ 10:00 am

Common questions we receive are things like “What’s the best way to learn more about Macro Scheduler?”, or “How can I advance my Macro Scheduler skills?”. You may be just getting started, or you may be wondering whether you can improve one of your scripts or how to tackle another process. There are a number of resources available.

Scripting Windows for Beginners

I recommend that new users start by reading the “Scripting Windows for Beginners” guide in the help file. This runs through a simple process of automating Windows Notepad. It only takes a few minutes but it introduces the key concepts of automating with Macro Scheduler. All the commands you learn in that tutorial will be needed in almost any other automation process. So do take the time to work through it.

How to Start Writing an Automation Script

Another useful resource for those just getting started is this article. I believe that if you know the process you are automating, and use some good old paper and a pen to jot down each key send and note down titles of windows as they appear, and any other timings/events that are important, you’ll be half way to creating your script. Read the article to learn more.

Getting more Advanced

The software comes with a number of example scripts showing how to get text from the screen, how to use screen image recognition to find and click on objects, how to read data from Excel, how to simulate user input, etc. Look at these examples and try to understand how they work. You’ll also find examples in the forums.

Articles on Specific Topics

Working with databases
Working with Excel
Screen Image Recognition
Text Capture

Some of these have downloads and videos with them. Browse/Search the Blog for more articles. There’s also the FAQs and other Support Resources. I’m adding articles all the time to the blog, so keep an eye on it and/or subscribe to the RSS feed, or subscribe by email. If there is something you’d like me to write about which hasn’t yet been covered, please let me know.

Search for Solutions

Search the forums here
Search the blog articles at the top right of any blog page.

Or search the entire site with Google: http://www.mjtnet.com/search.htm

Learning on the Job

Everyone learns differently. I prefer to learn by doing. There are usually no rights or wrongs in software automation. The right solution is the one that works and the one that you are comfortable with. So for anyone tackling a particular automation scenario for the first time I say just get stuck in. Break the process down to chunks and tackle one chunk at a time. If you’re unsure about anything ask in the forums, email us, or give us a call. But don’t be worried about having a go.

One on One Consultations

If you’re the sort of person who would prefer some one on one tuition, no problem. We can arrange a desktop sharing session. I’m not a believer in too many contrived “hello world” type learning examples and since one person’s automation scenario can vary so wildly from someone else’s I don’t believe it’s possible to create a generic course. Instead I think it’s far better to look at your specific task and discuss how we might go about automating it. Most people find that after picking our brains for a few minutes they have what they need to get the job done. We can show you a few ideas and run through some of the code if needed. And more often than not this gets people going in the right direction to finish the task off.

« Newer PostsOlder Posts »