Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to find a way to pass Variables from Form to Form....

So I do this:

 

       Dim frmPetZoom As New frmPetZoom("CUSTOMER", strCustCode)

       frmPetZoom.ShowDialog(Me) '-- This is Modal

       '-- Get Chosen Value Back
       txtCustNo.Text = strCustCode

 

frmPetZoom looks like this:

 

Public Sub New(ByVal strCategory As String, ByRef strReturnVar As String)
       MyBase.New()
.
.
.

 

Now how do I Change the Reference from strReturnVar to something Global? Or is my Approach waayyyy off?

Any input would be Appreciated :-\

 

Thanx

Burning

Posted

Thanx, but i don't want any Globals...

 

I just want to pass the reference (byref)... Aren't there Pointers in

VB?

 

I specifically only want to change the Variable I pass when

instantiating the Class... By doing this my Class won't need

to know, what variable, to send back data to.

 

Also, Anybody will be able to use it, without Affecting their style

of coding (By adding Globals)

 

I hope that makes sense :)

 

L8er

Burning

Posted

Or you could overload the exising function:

 


  'Calling code
       Dim thing As New Form2
       Dim strData As String
       thing.ShowDialog(Me, strData)
       MsgBox(strData)

  'Code to put into the dialog form

   Public Overloads Sub ShowDialog(ByVal Owner As System.Windows.Forms.IWin32Window, ByRef strData As String)
       MyBase.ShowDialog(Owner)
       strData = "show me the money"
   End Sub

Posted

I need to actually Pass a Reference from the Calling form to another form... And in My Other form Work with it, without

knowing the name of the Variable on the Owner form.

 

'Calling code
       Dim thing As New Form2 '-- Has Variable strData as string on
       thing.ShowDialog(Me, strData)
       MsgBox(strData)

 

I need to change the Value of strData in 'thing' without knowing

the Variable name strData, so When i use the 'thing' i just pass the reference, and it gets changed...

 

There has to be a way...

 

Come on u Gurus... This should be easy for ya... Help a man out

here...

  • Leaders
Posted

Seems as though if you pass any string into the function as ByRef, then you can modify the string passed to 'thing'. You'll only have to modify the strData in thing. If you changed the first character to an A, then you should see the changes in the variable that you passed.

And since the procedure is public you can call it from anywhere.

Am I on the right track of what you want? :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

Ok, no you can't do it that way

 

I assume in your constructor you are assigning the passed string variable to a private member in the class. The problem is this:

 

Dim x as String = "hi"

Dim y As String = x

 

x and y do not point to the same text string! y is a complete copy of x and is not associated with x.

 

You need to create a Property that you can read the final value from after the ShowDialog is complete.

 


Public Class X
 Inherits Form

 Protected _m As String

 Public Sub New(ByVal s As String)
   MyBase.New()
   _m = s
 End Sub

 Public ReadOnly Property ResultValue() As String
   Get
     Return _m
   End Get
 End Property

End Class

 

so, now you can do something like this:

 


Dim s As String = "First Value"

With New X(s)
 .ShowDialog(Me)
 Me.txtResult.Text() = .ResultValue()
End With

-=splice=-

It's not my fault I'm a Genius!

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