Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameters into a Macro 2

Status
Not open for further replies.

johnoha

IS-IT--Management
Mar 9, 2007
8
NL
Hello

Is it possible to pass parameters into a macro from a batch file (.bat) I would like to be able to pass strings such as catalog names, folder names etc. to reduce the number of macros that I need to maintain as these items are currently hard coded within each macro.

Thanks

 
John,
I don't believe that is possible.
A workround would be a .csv file containing all macro names and the appropriate parameters, and then have a routine in each macro that parses this file to read in the appropriate values.
lex

soi la, soi carré
 
John,

INI files work great. You can use the same macro to execute many things. I automate all my transformer builds and build multiple cubes from one macro. The ini file contains all the information you would need to accomplish this task. To answer your original question, yes you can pass parameters to a CognosScript Macro. When you call a macro put the parameter after the macro name, for example:

whatever.mcx buildcubeX

Inside the macro you can read the parameter as Command. Command will be the parameter. I'm not sure how it works with multiple params but with one it works great. The ini file is still the best way to control multiple versions with one macro and very little hard coding.
 
CC,
Thanks for correcting me; I learn something new each day.

It would appear that 'Command' will hold all text subsequent to the .mac/.mcx call, so all one needs to do is determine a consistent delimiter between parameters.

lex

soi la, soi carré
 
Thanks guys, I managed to perform a test and it works great..

sub main
Dim lsCommand As String
lsCommand=Command$
cmdlen = Len(lsCommand)
if cmdlen = 0 then
MsgBox "cmdlen=0; Exiting"
Exit sub
End if
MsgBox(lsCommand)
End Sub
Here is the format that should be used to pass the command line:

C:\"d:\program files\cognos\cer3\bin\runmac32.exe" c:\test.mcx hello

I would like to see an example of an INI file, if you could post that.

 
I have only one section in my INI file below, but you can have many many sections in the INI file and even utilize multiple INI files. This example only has one INI file and one section, but I think you will get the idea. This is one way of doing things, which has worked for me.

contents of example.ini file located in C:\Program Files\cognos\cer3

[Strings]
String1="Hello "
String2="World"
String3="!"

example.mac:

Declare Function INIValue(INIFile as string, INIApp as string, INIKey as string) as string

Declare Function apiGetPrivateProfileString lib "kernel32" _
Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Integer, _
ByVal lpFileName As String) as long

Option Explicit

Global gs_INILocation as String

Sub Main

Dim ls_String1 as String
Dim ls_String2 as String
Dim ls_String3 as String

gs_INILocation = "C:\Program Files\Cognos\cer3\example.ini"

ls_String1 = INIValue(gs_INILocation, "Strings", "String1")
ls_String2 = INIValue(gs_INILocation, "Strings", "String2")
ls_String3 = INIValue(gs_INILocation, "Strings", "String3")

msgbox(ls_String1 & ls_String2 & ls_String3)

End Sub

Function INIValue (INIFile as string, INIApp as string, INIKey as string) as string

dim INIBuffer as string*255
dim INIValueLength%

INIBuffer = ""
INIValueLength% = apiGetPrivateProfileString(INIApp, INIKey, " ", INIBuffer, 255, INIFile)
INIValue = Left$(INIBuffer,INIValueLength%)

End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top