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

calling sub from other modules

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
pardon my tremendous ignorance, i know im probably the dummest programmer here, ive only been working with VB for about a month or so, but i just wanted to know whats the proper syntax to call a sub from another module, i know im not going to get it right lol, how bout refering to another sub in another module from another workbook, thanks!
 
If you want to call a sub from another module you have to first define the sub you want to call as "Public", because otherwise it will be invisible to the calling routine.

After you've done that you can call the sub just by name if you want - but it might be better at the moment if you use the
Code:
Call
keyword beforehand so that when you look at the code afterwards it's clear what you did.

Try to make sure that your subs have different names, ie that there's not another sub of the same name in a different module. That being the case you can call the sub by putting it's name on one line. If no arguments are required (ie when you've written the sub that you want to call, nothing appears in between the brackets in the subroutine definition) then you need add nothing else. If you deo have to supply arguments in your call, put them in brackets after the sub name.

You can add the module name followed by a full stop before the macro name just to make things crystal clear for audit purposes.

So, the macro you want to call is "Greenflash", it's in the module "Dunlop":
Code:
Public Sub Greenflash(player_name as string)
select case player_name
    case "Heskey", "Andy Cole", "Ashley Ward"
          msgbox player_name & " is a pranny, they wear Greenflash"
    case else
          msgbox player_name & " is OK, tehy pass the Greenflash test"
    end select
end sub

So in your other module (player_assess) you want to make a call to this macro, and you want to use the argument "Andy Cole")

The code you'd need would be:

Code:
Call Dunlop.Greenflash("Andy Cole")


and that's it really.

** No star for this, please, it's book work.
 
LOL LOL LOL
"pranny" ??? Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top