Import textbox.text from form2 to form1 textbox

Rakstip

Member
Joined
Mar 14, 2005
Messages
14
Location
Alsip, IL USA
Programming Experience
Beginner
I have 3 textboxes in form2(Setup) and I want the text from those (2) tb's to be used by form1(Main). The text is to be used for a webrequest. I am using visual studio.net(vb.net).

'form2(Setup)
tburl.text = "some web address"
tbcmd.text = "cmd=user_xml"

'form1(Main)
tbemailaddress.text = "some email address"
btnGetXML_click......
dim url as string
url = form2(Setup)tburl.text & form2(Setup)tbcmd.text & "&email=" & form1(Main)tbemailaddress.text
'webrequest code
Thx for the help in advance.......
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
there are several ways to do this

1. you can reference your Form2 variable to get the text property of the textbox's IE:
VB.NET:
dim frmMyForm2 as new Form2
frmMyForm2.Show 'Youve already go this stuff done

 url = frmMyForm2.tburl.text & frmMyForm2.tbcmd.text & "&email=" & tbemailaddress.text
2. add a module to the project and in the module declare two global variables (strUrl and strCmd) then in form2 use the LostFocus event of the two textboxes to set those variables, then in form1 simply use the variables in your url line IE:
VB.NET:
'Module
Friend gstrUrl as String
Friend gstrCmd as String

'form2
Private Sub tburl_LostFocus (...) Handles  tburl.LostFocus
  'Validation Code Here
  gstrUrl =  tburl.Text
End Sub
Private Sub tbcmd_LostFocus (...) Handles  tbcmd.LostFocus
   'Validation Code Here
   gstrCmd =  tbcmd.Text
 End Sub

'form1
 url = gstrUrl & gstrCmd & "&email=" & tbemailaddress.text
i'd personally go with method two (i'm a big fan of modules) as it allows for those variable to be used in yet more forms if you choose to include more forms sometime later then the variables are already taken care of
 
Top Bottom