|
-
Feb 8th, 2010, 03:42 PM
#1
Thread Starter
New Member
Err help? :)
Erm, Im quite new with using Visual basic and I need help with this 1 code I just started.
What I am trying to do is have a field which I can type in and when I press the button it says what I have just typed in. Here is the code.
Code:
Public Class Form1
Dim name As String
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtbox.TextChanged
name = txtname.Text
MsgBox(name)
End Sub
End Class
Thanks.
-
Feb 8th, 2010, 03:56 PM
#2
Re: Err help? :)
This is VB6 forum, try VB.Net
-
Feb 8th, 2010, 04:11 PM
#3
-
Feb 8th, 2010, 04:17 PM
#4
Thread Starter
New Member
Re: Erm help pls? :)
Nope. it says variable "name" conflicts with property "name" in the base class "control" and should be declared as "shadows". im not sure what that means, and ive made sure that my name property and my text property arent the same, but it still says this?
-
Feb 8th, 2010, 04:17 PM
#5
Re: Erm help pls? :)
Do you have a textbox named "txtname" and a button named "Button1" on Form1?. If you do, the code you showed above should work.
Edit: Oh, it's a naming conflict. Just change you variable to another name such as "name1"
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Feb 8th, 2010, 04:19 PM
#6
Thread Starter
New Member
Re: Erm help pls? :)
 Originally Posted by stanav
Do you have a textbox named "txtname" and a button named "Button1" on Form1?. If you do, the code you showed above should work.
Yeah, its set to that but its still not working :/
Edit: Ive changed my variable to "name1" its works now but itstead of what I typed in the text box the label text appears in the new message box.
Last edited by Tubbly; Feb 8th, 2010 at 04:23 PM.
-
Feb 8th, 2010, 04:19 PM
#7
Re: Erm help pls? :)
To resolve such conflict enclose your conflicting variable name in brackets.
Code:
Public Class Form1
Dim [name] As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
[name] = txtname.Text
MsgBox([name])
End Sub
End Class
But normally it's not a good way to name a variable since it can confuse you or anyone who will be reading your code, besides you can do it simpler:
Code:
MsgBox(txtname.Text)
Your form already has a property Name so when you declare a variable with the same name the compiler informs you of the naming conflict. In most cases you should rename your variable (there are exceptions though, but not this time).
Last edited by cicatrix; Feb 8th, 2010 at 04:23 PM.
-
Feb 8th, 2010, 04:21 PM
#8
Re: Erm help pls? :)
Change the variable name from "name" to "name1"
Code:
Dim name1 As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
name1 = txtname.Text
MsgBox(name1)
End Sub
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Feb 8th, 2010, 04:39 PM
#9
Re: Err help? :)
You have an orphaned end sub.... right after your dim name line... shouldn't be there... try removing it, then try your code again. It should work.
-tg
-
Feb 8th, 2010, 07:25 PM
#10
-
Feb 8th, 2010, 07:46 PM
#11
Re: Err help? :)
This thread already exists in this forum, and is a bit more advanced.
My usual boring signature: Nothing
 
-
Feb 9th, 2010, 07:01 AM
#12
Re: Err help? :)
 Originally Posted by Shaggy Hiker
This thread already exists in this forum, and is a bit more advanced.
And now both have been merged into one.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|