|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Passing value to a Forms TextBoxHow do I pass a value from a Public Sub in a class to a forms textbox.
I get 'Name Forms is not declared' with Forms!frmName!txtBoxName. Regards Is this an ASP.NET Textbox control? If so, just use the name of the
control, as in: txtUser.Text = someValue Show quoteHide quote "Terry" <news-g***@whiteHYPHENlightDOTme.uk> wrote in message news:%23Wbz0ZPOHHA.4992@TK2MSFTNGP04.phx.gbl... > How do I pass a value from a Public Sub in a class to a forms textbox. > > I get 'Name Forms is not declared' with Forms!frmName!txtBoxName. > > > > Regards > > Hi Scott,
I'm using a Windows form, hopefully should be into ASP later this year, thanks. Regards Show quoteHide quote "Scott M." <s-mar@nospam.nospam> wrote in message news:eYrcUhPOHHA.2140@TK2MSFTNGP03.phx.gbl... > Is this an ASP.NET Textbox control? If so, just use the name of the > control, as in: > > txtUser.Text = someValue > > > "Terry" <news-g***@whiteHYPHENlightDOTme.uk> wrote in message > news:%23Wbz0ZPOHHA.4992@TK2MSFTNGP04.phx.gbl... >> How do I pass a value from a Public Sub in a class to a forms textbox. >> >> I get 'Name Forms is not declared' with Forms!frmName!txtBoxName. >> >> >> >> Regards >> >> > > In the Public Sub in your class, you need a reference to the form concerned.
There are many ways of achieving this but one way is: Dim _f As Form = My.Application.OpenForms("frmName") An object of type Form does not, of course know anything about txtBoxName, so you need to cast the reference to a variable of type frmName: Dim _f As frmName = CType(My.Application.OpenForms("frmName"), frmName) Now that you have the reference, you can manipulate the TextBox directly: _f.txtBoxName.text = "The quick brown fox ..." There are a number of nuances to this approach but if the app is a basic Windows Forms app then this approach should work just fine in most cases. Show quoteHide quote "Terry" <news-g***@whiteHYPHENlightDOTme.uk> wrote in message news:%23Wbz0ZPOHHA.4992@TK2MSFTNGP04.phx.gbl... > How do I pass a value from a Public Sub in a class to a forms textbox. > > I get 'Name Forms is not declared' with Forms!frmName!txtBoxName. > > > > Regards > > Hi Again Stephany,
Thanks again for your help. Just what I needed, I'll give it a go later today, it's 1 a.m. just now. regards Terry Show quoteHide quote "Stephany Young" <noone@localhost> wrote in message news:%23FONgvPOHHA.4848@TK2MSFTNGP04.phx.gbl... > In the Public Sub in your class, you need a reference to the form > concerned. There are many ways of achieving this but one way is: > > Dim _f As Form = My.Application.OpenForms("frmName") > > An object of type Form does not, of course know anything about txtBoxName, > so you need to cast the reference to a variable of type frmName: > > Dim _f As frmName = CType(My.Application.OpenForms("frmName"), frmName) > > Now that you have the reference, you can manipulate the TextBox directly: > > _f.txtBoxName.text = "The quick brown fox ..." > > There are a number of nuances to this approach but if the app is a basic > Windows Forms app then this approach should work just fine in most cases. > > > "Terry" <news-g***@whiteHYPHENlightDOTme.uk> wrote in message > news:%23Wbz0ZPOHHA.4992@TK2MSFTNGP04.phx.gbl... >> How do I pass a value from a Public Sub in a class to a forms textbox. >> >> I get 'Name Forms is not declared' with Forms!frmName!txtBoxName. >> >> >> >> Regards >> >> > > Here's another way of doing it:
- Start Windows App - Add a button to form1 - Add a second form - Add a textbox to form2 Open form2 in code view & add this code: Public Shadows Sub ShowDialog(ByVal s As String) TextBox1.Text = s MyBase.ShowDialog() End Sub Public Shadows Sub Show(ByVal s As String) TextBox1.Text = s MyBase.Show() End Sub Double-click the button in form1 & add one of these snippets: ' Show modal: Dim frm As New Form2 frm.ShowDialog("Hello, World!") frm.Dispose() ' Show form: Dim frm As New Form2 frm.Show("Hello, World!") I hope this helps, Newbie Coder Hi,
I'm guessing that form2 is discarded after the magic has worked. Usefull, I have seen this example on another site but it's not quite what I need just now. One for later in the project. Regards Terry Show quoteHide quote "Newbie Coder" <newbie_coder@pleasespamme.com> wrote in message news:u2jLoJQOHHA.5012@TK2MSFTNGP02.phx.gbl... > Here's another way of doing it: > > - Start Windows App > - Add a button to form1 > - Add a second form > - Add a textbox to form2 > > Open form2 in code view & add this code: > > Public Shadows Sub ShowDialog(ByVal s As String) > TextBox1.Text = s > MyBase.ShowDialog() > End Sub > > Public Shadows Sub Show(ByVal s As String) > TextBox1.Text = s > MyBase.Show() > End Sub > > Double-click the button in form1 & add one of these snippets: > > ' Show modal: > > Dim frm As New Form2 > frm.ShowDialog("Hello, World!") > frm.Dispose() > > ' Show form: > > Dim frm As New Form2 > frm.Show("Hello, World!") > > I hope this helps, > > Newbie Coder > > At least I could help you in the future, Terry
I guess you are on UK time like I am :) Take it easy, Newbie Coder (It's just a name)
Problem running query in code
System.Net.Sockets.SocketException Error Automate file downloads Newbie Missing Something with Access DB Update Using VB .NET setting form properties during runtime converting bitarray to int64 New line character How to get title of all "child" windows? SQL Statements Console application to generate Excel file |
|||||||||||||||||||||||