Passing arguments in gosub routines

  • Thread starter Thread starter nath
  • Start date Start date
N

nath

Hello,

Is it possible to pass arguments to routines that you are
calling with a gosub statement.

i.e. gosub table_modify (32)

table_modify(x as integer)

width = x*2

return

The above is an example not what i am trying to achieve.
 
Hi Nath,

Didn't realise this anachronism was still around. Looking at the help, it
would appear not as it goes to a subroutine within a sub procedure, not to a
sub procedure.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
GoSub is for calling subroutines within subroutines, and you cannot pass
arguments. There's no need to since you can define variables within the
Sub.


Public Sub Test()
Dim x As Long
Dim width As Long
x = 32
GoSub table_modify
MsgBox "x: " & x & vbNewLine & "width: " & width
Exit Sub
table_modify:
width = x * 2
Return
End Sub

OTOH, most modern programming eschews GoSubs for separate routines:


Public Sub Test1()
Dim x As Long
Dim w As Long
x = 32
w = Table_modify(x)
MsgBox "x: " & x & vbNewLine & "width: " & w
End Sub


Public Function Table_modify(x As Long) As Long
Table_modify = x * 2
End Function
 

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