Returning a variable from a sub

  • Thread starter Thread starter melisfreed
  • Start date Start date
M

melisfreed

hello there! Is there a way to either return a value from a sub to b
used in another sub OR is there a way to call a value from another sub
My sample code below:

Sub Small()
TestPoint = 100
End Sub

Sub Large()
Dim TestPoint
 
Hi, you can do this by first Publicly declaring your variable
(otherwise a variable will only be know inside the sub

Public TestPoint

Sub Large()
Small 'runs the sub named small
MsgBox TestPoint
End Sub

Sub Small()
TestPoint = 100
End Sub

The other method is passing a variable to another sub with arguments

Sub Small(Testpoint As Long) 'calls the passed variable "Testpoint"
MsgBox(TestPoint)
End Sub

Sub Large()
Small(100) 'pass the value 100 to the sub Small
End Sub

Regards,
ManualMan
http://www.gamesXL.tk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top