LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Cannot pass argument from control to sub and back

There are 2 ways to pass a variable. One is byref and the other is byval.
ByVal passes a copy of the variable to the sub and so any changes to the
variable are lost when the sub ends. By ref passes the acual variable so any
changes to the variable are kept in the calling procedure after the called
procedure ends.

While global variables can be handy be very judisious in their useage. They
are a pain to debug because if at any point the value is wrong it can be very
difficult to know which procedure modified it last...
--
HTH...

Jim Thomlinson


"Revolvr" wrote:

I'm at a loss here...

I have code associated with controls on a worksheet, which call
subroutines in other modules, and I am passing an argument, a string,
indicating the success or failure of the operations in that
subroutine. Then the string gets appended to a TextBox. But I am not
able to pass the string argument.

In Sheet1 I have
Private Sub dothings_Click()
'Dim smsg As String

Call messagetest(smsg)
€˜ Here if I check the value of smsg, it is empty.
NewMsg1 (smsg) €˜ writes to a text box

End Sub

The subroutine messagetest is in another module. Messagetest sets the
smsg string to a value, however when returning the value becomes an
empty string.

Sub messagetest(smsg As String)
smsg = "message test set this string"
End Sub

If this sub is in the same module as the sheet code, it works. I have
tried declaring smsg as public, but still doesn't work. I've tried
passign byval, still doesn't work.

Why is this and is it possible to pass arguments between code
associated with a worksheet, and modules?


Thanks!



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass control back to Excel window [email protected] Excel Worksheet Functions 1 December 29th 06 07:24 PM
Pass function as argument to UDF Ron Rosenfeld Excel Programming 10 February 9th 06 12:48 PM
Pass Argument? Hal[_4_] Excel Programming 1 December 5th 05 05:19 PM
can a userform pass an argument? smokiibear Excel Programming 12 December 8th 04 02:14 AM
pass argument to macro tommy Excel Programming 4 September 1st 04 06:21 PM


All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"