Results 1 to 12 of 12

Thread: Err help? :)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    5

    Question 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.

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Err help? :)

    This is VB6 forum, try VB.Net

  3. #3

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    5

    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?

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 -

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    5

    Re: Erm help pls? :)

    Quote Originally Posted by stanav View Post
    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.

  7. #7
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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).

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 -

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Err help? :)

    This thread already exists in this forum, and is a bit more advanced.
    My usual boring signature: Nothing

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Err help? :)

    Quote Originally Posted by Shaggy Hiker View Post
    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
  •  



Click Here to Expand Forum to Full Width