Hi All & Brian,
I have a doubt regarding declaring a variable in one macro script and then using the variable's value defined by the end user in the first macro in the second macro. To give you more perspective this is the code i am working on:
Macro 1:
Option Explicit
Global sFilename As String
( The variable sFilename then will contain the name of the database selected by the user, it was taken from your field mapping script template )
Macro 2:
Sub Main
Call TopNExtraction() 'sFilename is the variable database name
client.RefreshFileExplorer
Call ExportDatabaseXLSX() 'KPI 1.IMD
End Sub
' Data: Top Records Extraction
Function TopNExtraction
Set db = Client.OpenDatabase(sFilename) ' I get get an error code here, saying the database was not found or is in use.
Set task = db.TopRecordsExtraction
Dim dbName As String ' Made an addition while using sFilename as a variable
task.IncludeAllFields
task.AddKey "CREDIT", "A"
dbName = "KPI 1.IMD"
task.OutputFileName = dbName
task.NumberOfRecordsToExtract = 30
task.CreateVirtualDatabase = False
task.PerformTask
Set task = Nothing
Set db = Nothing
Client.OpenDatabase (dbName)
End Function
--------------
My end goal is that the after the user selects the database and maps the neccesary fields in the dialogue box, the 2nd Macro which has the actual analysis to be run, then selects that database from the variable defined in the 1st Macro i.e. sFilename.Please help me here, i am stuck.
rahulsaxena3
Offline
Last seen: 2 years 7 months ago
Joined: 01/09/2018 - 14:02
How many variables will you be transferring between the scripts. Calling a script from a script you can send four variables, if it is greater than that then you need to create a text file to hold the variables and script two would read the text file to populate the variables.
Hi Brian,
Firstly, thanks for replying !
It would be more than 4 variables, can you please show me an example of how to create that text file and then how to call it in the 2nd script ?
What would i need write exactly in that text file. p
Here are two example files for you. The first one, the Send Variable writes the variables to a text file and then calls the second script and sends the name of the text file. The second file gets the text file name and then loads in the variables. I have attached both files for you.
Example Macro to Send Variables.iss
Example Macro to Send Variables.iss
Thank you so mcuh Brian, let me try and use this, will take a few days but i will surely get back to you. Thnk you for taking out time and answering my questions