|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie QuestionIm new to VB.NET programming, Im currently starting my study. I have a simple question. I have two forms in my project and I was wondering how could I access the value of a Text box from one form in the other and vice versa. What is the best way to display the 2nd form and be able to access the objects from the main form. Right now im using the command Dim frmPrint As New Form2 frmPrint.Show() Thanks, Abet The code you have below is just fine. Now, let's assume this code is inside
of Form1, so you could access a textbox that is in Form2 from Form1 with this code: Public Class Form1 Sub ShowOtherForm() Dim frmPrint As New Form2 frmPrint.Show() Dim otherTextBoxValue As String = frmPrint.TextBox1.Text End Sub End Class Show quoteHide quote "Abet" <herbert.bautista@yahoo.yahoo> wrote in message news:e1fHUpakGHA.3848@TK2MSFTNGP04.phx.gbl... > Hi, > > > Im new to VB.NET programming, Im currently starting my study. > > I have a simple question. I have two forms in my project and > > I was wondering how could I access the value of a Text box > > from one form in the other and vice versa. What is the best way > > to display the 2nd form and be able to access the objects from > > the main form. Right now im using the command > > Dim frmPrint As New Form2 > frmPrint.Show() > > > Thanks, > Abet > Hi Scott,
Thanks for the reply. Im really new to VB.NET When I close Form2 or frmPrint, how do I get the value of frmPrint.TextBox1.Text? I tried checking for the value of otherTextBoxValue but the variable it is not recognized in other objects Thanks, Abet Show quoteHide quote "Scott M." <s-mar@nospam.nospam> wrote in message news:upiNUCbkGHA.1204@TK2MSFTNGP02.phx.gbl... > The code you have below is just fine. Now, let's assume this code is > inside of Form1, so you could access a textbox that is in Form2 from Form1 > with this code: > > > Public Class Form1 > > Sub ShowOtherForm() > Dim frmPrint As New Form2 > frmPrint.Show() > Dim otherTextBoxValue As String = frmPrint.TextBox1.Text > End Sub > > End Class > > > > > "Abet" <herbert.bautista@yahoo.yahoo> wrote in message > news:e1fHUpakGHA.3848@TK2MSFTNGP04.phx.gbl... >> Hi, >> >> >> Im new to VB.NET programming, Im currently starting my study. >> >> I have a simple question. I have two forms in my project and >> >> I was wondering how could I access the value of a Text box >> >> from one form in the other and vice versa. What is the best way >> >> to display the 2nd form and be able to access the objects from >> >> the main form. Right now im using the command >> >> Dim frmPrint As New Form2 >> frmPrint.Show() >> >> >> Thanks, >> Abet >> > > Abet,
I did read your message a little bit else than Scott, than it is stealing his code (this is refering to another message from Scott) :-) \\\Public Class Form1 Sub ShowOtherForm() Dim frmPrint As New Form2 frmPrint.Owner = Me frmPrint.Show() Dim otherTextBoxValue As String = frmPrint.TextBox1.Text End Sub /// Now you can use in your second form \\\ WhatINeed = me.owner.Textbox1.Text /// I hope this helps, Cor Let's take this from the top...
Module1 'Global variable to hold a value as long as the program is running 'This should be the Project's Startup Object Public OtherFormTBValue As String Sub Main Dim Form1 As New Form1 Form1.Show() End Sub End Module Public Class Form1 Private frmPrint As New Form2 Sub ShowOtherForm frm2.Show() End Sub Function GetOtherFormsTextBoxValue() As String 'Here's how you can get the value of a textbox on another form 'just by calling this method anytime Form1 is open Return frm2.tb.Text End Sub Function GetOtherFormsTextBoxValue2() As String 'Here's another way to get the other form's textbox value 'When the 2nd form is closed, the global variable will be populated Return OtherFormTBValue End Sub End Class Public Class Form2 Dim tb As New TextBox Sub Form2_Close() Handles Form2.Close OtherFormTBValue = tb.text End Sub End Class Show quoteHide quote "Abet" <herbert.bautista@yahoo.yahoo> wrote in message news:%23D$gFpbkGHA.4284@TK2MSFTNGP05.phx.gbl... > Hi Scott, > > Thanks for the reply. Im really new to VB.NET > When I close Form2 or frmPrint, how do I get > the value of frmPrint.TextBox1.Text? I tried > checking for the value of otherTextBoxValue but > the variable it is not recognized in other objects > > Thanks, > Abet > > "Scott M." <s-mar@nospam.nospam> wrote in message > news:upiNUCbkGHA.1204@TK2MSFTNGP02.phx.gbl... >> The code you have below is just fine. Now, let's assume this code is >> inside of Form1, so you could access a textbox that is in Form2 from >> Form1 with this code: >> >> >> Public Class Form1 >> >> Sub ShowOtherForm() >> Dim frmPrint As New Form2 >> frmPrint.Show() >> Dim otherTextBoxValue As String = frmPrint.TextBox1.Text >> End Sub >> >> End Class >> >> >> >> >> "Abet" <herbert.bautista@yahoo.yahoo> wrote in message >> news:e1fHUpakGHA.3848@TK2MSFTNGP04.phx.gbl... >>> Hi, >>> >>> >>> Im new to VB.NET programming, Im currently starting my study. >>> >>> I have a simple question. I have two forms in my project and >>> >>> I was wondering how could I access the value of a Text box >>> >>> from one form in the other and vice versa. What is the best way >>> >>> to display the 2nd form and be able to access the objects from >>> >>> the main form. Right now im using the command >>> >>> Dim frmPrint As New Form2 >>> frmPrint.Show() >>> >>> >>> Thanks, >>> Abet >>> >> >> > > Thanks for the help guys, I will try it.
You're a big help to my study. Abet Show quoteHide quote "Scott M." <s-mar@nospam.nospam> wrote in message news:OYy4XKikGHA.3816@TK2MSFTNGP02.phx.gbl... > Let's take this from the top... > > Module1 > 'Global variable to hold a value as long as the program is running > 'This should be the Project's Startup Object > > Public OtherFormTBValue As String > > Sub Main > Dim Form1 As New Form1 > Form1.Show() > End Sub > > End Module > > Public Class Form1 > > Private frmPrint As New Form2 > > Sub ShowOtherForm > frm2.Show() > End Sub > > Function GetOtherFormsTextBoxValue() As String > 'Here's how you can get the value of a textbox on another form > 'just by calling this method anytime Form1 is open > Return frm2.tb.Text > End Sub > > Function GetOtherFormsTextBoxValue2() As String > 'Here's another way to get the other form's textbox value > 'When the 2nd form is closed, the global variable will be populated > Return OtherFormTBValue > End Sub > > End Class > > Public Class Form2 > Dim tb As New TextBox > > Sub Form2_Close() Handles Form2.Close > OtherFormTBValue = tb.text > End Sub > > End Class > > > > "Abet" <herbert.bautista@yahoo.yahoo> wrote in message > news:%23D$gFpbkGHA.4284@TK2MSFTNGP05.phx.gbl... >> Hi Scott, >> >> Thanks for the reply. Im really new to VB.NET >> When I close Form2 or frmPrint, how do I get >> the value of frmPrint.TextBox1.Text? I tried >> checking for the value of otherTextBoxValue but >> the variable it is not recognized in other objects >> >> Thanks, >> Abet >> >> "Scott M." <s-mar@nospam.nospam> wrote in message >> news:upiNUCbkGHA.1204@TK2MSFTNGP02.phx.gbl... >>> The code you have below is just fine. Now, let's assume this code is >>> inside of Form1, so you could access a textbox that is in Form2 from >>> Form1 with this code: >>> >>> >>> Public Class Form1 >>> >>> Sub ShowOtherForm() >>> Dim frmPrint As New Form2 >>> frmPrint.Show() >>> Dim otherTextBoxValue As String = frmPrint.TextBox1.Text >>> End Sub >>> >>> End Class >>> >>> >>> >>> >>> "Abet" <herbert.bautista@yahoo.yahoo> wrote in message >>> news:e1fHUpakGHA.3848@TK2MSFTNGP04.phx.gbl... >>>> Hi, >>>> >>>> >>>> Im new to VB.NET programming, Im currently starting my study. >>>> >>>> I have a simple question. I have two forms in my project and >>>> >>>> I was wondering how could I access the value of a Text box >>>> >>>> from one form in the other and vice versa. What is the best way >>>> >>>> to display the 2nd form and be able to access the objects from >>>> >>>> the main form. Right now im using the command >>>> >>>> Dim frmPrint As New Form2 >>>> frmPrint.Show() >>>> >>>> >>>> Thanks, >>>> Abet >>>> >>> >>> >> >> > >
FileSystemWatcher raises Changed Twice....
Memory Leaks Overrides and mybase ?? Refer to an Instance of a form Timer1_Tick is never fired News content into an XML file Date time format Can we seperate the Bussiness Logic and User Interface? Printing over network... How to "Archive" a text file with multiple handles open |
|||||||||||||||||||||||