VS 2008 [RESOLVED] Shorten Code-VBForums
Results 1 to 17 of 17

Thread: [RESOLVED] Shorten Code

  1. #1

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Resolved [RESOLVED] Shorten Code

    I would like to make my code shorter.
    I would like to make it so instead of textbox1.text it would be txtbx1.txt.

    How can I do this? I tried doing some DIM's, but it didn't work.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,120

    Re: Shorten Code

    TextBox1 is the name of the control, which you generally set in the properties of the control in the designer. In fact, it's a good idea to always rename your controls rather than using the default name, so shorten them as much as you like.

    However, there is no advantage to shortening the names, so it is best to use names that are long enough that you can identify the controls easily. After all, the controls all show up in intellisense, so you generally never type the whole control name.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Re: Shorten Code

    So how would I change the control?

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,120

    Re: Shorten Code

    In the properties window when in the form designer is the best and easiest way.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Re: Shorten Code

    I see what your saying. But I want to change other things. for example, console.writeline to cnsl.wl. I would like it to change thing that do not have properties

  6. #6

  7. #7

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Re: Shorten Code

    Yes you can. I've seen it before

  8. #8

  9. #9
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,399

    Re: Shorten Code

    You can by creating a wrapper class, e.g.
    Code:
    Option Strict On
    Option Explicit On
    
    Public Class cnsl
    
        Public Shared Sub wl(l As String)
            Console.WriteLine(l)
        End Sub
    
        Public Shared Function rl() As String
            Return Console.ReadLine
        End Function
    
    End Class
    But do you really need so?!



  10. #10
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: Shorten Code

    Quote Originally Posted by 4x2y View Post
    You can by creating a wrapper class, e.g.
    Code:
    Option Strict On
    Option Explicit On
    
    Public Class cnsl
    
        Public Shared Sub wl(l As String)
            Console.WriteLine(l)
        End Sub
    
        Public Shared Function rl() As String
            Return Console.ReadLine
        End Function
    
    End Class
    But do you really need so?!
    you are missing my point. WHY!!!!

    *edit just seen bottom lines

  11. #11

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Re: Shorten Code

    Thank you

  12. #12

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Re: Shorten Code

    Do you know if I have to have strict and explicit on?

  13. #13
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,399

    Re: Shorten Code

    Quote Originally Posted by kshadow22 View Post
    Do you know if I have to have strict and explicit on?
    They are optional but it is highly recommended to always turn them on, because they will save a lot of debugging time, specially "Explicit On"
    Last edited by 4x2y; Feb 21st, 2015 at 12:54 AM.



  14. #14
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: [RESOLVED] Shorten Code

    Why would you want to do this OP? This will effect the readability of your code, and in my opinion, it's a terrible idea.

    Why would anyone want cnsl.wl("")
    that it an meaningful name. Console.WriteLine() is much clearer and read able. Honestly just leave it the way it is.

  15. #15

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Re: [RESOLVED] Shorten Code

    When I get deep into coding, I would like just to be able to type codes with the fewest amount of codes. Especially when I am dealing with encryptions.

  16. #16
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: [RESOLVED] Shorten Code

    Quote Originally Posted by kshadow22 View Post
    When I get deep into coding, I would like just to be able to type codes with the fewest amount of codes. Especially when I am dealing with encryptions.
    Not by shortening the actual class names and methods. You should leave them as they are, but you should aim to write readable and neat code. Condensing something like Console.WriteLine() into cnsl.wl("") is just the worst idea I've ever heard since I started programming. What if you were to give that code to another programmer to read? Don't adopt these bad habits. I don't see what encryption has to do with this

  17. #17
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: [RESOLVED] Shorten Code

    Quote Originally Posted by kshadow22 View Post
    When I get deep into coding, I would like just to be able to type codes with the fewest amount of codes. Especially when I am dealing with encryptions.
    so all of us who have been programmers for years are wrong? dealing with encryptions..... maybe in 5 years you might be.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.