byref in vb.net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 26
Reputation: dan_e6 is an unknown quantity at this point 
Solved Threads: 0
dan_e6 dan_e6 is offline Offline
Light Poster

byref in vb.net

 
0
  #1
Jun 11th, 2008
hey guys.
here is a scenario:

i have a form named frm1 and a variable in it

  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

  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 513
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 89
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: byref in vb.net

 
0
  #2
Jun 12th, 2008
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

  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
  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
KSG
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 18
Reputation: seoprofessional is an unknown quantity at this point 
Solved Threads: 0
seoprofessional seoprofessional is offline Offline
Newbie Poster

Re: byref in vb.net

 
0
  #3
Jun 12th, 2008
Declare x as Shared instead of Private
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: byref in vb.net

 
0
  #4
Jun 12th, 2008
Originally Posted by seoprofessional View Post
Declare x as Shared instead of Private
agree
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC