Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Communicating with controls from other windows

Status
Not open for further replies.

pink2070

Programmer
Joined
Jan 29, 2004
Messages
23
Location
US
Hello EveryOne,

Quick Questions (Really Simple):

1. How do I obtain a value from a previous form. It used to be that you could reference this information in visual basic 6.0 by using the following syntax (i.e, FrmName.ControlName.Text). My question is how is this done in visual basic.net?

Thanks,

Pink
 
In VB6, there was a hidden global variable for each form defined as
Private FrmName as New FrmName
This held the default instance of FrmName. You did not have to use it. You could have explicitly instantiated your own FrmName as in
Dim myFrm as FrmName
Set myForm as New FrmName

There is no default instance in VB.Net.

You must instantiate the form explicitly. If you wish, define the variable that will contain the reference as a Public field of a module or a Shared Variable of a class.

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Thank you very much, I tried your method, and I didn't receive any build errors, but I was unable to retrieve the values from the other screen, could you perhaps point me in the right direction on this one.

*******************************************************
this is what I did:

Start up form one (the frmNum1):
*I put 2 textboxes on the form and gave them values (txtOne, txtTwo)

Form two (the frmNum2)
dim tempValOne as string
dim tempValTwo as string
dim f1 as new frmNum1

tempValOne = f1.txtOne.text
tempValTwo = f1.txtTwo.text

**********************************************

For whatever reason I receive no vals for f1.txtOne.text and f1.txtTwo.text, could this be do to my transitioning methodology:

On frmNum1 I called frmNum2:
dim f2 as new frmNum2
f1.hide
f2.show()

Was there something wrong wth my transition statment?

Thanks in advance

Pink,

 
on form2 you are creating a new instance of form1 by

dim f1 as new frmNum1

what JohnYingLing meant by "If you wish, define the variable that will contain the reference as a Public field of a module or a Shared Variable of a class."

is that you need to be looking at the instance of f1(form1) which had the txtOne setup.

so, if you had a class which setup the Form1 then put the

Dim f1 As New frmNum1

in the global declarations. therefore from your other form or any other module you can just reference that instance of the form directly. i.e.

Msgbox f1.whatever


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top