| Author |
Message |
kageg

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
i am trying to take the texbox name and then send it to another procedure without typing the name of the textbox from the leave event of the textbox
Visual Studio Express Editions20
|
| |
|
| |
 |
Trucker

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
kageg wrote: | | i am trying to take the texbox name and then send it to another procedure without typing the name of the textbox from the leave event of the textbox |
|
How about a sample of what you are trying to do You question is not very clear. If you are trying to assign something from a textbox,like the text in the textbox, to another procedure, you will have to reference the Textbox1.Text in the other procedure:
MyotherValue = Textbox1.Text
Is that what you are wanting to do
james
aka:Trucker
|
| |
|
| |
 |
kageg

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
i want to remove S631 from the code
Private Sub S631_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles S631.Leave
Dim nu As String
Dim na As String
na = "S631"(the name of the textbox)
nu = S631.Text
Module1.AdSt(nu, na)
End Sub
|
| |
|
| |
 |
Andrej Tozon

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
The sender variable contains a reference to the control, which raised the event, that's a textbox in your case:
Dim nu As String Dim na As String
Dim textBox As TextBox = DirectCast(sender, TextBox).Name na = textBox.Name nu = textBox.Text Module1.AdSt(nu, na)Andrej
|
| |
|
| |
 |
kageg

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
im getting this error how do i get round it
Error 1 Value of type 'String' cannot be converted to 'System.Windows.Forms.TextBox'.
|
| |
|
| |
 |
spotty

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
You want to ensure that you are setting the text property
Textbox1.text = "sdsdsdsd"
not
Textbox1= "sdsdsdsd"
|
| |
|
| |
 |
kageg

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
Dim textBox As TextBox = DirectCast(sender, TextBox).Name
is where the error is occuring
|
| |
|
| |
 |
spotty

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
This will fail as your trying to assign a string to a textbox, breaking it down into two steps should help.
Dim textBox As TextBox = DirectCast(sender, TextBox) textBox.Name = sender.name
|
| |
|
| |
 |
Tall Dude

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
Public Class Form1
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TextBox1.Leave, TextBox2.Leave
Dim someboxtext As String = CStr((CallByName(sender, "Text", CallType.Get)))
MsgBox( CStr((CallByName(sender, "Name", CallType.Get))) & someboxtext)
End Sub
End Class
|
| |
|
| |
 |
kageg

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
i Think i am missing something when you say sender what do you mean
|
| |
|
| |
 |
spotty

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
Normally when you create an event handler say for a windows forms application event there are two parameters - normally the first is sender as object and the second is some kind of EventArgs.
Some examples are
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click,Button2Click
End Sub
The sender is actually identifying which control is initiating this call. As you can hook up the same event to multiple controls or events. So in the 2nd example you could use sender to determine where button1 or button2 was the control which caused the event method to be executed.
|
| |
|
| |
 |
kageg

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
Thanks for the help had to textbox = DirectCast(sender, TextBox) after the dim to get it work
Private Sub S631_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles S631.Leave
Dim nu As String
Dim na As String
Dim textbox As TextBox
textbox = DirectCast(sender, TextBox)
na = textbox.Name
nu = textbox.Text
Module1.AdSt(nu, na)
end sub
|
| |
|
| |
 |
Andrej Tozon

|
Posted: Visual Basic Express Edition, I do a use the textbox name with out typing it |
Top |
I'mSorry, had a typo when pasting the code - I forgot to remove .Name from the DirectCast line. Glad you figured it out yourself.
Andrej
|
| |
|
| |
 |
| |