Objects on a different form 
Author Message
 Objects on a different form

If I have 2 forms, frm1 and frm2, and frm1 has a text box, how do I get the
text from the text box in an event in frm2? In VB6 I used frm1.txtbox.text
but I don't how it works in .Net.

Thanks in advance



Fri, 04 Nov 2005 23:18:54 GMT  
 Objects on a different form
Hello,


Quote:
> If I have 2 forms, frm1 and frm2, and frm1 has a text box,
> how do I get the text from the text box in an event in frm2?
> In VB6 I used frm1.txtbox.text but I don't how it works
> in .Net.

http://makeashorterlink.com/?Y47252F94

Regards,
Herfried K. Wagner
--
http://www.mvps.org/dotnet



Fri, 04 Nov 2005 23:35:09 GMT  
 Objects on a different form
Thanks Herfried.



Quote:
> Hello,


> > If I have 2 forms, frm1 and frm2, and frm1 has a text box,
> > how do I get the text from the text box in an event in frm2?
> > In VB6 I used frm1.txtbox.text but I don't how it works
> > in .Net.

> http://makeashorterlink.com/?Y47252F94

> Regards,
> Herfried K. Wagner
> --
> http://www.mvps.org/dotnet



Fri, 04 Nov 2005 23:46:54 GMT  
 Objects on a different form

Quote:
> If I have 2 forms, frm1 and frm2, and frm1 has a text box, how do I
> get the text from the text box in an event in frm2? In VB6 I used
> frm1.txtbox.text but I don't how it works in .Net.

If you want to access an object, like a Form, you need a reference. If you
don't have the reference, you have to pass the reference to the object that
needs the reference. Where when and how depends on the structure of your
application.

--
Armin



Sat, 05 Nov 2005 02:04:22 GMT  
 Objects on a different form
yes, well, what if frm2 is a module?

in the module i have

Dim frm1 As New frmMain

str = frm1.txtBox.Text

MsgBox(str)

so, there is a refference. the problem is that str is always empty even if
txtBox has text.


Quote:

> > If I have 2 forms, frm1 and frm2, and frm1 has a text box, how do I
> > get the text from the text box in an event in frm2? In VB6 I used
> > frm1.txtbox.text but I don't how it works in .Net.

> If you want to access an object, like a Form, you need a reference. If you
> don't have the reference, you have to pass the reference to the object
that
> needs the reference. Where when and how depends on the structure of your
> application.

> --
> Armin



Sat, 05 Nov 2005 05:07:33 GMT  
 Objects on a different form


Quote:
> yes, well, what if frm2 is a module?

> in the module i have

> Dim frm1 As New frmMain

> str = frm1.txtBox.Text

> MsgBox(str)

> so, there is a refference. the problem is that str is always empty
> even if txtBox has text.

This is because you are creating a NEW reference instead of referring to a
form that already exists.  The new form's text box probably does not have
any text in the text property.


Sat, 05 Nov 2005 05:55:51 GMT  
 Objects on a different form

Quote:
> yes, well, what if frm2 is a module?

frm2 is a Form? Then it is not a module.

Quote:
> in the module i have

> Dim frm1 As New frmMain

> str = frm1.txtBox.Text

> MsgBox(str)

> so, there is a refference. the problem is that str is always empty
> even if txtBox has text.

"New" creates a new Form. If you want to access the _existing_ Form, you
have to pass a reference to the procedure:

Sub MySub(byval frm1 As frmMain)
    dim str as string
    str = frm1.txtBox.Text
    msgbox str
end sub

Apart from that, why don't you put the procedure in the Form?

--
Armin



Sat, 05 Nov 2005 06:09:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Controlling objects in a different form

2. SQL select different results on different forms

3. Linking Form Objects in HTML to other Form Objects using VBScript

4. Open form, close form, open form = disposed object exception

5. Access97: How can you compare different versions of objects

6. errors different when executing SQL statements via recordset or connection object

7. Invoking Word.Application Object using different Office versions

8. Excel Objects and saving in a different format

9. How to construct vbscript class object with different constructors

10. Referencing objects in a different window

11. (newbie question) Running an object on a different server

12. problems with object ID's in different language contexts

 

 
Powered by phpBB® Forum Software