Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Subclass a Control by UserControl

Subclass a Control by UserControl

Scheduled Pinned Locked Moved Visual Basic
questioncsharpvisual-studiohardware
32 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • realJSOPR realJSOP

    Samir Ibrahim wrote:

    6 month of learning vb.net

    Six months of "learning VB.net" makes you a rank amateur, a newbie, a mere child. It took me ten years to get to a point where I felt comfortable in my knowledge of C++. I've been doing C# for just two years (about 7 years less than almost everyone else here), and while I feel pretty comfortable with it, I wouldn't call myself "accomplished". And while I realize that this is the VB forum, saying you code in VB is like admitting you use AOL to get on the internet.

    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

    J Offline
    J Offline
    Jon_Boy
    wrote on last edited by
    #21

    John Simmons / outlaw programmer wrote:

    saying you code in VB is like admitting you use AOL to get on the internet.

    Hey now, I can understand bashing the OP, but the rest of us? Back when <= VS6, I would agree with you; but with the CLR/CLS, does it really matter what you use to 'develop' with these days (other than fitting in with the C# norm)?

    Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

    realJSOPR 1 Reply Last reply
    0
    • realJSOPR realJSOP

      Samir Ibrahim wrote:

      6 month of learning vb.net

      Six months of "learning VB.net" makes you a rank amateur, a newbie, a mere child. It took me ten years to get to a point where I felt comfortable in my knowledge of C++. I've been doing C# for just two years (about 7 years less than almost everyone else here), and while I feel pretty comfortable with it, I wouldn't call myself "accomplished". And while I realize that this is the VB forum, saying you code in VB is like admitting you use AOL to get on the internet.

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      S Offline
      S Offline
      Samir Ibrahim 0
      wrote on last edited by
      #22

      You have 10 years experience in C++, 2 years in C# Since the algorithm and principals (thinking of solving the problem) is the same almost in all language. can you compare your self for learning let say "Delphi" with someone who has no programming experience at all?

      Like car accidents, most hardware problems are due to driver error. Samir R. Ibrahim

      realJSOPR N 2 Replies Last reply
      0
      • J Jon_Boy

        John Simmons / outlaw programmer wrote:

        saying you code in VB is like admitting you use AOL to get on the internet.

        Hey now, I can understand bashing the OP, but the rest of us? Back when <= VS6, I would agree with you; but with the CLR/CLS, does it really matter what you use to 'develop' with these days (other than fitting in with the C# norm)?

        Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #23

        Jon_Boy wrote:

        Hey now, I can understand bashing the OP, but the rest of us?

        I am an equal-opportunity abuser.

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        J 1 Reply Last reply
        0
        • S Samir Ibrahim 0

          williamnw wrote:

          you are asking why writing a function (forget that it's a property for the moment) without returning a value causes a compiler warning that there is no value returned?

          Where I mention that I am not returning a value for the function? show me. here is my question

          Public Class myclass1
          Function Sum()
          Sum = 1 + 2 ' <-- Works Fine
          Me.Sum = 1 + 2 ' <-- Gives error although me.Sum should be the same as Sum alone
          End Function
          End Class

          Like car accidents, most hardware problems are due to driver error. Samir R. Ibrahim

          N Offline
          N Offline
          Nagy Vilmos
          wrote on last edited by
          #24

          0. No question, just a statement. 1. the first line is assigning the value that will be returned:

          Samir Ibrahim wrote:

          Sum = 1 + 2 ' <-- Works Fine

          2. The second line is trying to assign a new value to the what would be returned:

          Samir Ibrahim wrote:

          Me.Sum = 1 + 2 ' <-- Gives error although me.Sum should be the same as Sum alone

          Your whole reference point is wrong. With every post you are showing more ignorance and less ability. These are not new concepts, they have not changed for a long time. The example given, with a bit of editing, wouldn't have worked in any version of VB since classes came in in VB4 You failed to ask a very basic question. When given the best possible answer you ranted back. In summing up My Lord, I submit that the defendant is indeed a Doofus and should be shown no mercy. The case for the prosecution rests.


          Panic, Chaos, Destruction. My work here is done.

          1 Reply Last reply
          0
          • S Samir Ibrahim 0

            You have 10 years experience in C++, 2 years in C# Since the algorithm and principals (thinking of solving the problem) is the same almost in all language. can you compare your self for learning let say "Delphi" with someone who has no programming experience at all?

            Like car accidents, most hardware problems are due to driver error. Samir R. Ibrahim

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #25

            Samir Ibrahim wrote:

            You have 10 years experience in C++, 2 years in C#

            No, I have 18 years in C++, 2 in C#, 8 in Pascal, and a number of years in more obscure languages on systems that were not PCs. I've been programming for a living for 30 years.

            Samir Ibrahim wrote:

            Since the algorithm and principals (thinking of solving the problem) is the same almost in all language.

            Old news - I discovered that in 1981.

            Samir Ibrahim wrote:

            can you compare your self for learning let say "Delphi" with someone who has no programming experience at all?

            Delphi is Pascal, so no, I can't compare the two since I already know Pascal. What point are you failing to make?

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            1 Reply Last reply
            0
            • S Samir Ibrahim 0

              You have 10 years experience in C++, 2 years in C# Since the algorithm and principals (thinking of solving the problem) is the same almost in all language. can you compare your self for learning let say "Delphi" with someone who has no programming experience at all?

              Like car accidents, most hardware problems are due to driver error. Samir R. Ibrahim

              N Offline
              N Offline
              Nagy Vilmos
              wrote on last edited by
              #26

              Speaking for myself, I doubt I would make such a fundamental mistake.


              Panic, Chaos, Destruction. My work here is done.

              1 Reply Last reply
              0
              • realJSOPR realJSOP

                Samir Ibrahim wrote:

                6 month of learning vb.net

                Six months of "learning VB.net" makes you a rank amateur, a newbie, a mere child. It took me ten years to get to a point where I felt comfortable in my knowledge of C++. I've been doing C# for just two years (about 7 years less than almost everyone else here), and while I feel pretty comfortable with it, I wouldn't call myself "accomplished". And while I realize that this is the VB forum, saying you code in VB is like admitting you use AOL to get on the internet.

                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                S Offline
                S Offline
                Samir Ibrahim 0
                wrote on last edited by
                #27

                John Simmons / outlaw programmer wrote:

                Six months of "learning VB.net" makes you a rank amateur, a newbie, a mere child

                I agree 100%. Who said that I want from you to consider me an expert? Just take into consideration my programming experience because it make a lot of difference from dealing with no experience.

                Like car accidents, most hardware problems are due to driver error. Samir R. Ibrahim

                1 Reply Last reply
                0
                • realJSOPR realJSOP

                  Jon_Boy wrote:

                  Hey now, I can understand bashing the OP, but the rest of us?

                  I am an equal-opportunity abuser.

                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                  J Offline
                  J Offline
                  Jon_Boy
                  wrote on last edited by
                  #28

                  John Simmons wrote:

                  I am an equal-opportunity abuser.

                  Jon-boy lowers his head and prepares to be clubbed for his deep rooted love of VB.

                  Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                  1 Reply Last reply
                  0
                  • N Nagy Vilmos

                    Okay, Dave and Ellain have been nice to you. I won't be: Your code example was sh!t. Your knowledge of OO principles is w!nk. A rabid monkey knows more than you. Is that clear enough or do you need it carved on stone and shoved up your manky a...?


                    Panic, Chaos, Destruction. My work here is done.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #29

                    *cough* name is Elliott, not Ellain *cough*

                    Check out the CodeProject forum Guidelines[^]

                    N 1 Reply Last reply
                    0
                    • L Lost User

                      *cough* name is Elliott, not Ellain *cough*

                      Check out the CodeProject forum Guidelines[^]

                      N Offline
                      N Offline
                      Nagy Vilmos
                      wrote on last edited by
                      #30

                      I wouldn't call Trollslayer Elliot as she'd scratch me.


                      Panic, Chaos, Destruction. My work here is done.

                      1 Reply Last reply
                      0
                      • S Samir Ibrahim 0

                        williamnw wrote:

                        you are asking why writing a function (forget that it's a property for the moment) without returning a value causes a compiler warning that there is no value returned?

                        Where I mention that I am not returning a value for the function? show me. here is my question

                        Public Class myclass1
                        Function Sum()
                        Sum = 1 + 2 ' <-- Works Fine
                        Me.Sum = 1 + 2 ' <-- Gives error although me.Sum should be the same as Sum alone
                        End Function
                        End Class

                        Like car accidents, most hardware problems are due to driver error. Samir R. Ibrahim

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #31

                        Public Class myclass1
                        ' It's "best practice" to explicitly declare visibility of the Function and to
                        ' define it's return type if you're not using LINQ, or some other technology
                        ' that will try to imply the return type for you based on possible values that
                        ' the code might return.
                        Public Function Sum() As Integer
                        ' You haven't defined Sum anywhere, except as a function name. VB6 supported just
                        ' treating the function name as the return value holder. You should NOT be using
                        ' practice in VB.NET. It is only there for backward compatibility with converted
                        ' VB6 code.
                        Sum = 1 + 2 ' <-- Works Fine

                            ' Now you're treating Sum not as a variable, as in the previous line, but as an object
                            ' or property.  This will not work since Sum, outside of it's own code, cannot be
                            ' as a variable since, in true OOP, it's a method name.
                            Me.Sum = 1 + 2  ' <-- Gives error although me.Sum should be the same as Sum alone
                        
                            ' It is considered "best practice" to explicitly declare a single Return statement.
                            Return x
                         End Function
                        

                        End Class

                        Serisouly, VB6 and VFP have taught you some very bad habits that are not supported in the true OOP world of VB.NET. I still highly recommend picking up a book on VB.NET so you can learn how the basics are really supposed to work, instead of the garbage VFP taught you.

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                             2006, 2007, 2008

                        1 Reply Last reply
                        0
                        • S Samir Ibrahim 0

                          Hi all in VFP, When I begin to work with a project, I create control that is a subclass of it is baseclass, then I code what I want to this subclass, then I drag it and put it on the form. and I use this subclass in all my forms later on. Now to make that in vb.net I found the UserControl is the closet control to do what I want. Q1: Is UserControl is the right direction to achieve what I want? I have did some tests on UserControl and I have these questions 1- Why it gives warning in 'Me.Version = "1.0" 2- Why it gives warning and my vb crashes and could not be restarted unless I close all vb IDE's in Version = value 3- Should I assign a new variable (m_version) for each property I want to add? Cannot I work directly with property? 4- When I drag the control to my form, I notice that the control (Textbox) (width and height) are not expanded to take the the Length and Height of the Usercontrol. Should I handle that manually? 5- I have included many code in the Get, so I would like to know what is the best I should use.

                          Public Class UserControl1 ' I add Textbox
                          Dim m_Version
                          Property Version()
                          Get
                          'Version = "1.0" ' Worked Fine
                          'Me.Version = "1.0" ' Warning 3 Property 'Version' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
                          'Return "1.0" ' Worked Fine
                          Return m_Version ' Worked Fine
                          End Get
                          Set(ByVal value)
                          m_Version = value ' Works Fine
                          'Version = value ' Warning 3 Expression recursively calls the containing property 'Version'.
                          End Set
                          End Property
                          End Class

                          TIA

                          Like car accidents, most hardware problems are due to driver error. Samir R. Ibrahim

                          D Offline
                          D Offline
                          DidiKunz
                          wrote on last edited by
                          #32

                          I normaly type my variables and properties in .NET like so:

                          Public Class UserControl1 ' I add Textbox
                          Dim m_Version As String
                          Property Version() As String
                          Get
                          'Version = "1.0" ' Worked Fine
                          'Me.Version = "1.0" ' Warning 3 Property 'Version' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
                          'Return "1.0" ' Worked Fine
                          Return m_Version ' Worked Fine
                          End Get
                          Set(ByVal value) As String
                          m_Version = value ' Works Fine
                          'Version = value ' Warning 3 Expression recursively calls the containing property 'Version'.
                          End Set
                          End Property
                          End Class

                          But it probably realy would make sense to make the Property readonly. Regards: Didi

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups