hey all,

I have a class, called myClass.vb. I have a sub in it.
this sub has a string variable, which has got some value. Now, i want this value to be transferred to the button_click event of a very seperate form called myForm.vb.

how can this be done?

Thanks in anticipation.

Recommended Answers

All 3 Replies

At least two ways to do this:
1. Declare a public variable pubStr as String in Module, pass the string value in the sub of your MyClass.vb to pubStr. Then the pubStr is available anywhere with your project;
2. Dim a public variable in your MyClass.vb (pubStr as String), pass the string value to pusStr. In MyForm:
Dim myCls As New MyClass
myCls.pubStr will return the string value to you.

I did the same as second option but its not working!!
my code is like:

MyClass.vb

Public Class MyClass
    Public sendVal As String = ""
   
     Public Sub kaise()
        Dim mystring As String = "some value"
        sendVal = mystring
    End Sub
End Class

MyForm.vb

Public Class MyForm

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim obj As New MyClass
        Dim show As String
        show = obj.sendVal
        MessageBox.Show(show.ToString())
    End Sub

End Class

Simply, How can I take my private variable in the sub routine and make it Public for another function to get a hold of it?
Thanks

At least two ways to do this:
1. Declare a public variable pubStr as String in Module, pass the string value in the sub of your MyClass.vb to pubStr. Then the pubStr is available anywhere with your project;
2. Dim a public variable in your MyClass.vb (pubStr as String), pass the string value to pusStr. In MyForm:
Dim myCls As New MyClass
myCls.pubStr will return the string value to you.

Public Class MyForm     
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        
      Dim obj As New MyClass        
      Dim show As String
      obj.kaise 'pass value to sendVal        
      show = obj.sendVal        
      MessageBox.Show(show.ToString())    
End Sub End
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.