Skip to main content

Call a script within a script

Hi all,
I have created several scripts, one for each test. Now I want to run all of these scripts (or only some of them). My idea is to create a new script (maybe with option fields) from where I could start the other scripts. Is that possible?
Thank you,
Ole

Brian Element Tue, 01/28/2014 - 11:42

Hi Ole and welcome to the site.  Yes it is, you can have up to 4 parameters that you can pass between scripts.  I will try and put together an example for you to look at.  It has been awhile since I have done this so give me a few days to refresh my memory and do an example for you.

Ole Wed, 01/29/2014 - 03:25

Hi Brian,
thanks for the quick answer. I will wait.

Brian Element Wed, 01/29/2014 - 07:32

Hello Ole,

Here is an example for you. The first script has a menu with 3 buttons, the first button sends 4 character variables to a second script which displays the characters, the second button does the same but with integers and the third button asks for your name and then the second script will display your name. You will notice that in the third example even though we are only sending one variable we have to use "" for the other three variables.

The receiving scripts obtain these variables through the arg1, arg2, arg3 and arg4 variables. In this example I am just displaying them but in a more complex script you can take these variables and then work with them. Unfortunately there is only 4 variables that you can send at a time. If you need more you probably need to write the variables to a text file from the first script and then open the text file in the second script to obtain the variables.

The example scripts, once complete, will open the menu script again.  You will notice that  the function is different.  The function used in the example scripts to return to the main script cannot send variables, it simply open the script.

Let me know if this answers your question or if you need more info on this.

I have attached the script that I used so you can play with them.

Good luck.

Brian

'*****************************************************************************************
'* Script :		CallAScriptMenu.iss
'* Author:	Brian Element
'* Date: 		Jan 29, 2013
'* Purpose:	Example of hot to call other scripts and return to the original script
'*****************************************************************************************
Begin Dialog NewDialog 21,20,201,179,"Calling Scripts Demo", .NewDialog
  PushButton 19,13,40,14, "Call Script 1", .PushButton1
  PushButton 20,41,40,14, "Call Script 2", .PushButton2
  Text 25,71,77,11, "Enter your Name:", .Text1
  TextBox 24,86,81,14, .TextBox1
  PushButton 27,109,40,14, "Call Script 3", .PushButton3
  OKButton 34,136,40,14, "OK", .OKButton1
  CancelButton 99,136,40,14, "Cancel", .CancelButton1
  Text 72,15,108,14, "This will pass the variables a, b, c and d.", .Text2
  Text 70,43,112,14, "This will pass the variable 1, 2, 3 and 4.", .Text3
End Dialog
Option Explicit

Sub Main

	'seeting up the variables to be used.
	Dim dlg As NewDialog
	Dim iButton As Integer
	Dim sName As String
	Dim sChar1 As String
	Dim sChar2 As String
	Dim sChar3 As String
	Dim sChar4 As String
	Dim iNum1 As Integer
	Dim iNum2 As Integer
	Dim iNum3 As Integer
	Dim iNum4 As Integer
	
	iButton = Dialog(dlg)
	
	Select Case iButton
		Case 1
			'This will send 4 characters to the file
			sChar1 = "a"
			sChar2 = "b"
			sChar3 = "c"
			sChar4 = "d"
			Client.RunIDEAScriptEX "CallAScriptExample1.iss", sChar1, sChar2, sChar3, schar4
		Case 2
			'This will send 4 integers to the file
			iNum1 = "1"
			iNum2 = "2"
			iNum3 = "3"
			iNum4 = "4"
			Client.RunIDEAScriptEX "CallAScriptExample2.iss", iNum1, iNum2, iNum3, iNum4
		Case 3
			'Even if you are only passing one variable you have to send blanks for the variables not being used.
			sName = dlg.TextBox1
			Client.RunIDEAScriptEX "CallAScriptExample3.iss", sName, "", "", ""
		
		
	End Select
End Sub

'*****************************************************************************************
'* Script :		CallAScriptExample1.iss
'* Author:	Brian Element
'* Date: 		Jan 29, 2013
'* Purpose:	Example of hot to call other scripts and return to the original script
'*****************************************************************************************

Sub Main
	MsgBox arg1
	MsgBox arg2
	MsgBox arg3
	MsgBox arg4
	Client.RunIDEAScript  "CallAScriptMenu.iss"

End Sub

'*****************************************************************************************
'* Script :		CallAScriptExample2.iss
'* Author:	Brian Element
'* Date: 		Jan 29, 2013
'* Purpose:	Example of hot to call other scripts and return to the original script
'*****************************************************************************************

Sub Main
	MsgBox arg1
	MsgBox arg2
	MsgBox arg3
	MsgBox arg4
	Client.RunIDEAScript  "CallAScriptMenu.iss"

End Sub

'*****************************************************************************************
'* Script :		CallAScriptExample3.iss
'* Author:	Brian Element
'* Date: 		Jan 29, 2013
'* Purpose:	Example of hot to call other scripts and return to the original script
'*****************************************************************************************

Sub Main
	MsgBox "Your name is: " & arg1
	Client.RunIDEAScript  "CallAScriptMenu.iss"

End Sub

 

timado83 Sat, 02/13/2016 - 20:03

In reply to by Brian Element

Hi Brian,
Thank you so much for putting up this example. It is exactly what I am looking for. I have dowloaded your sample script and tried to run it however it said "Invalid macro filename". I am not sure if I have to copy the submacro to a specific folder in IDEA? 
Many thanks,
 
 

Brian Element Sun, 02/14/2016 - 07:15

In reply to by timado83

Hi and welcome to the site.

Yes, the scripts have to be in the project folder, if you put them in the macros.ilb folder you will get this error.  To use them in the macros folder you will have to add the location of the script.

Brian

Ole Thu, 01/30/2014 - 04:43

Yes, that's what I wanted to know. Thank you very much. Yesterday I watched your tutorial and it was great. I thought IDEAscript is just a small uncomfortably "language" but your tutorial showed me that I was wrong. Well done!
Ole

Brian Element Thu, 01/30/2014 - 05:40

Hi Ole,

Glad I could help and glad you enjoyed the videos.  IDEAScript is actually a very powerful language once you learn it but like anything else it takes time to learn how to use it.  Let me know if you have any subjects you want me to explain or cover in the future.  I am always looking for topics that could help users out.

Brian

oseroke Mon, 09/25/2017 - 09:33

Hello Brian,
A s a follow up to this thread, is it possible to pass an array as one of the four variables? I am trying it and currently facing issues.
 
Thanks.

Brian Element Mon, 09/25/2017 - 09:51

In reply to by oseroke

Hi Oseroke,

Sorry you can't pass an array.  If you have more than four variables to pass you probably need to create a text file, save the information in the text file and then read it from the other script.

Brian