How to convert this VBScript code to use with JScript in TestComplete? - vbscript

How to convert the following VBScript code to use with JScript in TestComplete? We are trying to invoke the application/.exe using Windows Script Host functions instead of the predefined functions in TestComplete.
strExe = "C:\whatever\myprogram.exe -h1 -d33"
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec(strExe)
strExeOut = objScriptExec.StdOut.ReadAll

Here's the JScript version:
var strExe = "C:\\whatever\\myprogram.exe -h1 -d33";
var objShell = new ActiveXObject("WScript.Shell");
var objScriptExec = objShell.Exec(strExe);
var strExeOut = objScriptExec.StdOut.ReadAll();

I've written a blog article on this. You can find it here: http://blog.dimaj.net/2011/02/howto-start-application-from-jscript-and-specify-start-in-folder-attribute/
Aside from launching an application, I'm also describing how to set the 'start in' option since some application must have that option set.

Related

how to get the file path from button click and print it on textbox VB6

I have a button and a textbox and I want to make the button to open the folder by a default path.
I will give example:
'C:\Folder\...
Dim path as string
path = "C:\Folder\.."
Dim fso
set fso = createobject("Scripting FileSystemObjh)
I tried some method where it only opens the folder but doesn't get the file path so not what I want to do.
And when I select the file and click okay the file path to be printed on the textbox.
Thank you in advance!
If I understand what you need, the following should point you in the right direction. First, select the following Component:
Microsoft Common Dialog Control 6.0 (SP6)
Second, select the following Reference:
Microsoft Scripting Runtime
Third, drop a CommonDialog control onto your form along with the CommandButton and TextBox. Type the following code:
Option Explicit
Private Sub Command1_Click()
Dim fso As FileSystemObject
Dim path As String
path = "c:\temp\"
CommonDialog1.InitDir = path
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*"
CommonDialog1.DefaultExt = "txt"
CommonDialog1.DialogTitle = "Select File"
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
Set fso = New FileSystemObject
'use fso to do whatever you need
End Sub

how to open mutliple files tiled vertically on a dual monitor setup

i have a dual monitor setup. i have been working on 4 excel workbooks simultaneously and it is going to continue for a long time.
i wanted to make a batch file or a vb script file to open the required files and tile them vertically on the monitors. 2 files on one monitor and 2 more on the other.
i found this code
Dim shell
Set shell = CreateObject("Shell.Application")
shell.MinimizeAll
shell.Open "F:\FSA 30-08-15.xlsx"
shell.Open "F:\SMH 09-08-15.xlsx"
shell.Open "F:\MPP 23-08-15.xlsx"
shell.Open "F:\GIP 23-08-15.xlsx"
Wscript.Sleep 1000
shell.TileVertically
but this does not open all files nor does it tile them. it only opens the first file. running the script again opens the 2nd file and so on. but tiling the files doesnt work.
The reason being you are using one shell object to open multiple Excel workbooks. As a result, only one instance of Excel is created and all 4 workbooks are opened in that Excel instance. You might have to update your script so that each workbook open in separate Excel instance and then you can tile them.
Dim shell, objEx
Set shell = CreateObject("Shell.Application")
shell.MinimizeAll
Set objEx = CreateObject("Excel.Application")
objEx.Application.Visible = True
objEx.WorkBooks.Open "C:\Users\pankaj.jaju\Desktop\Work.xlsx"
Set objEx = Nothing
Set objEx = CreateObject("Excel.Application")
objEx.Application.Visible = True
objEx.WorkBooks.Open "C:\Users\pankaj.jaju\Desktop\portfolioIM_20150729_1318.xlsx"
Set objEx = Nothing
Set objEx = CreateObject("Excel.Application")
objEx.Application.Visible = True
objEx.WorkBooks.Open "C:\Users\pankaj.jaju\Desktop\Sample Conditional Formatting.xlsx"
Set objEx = Nothing
Set objEx = CreateObject("Excel.Application")
objEx.Application.Visible = True
objEx.WorkBooks.Open "C:\Users\pankaj.jaju\Desktop\Products.xlsx"
Set objEx = Nothing
Wscript.Sleep 5000
shell.TileVertically
set shell = nothing

REALBasic - Programmatically create controls

i'm tring to create some label programmatically, the code doesn't return any error but i cannot see any label in my window.
dim dr As DatabaseRecord
dim sql As String
sql = "SELECT * FROM pack WHERE applicabilita_modello LIKE '%" + versione + "%'"
dim rs As RecordSet = database.SQLSelect(sql)
dim i As Integer = 1
dim test(10) As Label
while not rs.EOF
test(i) = new Label
test(i).Text = rs.Field("descrizione").StringValue
test(i).Left = me.Left
test(i).Top = me.Top * i
test(i).Enabled = true
test(i).Visible = true
rs.MoveNext
i = i + 1
wend
rs.Close
i've verified that the recordset contain some data, the loop work correctly but no label is shown and cannot understand why.
thanks for any help
There are two ways to create controls at runtime in Real Studio. The first is to create a control array. You could name the control MyLabel and give it an index of zero. Then your code would be:
test(i) = new MyLabel
The second is to use a ContainerControl. This container would contain a label and because you can add them to your window (or other container) using the NEW command and using the ContainerControl.EmbedWithin method.
I generally prefer the ContainerControl approach for many reasons, but mostly because control arrays make the logic a big more convoluted. The only drawback with containers is that it requires Real Studio Professional or Real Studio Enterprise.
http://docs.realsoftware.com/index.php/UsersGuide:Chapter_5:Creating_New_Instances_of_Controls_On_The_Fly
http://docs.realsoftware.com/index.php/ContainerControl

How do I determine the image dimensions of a tiff file?

I have a vbscript script and I need to chew through a directory of .tif files. For each file, I need to determine if the file is proportioned as a landscape or a portrait. Basically, I need to be able to get the image dimensions for each file. So for, I have seen some examples of people reading the file file headers to extract this sort of information from jpg or bmp files. Has anyone done the same thing to extract the dimensions for a tiff file?
In VBScript, you can determine the image dimensions in two ways:
Using the WIA Automation Library (download link, MSDN documentation, an excellent Hey, Scripitng Guy! article on the subject). Once you have the wiaaut.dll library registered, you can use the following simple code:
Set oImage = CreateObject("WIA.ImageFile")
oImage.LoadFile "C:\Images\MyImage.tif"
WScript.Echo "Width: " & oImage.Width & vbNewLine & _
"Height: " & oImage.Height
Using the GetDetailsOf method to read the corresponding extended file properties. This is a native Windows scripting method, so no external libraries are required; but the code is longer:
Const DIMENSIONS = 31
CONST WIDTH = 162
CONST HEIGTH = 164
Set oShell = CreateObject ("Shell.Application")
Set oFolder = oShell.Namespace ("C:\Images")
Set oFile = oFolder.ParseName("MyImage.tif")
strDimensions = oFolder.GetDetailsOf(oFile, DIMENSIONS)
strWidth = oFolder.GetDetailsOf(oFile, WIDTH)
strHeigth = oFolder.GetDetailsOf(oFile, HEIGTH)
WScript.Echo "Dimensions: " & strDimensions & vbNewLine & _
"Width: " & strWidth & vbNewLine & _
"Height: " & strHeigth
This script outputs something like:
Dimensions: 2464 x 3248
Width: 2464 pixels
Height: 3248 pixels
so if you need plain numbers, you'll have to extract them from the returned strings.
There's also another problem with this method - the property indexes (those constants in the beginning on the script) are different in different Windows versions, as I explained in this answer. The above script is for Windows 7, but if you use another Windows versions or if you want the script to work on different Windows versions, you'll need to use version-specific indexes. The most complete list of available property indexes is here.
I would recommend using Atalasoft's DotImage Photo Its powerful & it's free! But, it's a .NET package, so you'll have do some Regasm Magic to make it work. Go check out Use vb.net in VBScript before you get started.
Here is the code you'll need to get the dimensions.
Public Function GetHeight(path As String) As Integer
Using stm As New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim decoder As New TiffDecoder()
If Not decoder.IsValidFormat(stm) Then
Throw New Exception("not a TIFF")
End If
Dim image As AtalaImage = decoder.Read(stm, Nothing)
Return image.Height
' Return image.Width --- To return the Width.
End Using
End Function

Clicking on a link that contains a certain string in VBS

I'm trying to run an automated vbs script that clicks on a link on a page. I have things of the form:
Const READYSTATE_COMPLETE = 4
Set IE = CreateObject("INTERNETEXPLORER.APPLICATION")
IE.Visible = true
IE.navigate ("http://mywebpage.com")
How do I then make it click on a link on that page that doesn't have an ID but is like
ClickMe!
Thanks!
Along the lines of
Dim LinkHref
Dim a
LinkHref = "link"
For Each a In IE.Document.GetElementsByTagName("A")
If LCase(a.GetAttribute("href")) = LCase(LinkHref) Then
a.Click
Exit For ''# to stop after the first hit
End If
Next
Instead of LCase(…) = LCase(…) you could also use StrComp(…, …, vbTextCompare) (see StrComp() on the MSDN).

Resources