Results 1 to 19 of 19

Thread: VB - Format your code for copying

  1. #1

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    VB - Format your code for copying

    Ever had the problem of copying VB code into a word file (or other text editor) and finding that all the colour and font formatting is lost?
    Well with this you can copy the code into the rich text box and press format and it goes through the contents of the box and changes all comments to green and all the vb Keywords to blue, so it looks just like it does in the VB editor!
    Very useful for students like myself wanting to put their in a word file for documentation for coursework etc...

    EDIT: Latest version now here:
    Attached Files Attached Files
    Last edited by Arachnid13; May 11th, 2005 at 04:41 PM. Reason: Updating Attachment
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  2. #2
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: VB - Format your code for copying

    VERY useful, thankyou, and working well

    Keep up the good work
    Zeegnahtuer?

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

    Re: VB - Format your code for copying

    Very, very nice. I added one thing, and that was to make the Keyword listbox sorted so they are displayed alphabetically.

    (Once that was done I noticed that Replace and Split were missing, so I just added them to the Keyword CONST.)

    This will be useful.

  4. #4

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: VB - Format your code for copying

    @ Hack:

    Thanks for that, i guessed id probably missed some words, ill add them in and post it again next time im online on my pc, ill add the alphabetical sort too. If anyone notices any other words missin then please post them on here so i know.
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

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

    Re: VB - Format your code for copying

    I added these to the Const:

    ¦Split¦Replace¦ParamArray¦Declare¦Select¦Me¦Resume¦On¦Error¦GoTo¦In¦Call¦Is¦Nothing¦W ith¦IsNumeric¦IsDate¦" + _
    "CDec¦CBool¦CByte¦CCur¦CDate¦CDbl¦CDec¦CInt¦CLng¦CSng¦CStr¦CVar¦IsNull¦Abs¦IsEmpty¦Ty pe"

    At some point, I think I going to create a Access Db table to hold them. That way, if you actually do "Add" or "Remove" a keyword, it will, or will not, be available the next time you run the program.

  6. #6

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: VB - Format your code for copying

    yea, the two you gave me yesterday, "Replace" and "Split" dont actually show up blue in the vb editor... i missed "With" as well from the original
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  7. #7

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: VB - Format your code for copying

    oops just noticed you already said about "With"!
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

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

    Re: VB - Format your code for copying

    Quote Originally Posted by Arachnid13
    yea, the two you gave me yesterday, "Replace" and "Split" dont actually show up blue in the vb editor... i missed "With" as well from the original
    Yes, I know, but in so far as the code formatter will be for individual use, anyone can put in whatever they want as highlighted keywords. I've always felt those two should be blue anyway.

  9. #9

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: VB - Format your code for copying

    yea i guess, well here's the updated version, it sorts the listbox now and instead of using a keyword constant, it accesses the "KeywordList.txt" file, just make sure you either put the file in your vb folder (or in the same folder as the app if u compile it) or change the line "Directory = App.Path" to the directory that you have the file in... (it's in the Form_Load() event)
    Attached Files Attached Files
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

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

    Re: VB - Format your code for copying

    Cool. Nice catch on the "Lib" keyword by the way. I missed that one as well.

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

    Re: VB - Format your code for copying

    Here is what I'm currently using for keywords:

    Const DEFAULT_KEYWORDS = "Dim¦Const¦Private¦Public¦Global¦As¦Boolean¦Byte¦Currency¦Date¦Double¦Empty¦Integer¦Lon g¦Single¦String¦Variant¦" + _
    "For¦To¦Next¦Step¦If¦Not¦And¦Or¦Xor¦Else¦ElseIf¦End¦Then¦True¦False¦Do¦Loop¦Until¦ While¦Wend¦Sub¦Function¦Optional¦Exit¦Set¦New¦Option¦Explicit¦" + _
    "Case¦Open¦Close¦Print¦Input¦Get¦Put¦Debug¦Split¦Replace¦ParamArray¦Declare¦Select¦Me¦ Resume¦On¦Error¦GoTo¦In¦Call¦Is¦Nothing¦With¦IsNumeric¦IsDate¦" + _
    "CDec¦CBool¦CByte¦CCur¦CDate¦CDbl¦CDec¦CInt¦CLng¦CSng¦CStr¦CVar¦IsNull¦Abs¦IsEmpty¦Ty pe¦Lib¦IsArray"

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB - Format your code for copying

    Keywords copied+pasted from that wonderful piece of software, Notepad++.
    There are a whole lot of VB.NET ones in there as well.

    Code:
    addhandler addressof andalso alias and ansi as assembly attribute
    auto begin boolean byref byte byval call case catch cbool cbyte
    cchar cdate cdec cdbl char cint class clng cobj compare const
    continue cshort csng cstr ctype currency date decimal declare
    default delegate dim do double each else elseif end enum erase
    error event exit explicit false finally for friend function get
    gettype global gosub goto handles if implement implements imports
    in inherits integer interface is let lib like load long loop lset
    me mid mod module mustinherit mustoverride mybase myclass
    namespace new next not nothing notinheritable notoverridable
    object on option optional or orelse overloads overridable
    overrides paramarray preserve private property protected public
    raiseevent readonly redim rem removehandler rset resume return
    select set shadows shared short single static step stop string
    structure sub synclock then throw to true try type typeof unload
    unicode until variant wend when while with withevents writeonly xor

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

    Re: VB - Format your code for copying

    Cool! I added a bunch more keywords based on your thread penagate!

  14. #14
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: VB - Format your code for copying

    A couple of things :

    In Form_Load :
    1) There is no need for Directory = "D:\", and you can use this : If Right$(Directory, 1) <> "\" Then Directory = Directory & "\" to make sure you have the backslash at the end.

    2) In cmdAdd_Click, to not add anything if the user presses cancel, you can use this :

    VB Code:
    1. Private Sub cmdAdd_Click()
    2. Dim i As Long
    3. Dim sInput As String
    4.  
    5. sInput = InputBox("Enter a new keyword", "Arachnid Software")
    6. If StrPtr(sInput) <> 0 Then
    7.     lstKeywords.AddItem sInput
    8.    
    9.     Open Directory + "KeywordList.txt" For Output As #1
    10.     For i = 0 To lstKeywords.ListCount - 1
    11.         Print #1, lstKeywords.List(i)
    12.     Next i
    13.     Close #1
    14. End If
    15.  
    16. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  15. #15
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: VB - Format your code for copying

    Quote Originally Posted by manavo11
    A couple of things :

    In Form_Load :
    1) There is no need for Directory = "D:\", and you can use this : If Right$(Directory, 1) <> "\" Then Directory = Directory & "\" to make sure you have the backslash at the end.
    Why not simply

    Directory = App.Path & "\"

    ?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  16. #16
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: VB - Format your code for copying

    Well, will probably work just as well. You don't check if there is one at the end, you append one anyway. If there is more than one, it will still open the same folder, no difference, so you have a point


    Has someone helped you? Then you can Rate their helpful post.

  17. #17
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: VB - Format your code for copying

    I thought a print option might be useful.
    Attached Files Attached Files
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  18. #18
    Member
    Join Date
    May 2008
    Posts
    47

    Re: VB - Format your code for copying

    Thank you so much for this! I took out the listbox and just stored the keywords in an array and caught the 'Enter' key (ascii 13) to call the code written here. It works just like the VB editor now! Thanks!

  19. #19
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: VB - Format your code for copying

    Thanks....

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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