943,640 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 5914
  • VB.NET RSS
Jun 11th, 2008
0

byref in vb.net

Expand Post »
hey guys.
here is a scenario:

i have a form named frm1 and a variable in it

VB.NET Syntax (Toggle Plain Text)
  1. 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

VB.NET Syntax (Toggle Plain Text)
  1.  
  2. private number as integer
  3.  
  4. Public Sub New(ByRef x as integer)
  5.  
  6. number = x
  7.  
  8. end sub

and from frm1 i create frm2 as follows:

VB.NET Syntax (Toggle Plain Text)
  1.  
  2. public sub createfrm()
  3.  
  4. dim frm as new frm2(x)
  5. frm.showdialogue()
  6.  
  7. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
dan_e6 is offline Offline
26 posts
since Apr 2008
Jun 12th, 2008
0

Re: byref in vb.net

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

VB.NET Syntax (Toggle Plain Text)
  1. Public Shadows Sub ShowDialog(ByRef x As Integer)
  2. MyBase.ShowDialog()
  3. x = 566
  4. End Sub

To Show Form2 In Form1
Declare
Private Number as Integer
VB.NET Syntax (Toggle Plain Text)
  1. Dim NewForm As New Form2
  2. MessageBox.Show(Number)
  3. NewForm.ShowDialog(Number)
  4. MessageBox.Show(Number)
I am using MessageBox to Show before and After calling the ShowDialog
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Jun 12th, 2008
0

Re: byref in vb.net

Declare x as Shared instead of Private
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seoprofessional is offline Offline
18 posts
since May 2008
Jun 12th, 2008
0

Re: byref in vb.net

Declare x as Shared instead of Private
agree
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,138 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Error in line of code
Next Thread in VB.NET Forum Timeline: Syntax error on update database code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC