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

Accessing a Procedure

Status
Not open for further replies.

JaeBrett

Programmer
May 5, 2003
196
CN
This sounds like such a dumb and easy question but there's no mention of it anywhere.

How can I access a procedure from another procedure? I'm used to doing it in Java. :)
 
If you declare the function as Public rather that Private it should have scope throughout your application.

Public Sub Mod_DoSomething()
End Sub

good luck,
KCI
 
Just to add to KCI, once its Public just use the CALL within your code

Call Mod_DoSomething



 
Or just...
Mod_DoSomething
By itself

Basic handles Functions and Subs pretty much the same way, except Functions return a value...

A sub is like a void function in C and Java

With the following 2 procedures:

Public Sub MySub(X as integer, Y as Integer)
...
End Sub

Public Function MyFunction(X as Integer, Y as Integer) As Integer
...
End Sub


You can call them like this...

With Parentheses...
Call MySub(X, Y)
Z = MyFunction(X, Y)


Or without...
MySub X, Y
MyFunction X, Y


*Note: If you call a sub with parentheses, you MUST use CALL (as shown above)
On the flip side, If you want a function to return a value, you must Use Parentheses...

You Can also Call them like so...
MySub X, MyFunction(A, B)

As far as calling from other procedures, that is a matter of scope...

Any Sub/Function can call any other Sub/Function within the same module, no matter what...

If you need to call it from a different module, use Public
Public Sub MySub(X as integer, Y as Integer)
...
End Sub


If don't want it to be called from any other module, use Private
Private Sub MySub(X as integer, Y as Integer)
...
End Sub


Good Luck,
--Josh--

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top