Skip to main content

Experimenting with Visio and VBScript


This diagram is created:




















 
 
 
 
 
 
 
using this code:

















































 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Copy the code:

Option Explicit

Dim strVSDPath, filesys
Dim vsoApplication, vsoDocument, vsoPages, vsoPage
Dim vsoMaster1, vsoMaster2, vsoStencil
Dim vsoShape1, vsoShape2, vsoConnector1
Dim itr

Const visAutoConnectDirDown = 2     'Connect down.
Const visAutoConnectDirLeft = 3     'Connect to the left.
Const visAutoConnectDirNone = 0     'Connect without relocating the shapes.
Const visAutoConnectDirRight = 4     'Connect to the right.
Const visAutoConnectDirUp = 1         'Connect up.

' Visio file to be created.
strVSDPath = "D:\Workspace_Visio\TestRunFlow.vsd"

'delete any previously existing Suite file
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(strVSDPath) Then
    filesys.DeleteFile strVSDPath
End If
Set filesys = Nothing

' Bind to Visio object.
On Error Resume Next
'Set vsoApplication = CreateObject("Visio.Application")
Set vsoApplication = CreateObject("Visio.InvisibleApp")

If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Visio application not found."
    Wscript.Quit
End If
On Error GoTo 0


Set vsoDocument = vsoApplication.Documents.Add("Basic Diagram.vst")
Set vsoPages = vsoDocument.Pages
Set vsoPage = vsoPages.Item(1)
Set vsoStencil = vsoApplication.Documents("Basic Shapes.vss")

Set vsoMaster1 = vsoStencil.Masters("Rectangle")
'Set vsoMaster2 = vsoStencil.Masters("Rectangle")

Set vsoShape1 = vsoPage.Drop(vsoMaster1, 3.5, 7)
vsoShape1.Text = "Shape 1"
For itr = 2 to 3   
    Set vsoShape2 = vsoPage.Drop(vsoMaster1, 3.5, 5.5 + (itr - 1)*2)
   
    vsoShape2.Text = "Shape " & itr

    vsoShape1.AutoConnect vsoShape2, visAutoConnectDirDown
   
    Set vsoShape1 = vsoShape2
    Set vsoShape2 = Nothing
Next

vsoDocument.SaveAs strVSDPath
vsoDocument.Close

vsoApplication.Quit


'Set vsoApplication = Nothing
Set vsoShape1 = Nothing
Set vsoShape2 = Nothing
Set vsoConnector1 = Nothing

Set vsoMaster2 = Nothing
Set vsoMaster1 = Nothing
Set vsoStencil = Nothing
Set vsoPage = Nothing
Set vsoPages = Nothing
Set vsoDocument = Nothing
Set vsoApplication = Nothing

Wscript.Echo "Done"

Comments

Popular posts from this blog

Microsoft Test Manager – FUEL for test automation

(this is a follow-up post to this one:  http://sudiptopaul.blogspot.com/2011/12/using-aspnet-page-state-and-theme-to.html ) Traditionally Test Management and Test Automation tools have been remotely related to each other. Microsoft’s Test Manager changes this - Manual Testers contribute effectively by creating action recordings for each test Common portions of test steps can now be grouped into what is called as Shared Steps – again manual tester can create independent action recordings for these Test Manager enables these action recordings to serve as active inputs to test automation – separate class is created for each test case, and a reusable function for each shared step This is very elegant as it saves the test automation engineer an amount of time required to refactor common portions of longish test path recordings The Manual Tester gets to contribute in the Keyword definition phase – an important thing to do, because they are the subject matter experts! Here’...

QTP – search sub-folders for existence of QTP scripts

  Suppose we want to report on all subfolders in a specific root folder that contain script files. Consider the example folder structure here – ODBC_MYSQL, ODBC_SQLEXPRESS and Test1 are the folders that have QTP scripts: Here’s a VBScript program that takes the root (start) folder as input, and iterates all subfolders recursively to report on the ones that are actual QTP script folders: Note: This program can be run directly as a VBScript program, or from within a QTP script by toggling the comment between lines 17 and 18. (p.s.: if Print statement does not work on specific version of QTP, use the Msgbox statement. For real world test automation projects, do not use either – to avoid human intervention!) On running the program, Folders across various levels (Level 2, 3) get reported!