473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Passing value to a Forms TextBox

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
Jan 15 '07 #1
11 1589
Is this an ASP.NET Textbox control? If so, just use the name of the
control, as in:

txtUser.Text = someValue
"Terry" <ne*******@whiteHYPHENlightDOTme.ukwrote in message
news:%2****************@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


Jan 15 '07 #2
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" <ne*******@whiteHYPHENlightDOTme.ukwrote in message
news:%2****************@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


Jan 15 '07 #3
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
Jan 16 '07 #4
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

"Stephany Young" <noone@localhostwrote in message
news:%2****************@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" <ne*******@whiteHYPHENlightDOTme.ukwrote in message
news:%2****************@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



Jan 16 '07 #5
Hi Scott,

I'm using a Windows form, hopefully should be into ASP later this year,
thanks.

Regards

"Scott M." <s-***@nospam.nospamwrote in message
news:eY**************@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" <ne*******@whiteHYPHENlightDOTme.ukwrote in message
news:%2****************@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



Jan 16 '07 #6
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

"Newbie Coder" <ne**********@pleasespamme.comwrote in message
news:u2**************@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


Jan 16 '07 #7
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)
Jan 16 '07 #8
Terry,

The one is given by Newbie is the one if you pass from a owner to a slave,
the one given by Stephany is the one if you pass from a slave to an owner.
You did in my opinion not tell that direction.

In the latter case (from a child to a parent) I prefer however

Dim frmSlave as Form2
frmSlave.owner = me
frmSlave.Show

and in the slave
DirectCast(owner.TextboxA) = "whatever"

Cor

"Terry" <ne*******@whiteHYPHENlightDOTme.ukschreef in bericht
news:%2****************@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


Jan 16 '07 #9
Hi Cor,

Thanks for distinguishing between the two, I've no doubt that I will need
both shortly.

Regards
Terry

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eG**************@TK2MSFTNGP02.phx.gbl...
Terry,

The one is given by Newbie is the one if you pass from a owner to a slave,
the one given by Stephany is the one if you pass from a slave to an owner.
You did in my opinion not tell that direction.

In the latter case (from a child to a parent) I prefer however

Dim frmSlave as Form2
frmSlave.owner = me
frmSlave.Show

and in the slave
DirectCast(owner.TextboxA) = "whatever"

Cor

"Terry" <ne*******@whiteHYPHENlightDOTme.ukschreef in bericht
news:%2****************@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



Jan 16 '07 #10
I haven't seen that syntax since Access VBA. Are you attempting to interact
with a textbox in this manner: Forms!frmName!txtBoxName?

If so,

Try using a dot instead of an exclamation point.

forms.item(myformindex).txtMyTextbox

Example

public sub Test(someValue as string)
dim strValue as string

strValue = "Test:" & someValue

for each f as form in forms
if typeof f is frmTarget then
f.txtTarget.text = someValue
end if
next

end sub
"Terry" <ne*******@whiteHYPHENlightDOTme.ukwrote in message
news:%2****************@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


Jan 16 '07 #11
Hi Amdrit,

Yup, good old Access VBA. I understand your example, I have used something
similar in VBA to test whether a form was open or not.

Thanks for the help.
Regards

"AMDRIT" <am****@hotmail.comwrote in message
news:Oy**************@TK2MSFTNGP06.phx.gbl...
>I haven't seen that syntax since Access VBA. Are you attempting to
interact with a textbox in this manner: Forms!frmName!txtBoxName?

If so,

Try using a dot instead of an exclamation point.

forms.item(myformindex).txtMyTextbox

Example

public sub Test(someValue as string)
dim strValue as string

strValue = "Test:" & someValue

for each f as form in forms
if typeof f is frmTarget then
f.txtTarget.text = someValue
end if
next

end sub
"Terry" <ne*******@whiteHYPHENlightDOTme.ukwrote in message
news:%2****************@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



Jan 16 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
3
by: Aaron | last post by:
I am having a little difficulty with a relatively simple task. I have a parent webform. I have a javascript attribute added to a button to open a new window when clicked. The user fills in a...
4
by: Bernie Yaeger | last post by:
This s/b easy, and I'm sure it is, but I haven't been able to figure it out: I want to pass the value of a textbox from form1 to form2 - both are child forms of the mdi parent 'baseform'. form1...
6
by: RBCC | last post by:
Public Class fraction Dim m_numerator As Int16 Dim m_denominator As Int16 Public Event zerodenom() Public Property numerator() As Int16 Get Return m_numerator
0
by: Eric Sabine | last post by:
OK, I'm trying to further my understanding of threading. The code below I wrote as kind of a primer to myself and maybe a template that I could use in the future. What I tried to do was pass data...
4
by: campwes | last post by:
Hi! I have what I hope is a simple problem. I have 2 web forms. The first form is a welcome page with a textbox and button (in a user control). What's supposed to happen is that a user will...
5
by: lextendo | last post by:
Hi all, I have a problem which seems it has to have a simple solution, though I can't figure it out and I can't find a solution on usenet either. Two forms: Form A contains a textbox where the...
3
by: nt8jbwu02 | last post by:
I am trying to use the example at: http://msdn2.microsoft.com/en-us/library/ms171728(d=ide).aspx to update a control in a thread safe maner. The article shows a couple of ways to do so and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.