Home All Groups Group Topic Archive Search About

Passing value to a Forms TextBox

Author
16 Jan 2007 10:45 PM
Terry
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

Author
15 Jan 2007 10:56 PM
Scott M.
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
>
>
Author
16 Jan 2007 12:59 AM
Terry
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
>>
>>
>
>
Author
15 Jan 2007 11:21 PM
Stephany Young
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
>
>
Author
16 Jan 2007 12:58 AM
Terry
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
>>
>>
>
>
Author
16 Jan 2007 12:10 AM
Newbie Coder
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
Author
16 Jan 2007 1:03 AM
Terry
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
>
>
Author
16 Jan 2007 1:13 AM
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)