hey guys.
here is a scenario:

i have a form named frm1 and a variable in it

private x as integer = 0

and another form called frm2 that needs to be able to make a local copy of "x" from frm1 and any changes made to "x" on frm2 needs to be changed on frm1.

so in frm2 i do

private number as integer 

Public Sub New(ByRef x as integer)

number = x

end sub

and from frm1 i create frm2 as follows:

public sub createfrm()

dim frm as new frm2(x)
frm.showdialogue()

end sub

and now any changes made to 'number' inside frm2 should change 'x' in frm1 shouldnt it? this does work if you're using a textbox object since the project im working in does exactly that. but when i try and do it for a variable like single/string/integer it doesnt work. it changes the local variable on frm2 but not the variable on frm1.

Hi,
I think Single, Integer, Double Char all are ValueType, So It is not working. Also you can override the ShowDialog() and pass your value

For Example In Form2

Public Shadows Sub ShowDialog(ByRef x As Integer)
        MyBase.ShowDialog()
        x = 566
    End Sub

To Show Form2 In Form1
Declare Private Number as Integer

Dim NewForm As New Form2
   MessageBox.Show(Number)
   NewForm.ShowDialog(Number)
   MessageBox.Show(Number)

I am using MessageBox to Show before and After calling the ShowDialog

This article has been dead for over six months. Start a new discussion instead.