Passing as string variable from sub to sub 
Author Message
 Passing as string variable from sub to sub

How do you pass a string variable from one sub to another.

Private Sub Mach1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Mach1.Click

Dim s1path As String = "C:\cncmgr\m1pg\"

End Sub

Private Sub pgmlabel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs, ByVal s1path As String) Handles pgmlabel.Click

ERROR GENERATED

Method 'pgmlabel_Click' cannot handle Event 'Click' because they do not have
the same signature.

I need to pass the variable "s1path"

These subs are in the form design stage.

Thanks for any help



Thu, 14 Jul 2005 13:23:09 GMT  
 Passing as string variable from sub to sub
Hi Armon,

There are a few ways to share data between sub / method calls depending on
what you want to do.

The easiest thing you can do is to define the shared variable in a place
that is in scope to both subs.  Usually you do not want to modify the
parameters that an event handler (such as pgmlabel.Click) is expecting.
E.g.

Dim s1path As String = ""

Private Sub Mach1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Mach1.Click

    s1path = "C:\cncmgr\m1pg\"

End Sub

Private Sub pgmlabel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles pgmlabel.Click

    Dim localpath As String = s1path

End Sub

You could also define the path in a new Module file if you want it to be
available to all forms in the app:

Module Module1

    Public myPath As String = "C:\cncmgr\m1pg\"

End Module

If this does not solve the problem, please tell me a little more about what
you want to do on this form, and how you want each event handler sub to use
the path.

Best,

Paul
Visual Basic .NET

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> How do you pass a string variable from one sub to another.

> Private Sub Mach1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Mach1.Click

> Dim s1path As String = "C:\cncmgr\m1pg\"

> End Sub

> Private Sub pgmlabel_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs, ByVal s1path As String) Handles pgmlabel.Click

> ERROR GENERATED

> Method 'pgmlabel_Click' cannot handle Event 'Click' because they do not
have
> the same signature.

> I need to pass the variable "s1path"

> These subs are in the form design stage.

> Thanks for any help



Sat, 16 Jul 2005 05:45:40 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing a sub name to another sub

2. Calling a sub or function using a variable through another sub or function

3. menus and sub-menus and sub-sub-menus

4. count elements in root, sub root sub-sub root treeview

5. Passing variables from VBA sub to VB scipt

6. Pass a variable to a sub

7. Passing arrays from a server-function/sub to a server -variable

8. Passing ASP variable to Active X sub

9. passing variables from report to a sub report

10. Variable Passing b/n Sub and parent reports, while hiding subreport

11. passing variables to a timer sub

12. Passing 2 variables to a Sub

 

 
Powered by phpBB® Forum Software