mrdance Posted November 24, 2003 Posted November 24, 2003 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 Quote
Administrators PlausiblyDamp Posted November 24, 2003 Administrators Posted November 24, 2003 You would need to pass the form in as a parameter to the function as well. Public Sub addstatus(ByVal msg As String, f as frmChatMain) f.ListBox1.Items.Add(Now & " " & msg) End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mrdance Posted November 24, 2003 Author Posted November 24, 2003 ok, so there is no way to access the form without passing the parameter in? Quote
Leaders dynamic_sysop Posted November 24, 2003 Leaders Posted November 24, 2003 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 Quote
mrdance Posted November 24, 2003 Author Posted November 24, 2003 Nice solution! Thank you! Is there any disadvantages of using this method? Quote
Leaders dynamic_sysop Posted November 24, 2003 Leaders Posted November 24, 2003 not really no , just remember not to dispose of the " f " , because then you will have to re-initialize it :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.