Author Topic: Best way to store code snippets  (Read 717 times)

mjwillyone

  • Newbie
  • *
  • Posts: 45
Best way to store code snippets
« on: August 23, 2021, 03:28:03 pm »
So .. I am wanting to store code snippets that I would like to use later to speed up future work

I am curious ...  where/how do you store code for easy retrieval?   I'd love a way that would let me categorize my code (i.e. Code to use with Excel, Error handling, etc)

Thanks much!!
Mike

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #1 on: August 24, 2021, 02:55:56 am »
I doubt there is a 'best way'... For a long time I would store my favorite UDF's in Access memo fields with associated text field identifiers. Access was also useful to store compiled .wbc code as binary field - both easily extractable. Of course there is always sub-folders.

kdmoyers

  • Sr. Member
  • ****
  • Posts: 427
Re: Best way to store code snippets
« Reply #2 on: August 24, 2021, 05:33:02 am »
Speaking for myself, the challenge is not so much where I store the code (it's all sitting there in a folder) but what I name the functions and what I say in the comments, because this is what helps me find the right thing a couple years later.  So, I try to resist my tendency to use names like NextOp in favor of better names like PopOperationFromLIFOStack.
$0.02
-Kirby
The mind is everything; What you think, you become.

mjwillyone

  • Newbie
  • *
  • Posts: 45
Re: Best way to store code snippets
« Reply #3 on: August 24, 2021, 06:34:00 am »
Thanks to both of you.  I did an internet search and found a number of options.  I prefer a Windows option but there are more Internet based tools out there.

I would love to find a Windows app that allows me to categorize my code with 1 word on the left frame that when clicked opens the code in a main window on the right.

I’m still looking.  Access may be able to do that??

Mike

jmburton2001

  • Full Member
  • ***
  • Posts: 110
Re: Best way to store code snippets
« Reply #4 on: August 24, 2021, 06:41:58 am »
I've been a hobbyist with Winbatch since the mid 1990's. My coding style (if you could call it that) lends itself to consistent use of certain functions. What I've done over time is create a "base" Winbatch file that I pull up whenever I start a new project. It contains my most used functions and commands that I can modify (or delete if not needed) for the particular project I'm working on. It's my low-tech hobbyist solution.

As Kirby said... $0.02

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #5 on: August 24, 2021, 10:11:38 am »

I’m still looking.  Access may be able to do that??

Mike


It's trivial.  Create Table with 5 fields [or 3 if binary and type not needed]
title:  short text
keywords: short text
type: boolean [ true=memo, false = binary]
code: memo
wbc: binary   [optional, but wbc files are quite useful with the call command]


wbc files inserted with WB ADO Stream....


then simple dialog, button to choose keyword(s), dropdown to display all related titles, show multi-line text for memos, or extract .wbc locally....

mjwillyone

  • Newbie
  • *
  • Posts: 45
Re: Best way to store code snippets
« Reply #6 on: August 25, 2021, 01:07:40 pm »
I've been a hobbyist with Winbatch since the mid 1990's. My coding style (if you could call it that) lends itself to consistent use of certain functions. What I've done over time is create a "base" Winbatch file that I pull up whenever I start a new project. It contains my most used functions and commands that I can modify (or delete if not needed) for the particular project I'm working on. It's my low-tech hobbyist solution.

As Kirby said... $0.02

Is it just one very large WB file?  Is there a particular way that you sort these?

JTaylor

  • Pundit
  • *****
  • Posts: 1717
    • Data & Stuff Inc.
Re: Best way to store code snippets
« Reply #7 on: August 25, 2021, 01:52:25 pm »
I do the same as Kirby.   It is one file for me.   "large" is a subjective term but I have never noticed any problems using this method.   I don't sort mine.  I just do a search if I need to see the function.  If you have several hundred or thousands of functions you may want to break that up into types.  You could create one script that uses #include calls to the various scripts broken up by type.  That would allow you to easily exclude any groups you didn't need for a particular project and lower the number of functions that get loaded.

There is Stan's suggestion of using a database to store them.   You could even create groups as mentioned above and/or assign them to projects/apps so you could generate a file of all the functions you want included in something and if you make changes you could easily re-generate the file from the main database again without having to make multiple changes.

Jim

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #8 on: August 26, 2021, 05:35:16 am »
Jim;


Speaking of databases... didn't we [years ago] work out a method to put the entire WB Tech DB into a database and wasn't it available as a download. In terms of organizing by topic=>subcategory it is nicely done. Of course a lot of new sections have been created since then, like dotNet but the process is pretty much:
  • extract hrefs from HTML in web pages, looping down to subsections, individual posts.
  • parse topic->subtopic->sub-subtopic->text into db fields.
  • create retrieval dialog
Then I was thinking Tony had done this and entire tech db could be downloaded.  Obviously I lot of stuff that is dated, but a lot more that is nice to have as a query reference.

jmburton2001

  • Full Member
  • ***
  • Posts: 110
Re: Best way to store code snippets
« Reply #9 on: August 26, 2021, 06:41:11 am »
Is it just one very large WB file?  Is there a particular way that you sort these?

It's "somewhat" large. I use a ;===== COMMENT LINE ===== to put in a description in my own words and then just perform a simple search for that description/section.

Depending on the project I may open a new file beside this one and then copy/paste between them.

Like I said...low tech (and $0.02).

JTaylor

  • Pundit
  • *****
  • Posts: 1717
    • Data & Stuff Inc.
Re: Best way to store code snippets
« Reply #10 on: August 26, 2021, 10:18:59 am »
Yes.   Not sure if that is still an option or not.   I seem to remember being involved in that project but a bit fuzzy now.   Will have to search around in my directories.

Jim

Jim;


Speaking of databases... didn't we [years ago] work out a method to put the entire WB Tech DB into a database and wasn't it available as a download. In terms of organizing by topic=>subcategory it is nicely done. Of course a lot of new sections have been created since then, like dotNet but the process is pretty much:
  • extract hrefs from HTML in web pages, looping down to subsections, individual posts.
  • parse topic->subtopic->sub-subtopic->text into db fields.
  • create retrieval dialog
Then I was thinking Tony had done this and entire tech db could be downloaded.  Obviously I lot of stuff that is dated, but a lot more that is nice to have as a query reference.

JTaylor

  • Pundit
  • *****
  • Posts: 1717
    • Data & Stuff Inc.
Re: Best way to store code snippets
« Reply #11 on: August 26, 2021, 10:21:29 am »
I actually found it.  Last updated in 2006 :)

Jim

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #12 on: August 27, 2021, 02:18:52 am »
I actually found it.  Last updated in 2006 :)

Jim


An .mdb not an .accdb... I probably have it on a USB archive. How time flies.

JTaylor

  • Pundit
  • *****
  • Posts: 1717
    • Data & Stuff Inc.
Re: Best way to store code snippets
« Reply #13 on: August 27, 2021, 12:22:00 pm »
Yep.  That it does...

Jim

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #14 on: August 28, 2021, 08:02:17 am »
Yep.  That it does...

Jim


I think I found it also... just can't open it. Error: cannot open file saved in previous version.... seems like Office 2013 or greater doesn't like older .mdb format. The suggestion from Microsoft, of course, is to open with an earlier office version, like 2010 and convert the .mdb to .accdb .... yah sure!!! I remember the thing about upgrading to 2013/16/19 was to completely remove earlier versions.

mjwillyone

  • Newbie
  • *
  • Posts: 45
Re: Best way to store code snippets
« Reply #15 on: August 29, 2021, 11:46:41 am »
I’ve got an active Office 2007… can I help you get it into a format you can use?  Where do I find the file?

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #16 on: August 30, 2021, 12:14:52 pm »
I’ve got an active Office 2007… can I help you get it into a format you can use?  Where do I find the file?


To be honest, I assumed my file db.mdb was correct.  Probably a better approach is to see the code that built it, and to again be honest I cannot locate that.  2006 was not a good year.


Jim... can you help out here???

JTaylor

  • Pundit
  • *****
  • Posts: 1717
    • Data & Stuff Inc.
Re: Best way to store code snippets
« Reply #17 on: August 30, 2021, 02:21:03 pm »
Hmmmmmm....after I initially created something for myself and mentioned it (assuming my memory is correct) I think Marty started populating the database and posting it occasionally.  I can post the script I use to read it and maybe find code that initially populated it.   Which do you want, assuming I can find it?

Jim

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #18 on: August 31, 2021, 06:21:47 am »
I found my original 2005 code. Used IE and .links DOM... Not really useful and never made it to the tech db as a script.

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #19 on: August 31, 2021, 11:06:18 am »
I found my original 2005 code. Used IE and .links DOM... Not really useful and never made it to the tech db as a script.


God! Not even worth going back to 2005. With all the changes and IE being replaced by Edge... simple web-scraping may not be that simple.  But, Powershell provides as easy out...  [and can be implemented from WB via CLR].... Below at least gets latest href links from Tech DB.... putting those into a db table shouldn't be that difficult.
Code: [Select]

$file = "C:\scripts\wbtechsupt.txt" #change as needed
$varout = ""
$url = Invoke-WebRequest -Uri https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch
$links = $url.Links.Href | Sort-Object | Get-Unique
foreach ($lnk in $links) {
 if ($lnk -Match "nftechsupt.web") {
 $url1 = Invoke-WebRequest -Uri $lnk
 $links1 = $url1.Links.Href | Sort-Object | Get-Unique
 foreach ($lnk1 in $links1) {
   if ($lnk1 -Match "nftechsupt.web") {
   $varout = $varout + $lnk1 + "`n"
   }
 }
 }
 }
 $varout | Out-File $file




on my PC output file was around 951kb...

JTaylor

  • Pundit
  • *****
  • Posts: 1717
    • Data & Stuff Inc.
Re: Best way to store code snippets
« Reply #20 on: August 31, 2021, 12:02:55 pm »
Maybe Tony will find what they were doing before and drop a file or db out there, if it is deemed worth the time.   Guess one in sqlite format would work well since there is an extender for that :-)

Jim

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #21 on: August 31, 2021, 12:29:36 pm »
Yeah, the Powershell only went down 2 levels...  but
url.ParsedHtml.body.IHTMLElement_outerText  gets each article text.... good to see the PS keeps most of the mshtml elements so webscraping is not totally detached from previous practices.

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #22 on: August 31, 2021, 05:23:36 pm »
enough is enough... think the original intent of the thread was hijacked... but to be fair.... I expanded my PS script to drill down another level and wrote to the output file per the third level.. it ran for over an hour, I stopped it and it was down to Miscellaneous with over 142,000 links..  so looks like we been busy since 2005.  I may just tweak it to look for keywords like 'Excel' or just obtain links from the dotNet section. 
Code: [Select]

$file = "C:\scripts\wbtechsupt.txt" #change as needed
$varout = ""
$url = Invoke-WebRequest -Uri https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch
$links = $url.Links.Href | Sort-Object | Get-Unique
foreach ($lnk in $links) {
   if ($lnk -Match "nftechsupt.web") {
    $url1 = Invoke-WebRequest -Uri $lnk
    $links1 = $url1.Links.Href | Sort-Object | Get-Unique
    foreach ($lnk1 in $links1) {
       if ($lnk1 -Match "WinBatch/") {
       $url2 = Invoke-WebRequest -Uri $lnk1
       $links2 = $url2.Links.Href | Sort-Object | Get-Unique
       foreach ($lnk2 in $links2) {
         if ($lnk2 -Match "WinBatch/") {
         $varout = $varout + $lnk2 + "`n"
   }
   }
   Set-Content -Path $file -Value $varout
   }
 }
 }
 }
 Set-Content -Path $file -Value $varout

td

  • Tech Support
  • *****
  • Posts: 3872
    • WinBatch
Re: Best way to store code snippets
« Reply #23 on: September 03, 2021, 09:42:26 am »
Yeah, the Powershell only went down 2 levels...  but
url.ParsedHtml.body.IHTMLElement_outerText  gets each article text.... good to see the PS keeps most of the mshtml elements so webscraping is not totally detached from previous practices.

In Windows 11 it appears that  "WinHttp.WinHttpRequest.5.1" COM Automation server as well as "Microsoft.XMLHTTP.1.0" are supported. This means the Web scraping using WinBatch's COM Automation client system will still be possible in Windows 11 as it is when running Windows 10.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mjwillyone

  • Newbie
  • *
  • Posts: 45
Re: Best way to store code snippets
« Reply #24 on: September 08, 2021, 11:34:00 am »
Yep hijacked!

stanl

  • Pundit
  • *****
  • Posts: 1534
Re: Best way to store code snippets
« Reply #25 on: September 08, 2021, 12:34:03 pm »
Yep hijacked!


It is what it is. But I updated my script to scrape the latest tech db, still use Access but easily converted to SQLite per Jim's Extender