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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling a macro from within a macro

Status
Not open for further replies.

corchat

Technical User
Jan 4, 2005
3
0
0
NL
Hi,

I'm trying to build a macro library for impromptu but I can't call the module in the external file.

could somebody give me a hint about what I'm doing wrong.
this is the code i'm using for the main macro

declare sub ctrl_pad
BasicLib "D:\Cornelis\Documenten\Impromptu\macros\Opslaanals.mcx" alias "ctrl_pad" (pad as string)

sub main
dim pad as string
pad="c:\test"
call ctrl_pad(pad)

end sub

and this is the corresponding part of the library

option explicit
sub ctrl_pad(pad)
dim tstdir
tstdir= dir (pad,16)
if tstdir="" then
mkdir(pad)
end if
end sub

I've also tried (of course without the Rem)
rem '$Include:'D:\Cornelis\Documenten\Impromptu\Test\test.SBH'
this worked fine for a msgbox but refused to create the folder

Thanks a lot
Cornelis
 
The $Include always works fine for me. I usually make my library function (rather than sub procedure) based, and use the return value to tell me if it was successful.

That said, you do not declare the library procedure with the main procedure, but rather from within the included library header. It may be a matter of form rather than function though. Anyway, try this code:

Code:
option explicit

'$INCLUDE "C:\library1.sbh"
sub main
 dim messtxt$
 dim x$
 dim padx$

 padx$="c:\test"
 x$= ctrl_pad(padx$)

 if x$ = "1" THEN
   messtxt$ = "Directory Exists"
 else
   messtxt$ = "Directory Created"    
 end if

 Msgbox messtxt

end sub

and the corresponding library file (C:\library1.sbh noted above)
Code:
declare FUNCTION ctrl_pad(pad$) 

FUNCTION ctrl_pad(pad$) 
  dim tstdir$
  tstdir$= dir(pad,16)
  if tstdir$="" then
    mkdir(pad$)
    ctrl_pad = "0"
  else
    ctrl_pad = "1"   
  end if
end FUNCTION

This works for me fine and demonstrates the concept.

Regards,

Dave Griffin






The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
Want good answers? Read FAQ401-2487 first!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top