Multiple Forms in Console Application - see comments
So, I'm working on a console application in VB.NET that also has 2 forms in it. The problem is, I'm attempting to make a button that shows Form3 when clicked. That works. However, there's a button on Form3 that writes information to a listbox on Form1, which is where I'm having the problem. First, here's a class for a listbox item with tags, which is what I'm using for msgboxes: `Public Class msgboxitem` ` Public style As MsgBoxStyle` ` Public title As String` ` Public Text As String` ` Public name As String` ` Public Overrides Function ToString() As String` ` Return Me.Name` ` End Function` `End Class` Now then, here's the code where that's used: `Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click` ` Dim box As New msgboxitem` ` Me.DialogResult = System.Windows.Forms.DialogResult.OK` ` box.title = TextBox1.Text` ` box.Text = TextBox2.Text` ` box.name = TextBox3.Text` ` If ListBox1.SelectedItem = "AbortRetryIgnore" Then` ` box.style = MsgBoxStyle.AbortRetryIgnore` ` ElseIf ListBox1.SelectedItem = "ApplicationModal" Then` ` box.style = MsgBoxStyle.ApplicationModal` ` ElseIf ListBox1.SelectedItem = "Critical" Then` ` box.style = MsgBoxStyle.Critical` ` ElseIf ListBox1.SelectedItem = "DefaultButton1" Then` ` box.style = MsgBoxStyle.DefaultButton1` ` ElseIf ListBox1.SelectedItem = "DefaultButton2" Then` ` box.style = MsgBoxStyle.DefaultButton2` ` ElseIf ListBox1.SelectedItem = "DefaultButton3" Then` ` box.style = MsgBoxStyle.DefaultButton3` ` ElseIf ListBox1.SelectedItem = "Exclamation" Then` ` box.style = MsgBoxStyle.Exclamation` ` ElseIf ListBox1.SelectedItem = "Information" Then` ` box.style = MsgBoxStyle.Information` ` ElseIf ListBox1.SelectedItem = "MsgBoxHelp" Then` ` box.style = MsgBoxStyle.MsgBoxHelp` ` ElseIf ListBox1.SelectedItem = "MsgBoxRight" Then` ` box.style = MsgBoxStyle.MsgBoxRight` ` ElseIf ListBox1.SelectedItem = "MsgBoxRtlReading" Then` ` box.style = MsgBoxStyle.MsgBoxRtlReading` ` ElseIf ListBox1.SelectedItem = "MsgBoxSetForeground" Then` ` box.style = MsgBoxStyle.MsgBoxSetForeground` ` ElseIf ListBox1.SelectedItem = "OkCancel" Then` ` box.style = MsgBoxStyle.OkCancel` ` ElseIf ListBox1.SelectedItem = "OkOnly" Then` ` box.style = MsgBoxStyle.OkOnly` ` ElseIf ListBox1.SelectedItem = "Question" Then` ` box.style = MsgBoxStyle.Question` ` ElseIf ListBox1.SelectedItem = "RetryCancel" Then` ` box.style = MsgBoxStyle.RetryCancel` ` ElseIf ListBox1.SelectedItem = "SystemModal" Then` ` box.style = MsgBoxStyle.SystemModal` ` ElseIf ListBox1.SelectedItem = "YesNo" Then` ` box.style = MsgBoxStyle.YesNo` ` ElseIf ListBox1.SelectedItem = "YesNoCancel" Then` ` box.style = MsgBoxStyle.YesNoCancel` ` End If` ` Form1.ListBox2.Items.Add(box)` ` Me.Close()` ` End Sub` The problem with the code is `Form1.ListBox2.Items.Add(box)` and the error is `Reference to a non-shared member requires an object reference.` It is saying that Form1 is a non-shared member, which I don't get why, because I don't have this error on Forms Applications, only on console applications. I'm not exactly what to change though. Anyone got any suggestions? Dim f As New Form1 didn't work, because there's only one form1 being used. I can not have the user open up another one.
I don't remember if you do programming or not, but, @hba
Did you try making them firends? http://msdn.microsoft.com/en-us/library/vstudio/08w05ey2.aspx http://msdn.microsoft.com/en-us/library/76453kax.aspx
I'm not sure how to change a modifier of a form. I didn't see that in the properties window, or anywhere else.
And `Friend Class Form3` just causes more problems.
Kk.. Hmm...
And you looked at Microsoft's vast explanation of the error? http://msdn.microsoft.com/en-us/library/zwwhc0d0%28v=vs.90%29.aspx
This has an example: http://social.msdn.microsoft.com/Forums/en-US/d15623e1-de37-4c96-97de-28ff5f10e846/reference-to-a-nonshared-member-requires-an-object-reference?forum=vbide So they say the same basic thing, it needs to be objectified.
Oops, didn't see that you replied. Let me check the explanation.
I found one other. All are very short and I did not do enough VB to really remember all the ins and outs. http://stackoverflow.com/questions/13462479/reference-to-a-non-shared-member-requires-an-object-reference-occurs-when-callin
I've seen that. However, I'm using 2010 (even though not much has changed) and their explanation isn't too helpful.
Yah. MS tends to have great examples if they have them, but some iffy explanations.
Oops. Modules aren't consoles, are they?
Not sure... OH, and I saw a big set of articles on compiler design earlier.... made me think of your project. Heh.
This site had some info I found handy when I took vb.net: http://www.dotnetperls.com/console-write-vbnet
Join our real-time social learning platform and learn together with your friends!