Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

All right, I have two forms in a VB .NET project. The first form (form1) is the main menu. When a utton is clicked it opens another form. On the other form I am capturing data that was placed in text boxes into an array. Now how do I access that array in the first form??? This is the code for what I got so far:

 

*button click on main form*

Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click

Dim x As New input()

x.Show()

End Sub

 

*loading the array*

Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click

Dim buffer(11) As Long

buffer(0) = box1.Text

buffer(1) = box2.Text

buffer(2) = box3.Text

buffer(3) = box4.Text

buffer(4) = box5.Text

buffer(5) = box6.Text

buffer(6) = box7.Text

buffer(7) = box8.Text

buffer(8) = box9.Text

buffer(9) = box10.Text

buffer(10) = box11.Text

buffer(11) = box12.Text

Me.Close()

End Sub

 

Any help would be greatly appreciated!

Posted
When you load the second form pass a reference to the main form to it. You can do this by overloading the form's New constructer.

 

Excuse my ignorance, but how would one do this? Thank you.

Dodge

Grab Life By The Horns

Posted
I have tto agree with Dodge, I don't know what you mean. Could you explain a little further? Or, perhaps an example?
Posted
I hate to sound stupid, but I am still not seeing it. I looked at your stuff and tried it, but then it would break and point to the NEW thing inside microsoft stuff i.e. the windows form designer generated code. This is starting to frustrate me......I think I am going to toss me computer out the window.
  • *Gurus*
Posted

The following code overloads the form's constructer so we can pass an instance of the other form to it. Keep in mind this code is located in the form that we want to display. It takes the argument it receives and stores it in a class variable.

Public Sub New([b]ByRef frm As Form[/b])
    MyBase.New()

    [b]frmReference = frm[/b]

    '...
End Sub

Now, when we want to create an instance of that form we use the following code snippet. Keep in mind this code passes a reference of the primary form to the form that's about to be displayed.

Dim f As New Form2([b]Me[/b])
f.ShowDialog()

Posted

I appologize for my denseness... I added the code as you instructed. In my little demo project to help me understand this and get this concept down, I have a radio button on form1 which when selected sets the public variable "SandwichHam" to 1, and then shows the form2. On form2, I added the code as you instructed. I then added the follow:

If frm.SandwichHam =1 Then 
TextBox1.Text = "You ordered ham."
End If

 

However, it throws an exception ("An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe

 

Additional information: Object reference not set to an instance of an object.").

 

I am sure that this is something simple, but apparently still too complicated for my simple mind :rolleyes: :rolleyes: :-\

 

Thanks again!

Dodge

Grab Life By The Horns

  • 2 years later...
Posted

Same Problem

 

Is it possible to do this in Visual C++ .net? I tried the Walkthrough on the MSDN library but it completely ruined my program. I am simply trying to pass the data collected from the TextBox in my Dialog back to the main Form.

 

Please forgive my ignorance, I'm a newbie with Visual C++ & .net.

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...