Retrieve values from objects between forms

conan1989

Member
Joined
Jul 1, 2008
Messages
14
Programming Experience
1-3
Hi,

In VB.net how do you retrieve an value from a object in a different form.
(please correct me if i'm using wrong / bad terms)

eg:

VB.NET:
' on frmMain

MsgBox ("Say ""Hello World"" Mr. " & frmOther.txtName.text)
 
Last edited:
Using "F1" (online help) you usually get a good information.

Considering that you have a textbox named textbox1 on the form from which you want to retreive or set the text :

VB.NET:
    Public Property MyText() As String
        Get
            Return TextBox1.Text
        End Get
        Set(ByVal value As String)
            TextBox1.Text = value
        End Set
    End Property

You can add a validation clause to your if, then statement to control the value or create a readonly property if you don't need to write a value.
 
Hi,

In VB.net how do you retrieve an value from a object in a different form.

VB.NET:
' on frmMain

MsgBox (frmOther.txtName.text)
You can't already with this code? Controls in forms in VB 2008 has access modifier Friend by default, which means the class field that is holding the control reference is available for class consumers within the assembly. Your profile says you're using VB 2008, but if you're not I can't remember default values for older versions. You can set the Modifiers property in Designer by selecting the controls and go to Properties window. Allowing this type of access is something you may or may not want, as it allow users of the form (within the access level) full control of the control objects.
 
You can't already with this code? Controls in forms in VB 2008 has access modifier Friend by default, which means the class field that is holding the control reference is available for class consumers within the assembly. Your profile says you're using VB 2008, but if you're not I can't remember default values for older versions. You can set the Modifiers property in Designer by selecting the controls and go to Properties window. Allowing this type of access is something you may or may not want, as it allow users of the form (within the access level) full control of the control objects.

Hi, thanks. The IDE i'm using is SharpDevelop (SharpDevelop @ic#code).

I'm still having troubles pushing and pulling values between forms, pretty sure it's something painfully simple i've over looked. I remember back in VB6, it was real simple lol
 
Normally you interact with class instances through the defined properties and methods. When you add a control in designer the IDE generates a field variable for it, fields are normally not exposed outside the class, but using the Modifiers property as explained you can still allow it.
The IDE i'm using is SharpDevelop
If it's causing you unnecessary grief you should go for the free VB 2008 Express instead. I appreciate the effort and availability of the SharpDevelop project, but last time I tried it (v2) it was not up to par with the MS suite.
 
Normally you interact with class instances through the defined properties and methods. When you add a control in designer the IDE generates a field variable for it, fields are normally not exposed outside the class, but using the Modifiers property as explained you can still allow it.

If it's causing you unnecessary grief you should go for the free VB 2008 Express instead. I appreciate the effort and availability of the SharpDevelop project, but last time I tried it (v2) it was not up to par with the MS suite.


v3 is out, it's much much better then it was in v2. As much as i'm using windoze (*damn you work!*), i'd prefer to stay away from as many of MS's bag of tricks if possible, on ethos alone.

Thanks heaps for your help, I'll try it out in VS express to see what's different, and post it.
 

Latest posts

Back
Top