ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sub parameter passing (https://www.excelbanter.com/excel-programming/416221-sub-parameter-passing.html)

miek

Sub parameter passing
 
Is this the proper way to pass a varible parameter to and back from
subroutines?
My code seems a little sloppy, I would think that I'm missing some
delclaration

The subroutine "Orig_WS_name" is call with the following statement:
Call Sub Orig_WS_name("orig_name")

Private Sub Orig_WS_name(WSIn As String)
'WSIn has the value of "orig_name") prior to call
Call Add_WSname_Chars(WSIn)
'WSIn has the value of "orig_name-textadded") after call
End Sub

Private Sub Add_WSname_Chars(WS_name As String)
WS_name = WS_name & "-txt added"
End Sub

Bob Phillips

Sub parameter passing
 
If you want to pass the changed value back up, declare the argument Byref
(the default). If youy want it passed back in its original state, declare it
Byval.


Call Orig_WS_name("orig_name")

Private Sub Orig_WS_name(ByVal WSIn As String)
MsgBox WSIn
Call Add_WSname_Chars(WSIn)
MsgBox WSIn
End Sub

Private Sub Add_WSname_Chars(ByRef WS_name As String)
WS_name = WS_name & "-txt added"
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"miek" wrote in message
...
Is this the proper way to pass a varible parameter to and back from
subroutines?
My code seems a little sloppy, I would think that I'm missing some
delclaration

The subroutine "Orig_WS_name" is call with the following statement:
Call Sub Orig_WS_name("orig_name")

Private Sub Orig_WS_name(WSIn As String)
'WSIn has the value of "orig_name") prior to call
Call Add_WSname_Chars(WSIn)
'WSIn has the value of "orig_name-textadded") after call
End Sub

Private Sub Add_WSname_Chars(WS_name As String)
WS_name = WS_name & "-txt added"
End Sub




miek

Sub parameter passing
 
Thanks for your help, it is much apprecated

"Bob Phillips" wrote:

If you want to pass the changed value back up, declare the argument Byref
(the default). If youy want it passed back in its original state, declare it
Byval.


Call Orig_WS_name("orig_name")

Private Sub Orig_WS_name(ByVal WSIn As String)
MsgBox WSIn
Call Add_WSname_Chars(WSIn)
MsgBox WSIn
End Sub

Private Sub Add_WSname_Chars(ByRef WS_name As String)
WS_name = WS_name & "-txt added"
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"miek" wrote in message
...
Is this the proper way to pass a varible parameter to and back from
subroutines?
My code seems a little sloppy, I would think that I'm missing some
delclaration

The subroutine "Orig_WS_name" is call with the following statement:
Call Sub Orig_WS_name("orig_name")

Private Sub Orig_WS_name(WSIn As String)
'WSIn has the value of "orig_name") prior to call
Call Add_WSname_Chars(WSIn)
'WSIn has the value of "orig_name-textadded") after call
End Sub

Private Sub Add_WSname_Chars(WS_name As String)
WS_name = WS_name & "-txt added"
End Sub






All times are GMT +1. The time now is 01:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com