Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a sub in a module:

 

Public Sub addstatus(ByVal msg As String)

frmChatMain.ListBox1.Items.Add(Now & " " & msg)

End Sub

 

But I can't access frmChatMain which is the name of the main window. How can I do that?

 

thanks / Henrik

  • Leaders
Posted

in your Module ...

Module Module1
   Public f As Form1 '/// must be initialized , but that will happen in the form's load event.

   Public Sub addstatus()
       f.ListBox1.Items.Add("some stuff")
   End Sub

End Module

in your Form ...

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       f = DirectCast(Me, Form1) '/// initialize the form " f " when loading your main form.
   End Sub

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       addstatus() '/// test to see if addstatus adds an item to this form's listbox.
   End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...