-1

Is there anyone with very good knowledge in vb.net. I am working on my final semester project. I need to pass objects between forms. I have my codes of two forms here. http://pastebin.com/xP1LdL3t

http://pastebin.com/fpuY98NT To connect to the irc server i am using irc.Connect() function. It is perfectly working on my channel form and it is to be called only when users want to connect or on form load. When i double click the online user list a private message form opens. And i am unable to send irc.sendraw command and that form has not called irc.Connect(). It is not supposed to be called in every form. What i want is to use the channel's connection status on other forms so that irc.sendraw command will work. If i have failed to explain properly please let me know.

2 Answers2

0

It's not clear what you mean by "pass references". There are several ways to communicate between forms. Here are a few:

  1. Declare public variables or properties in one form to be accessed by other forms. If you do this, be sure you are using the proper instance of the form containing the public variables. If you refer to one of these variables before that form is loaded, you'll end up with two instances of the form and things will get confusing.

  2. Use a public method, similar to (1)

  3. Declare global variables in a separate module, to be accessed by any form in the project. (Some people consider this bad manners.)

  4. Pass parameters to and from the forms.

  5. Raise an event to be handled in another form.

xpda
  • 15,585
  • 8
  • 51
  • 82
0

basically, If you want to pass through function in Form 1 to function in Form 2 you can do somthing like this:

Public Class Form1

   Dim x As Integer = 2 

   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Form2.fun(x)
       Form2.Show() ' it's optional 
   End Sub

End Class

and in Form 2 you just get the value as ref:

Public Class Form2

   Dim y As Integer 'the variable to get the value of x

   Public Sub fun(ByRef x As Integer)
      y = x 
   End Sub

 End Class

Hope it can help you, and it's what you wanted.

zb22
  • 3,126
  • 3
  • 19
  • 34