Best way to store code snippets

Started by mjwillyone, August 23, 2021, 03:28:03 PM

Previous topic - Next topic

mjwillyone

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

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

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

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

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

Quote from: mjwillyone on August 24, 2021, 06:34:00 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

Quote from: jmburton2001 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

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

JTaylor

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

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

Quote from: mjwillyone on August 25, 2021, 01:07:40 PMIs 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

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

Quote from: stanl 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.

JTaylor

I actually found it.  Last updated in 2006 :)

Jim

stanl

Quote from: JTaylor on August 26, 2021, 10:21:29 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


stanl

Quote from: JTaylor on August 27, 2021, 12:22:00 PM
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

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

Quote from: mjwillyone 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?


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

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

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

Quote from: stanl 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.


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.


$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

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

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

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. 


$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

Quote from: stanl 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.

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


stanl

Quote from: mjwillyone on September 08, 2021, 11:34:00 AM
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