{"id":6752,"date":"2021-02-27T12:11:42","date_gmt":"2021-02-27T12:11:42","guid":{"rendered":"https:\/\/max-drake.cc\/?p=6752"},"modified":"2021-02-27T13:52:00","modified_gmt":"2021-02-27T13:52:00","slug":"ahk-freezer-inventory","status":"publish","type":"post","link":"https:\/\/max-drake.cc\/?p=6752","title":{"rendered":"AHK Barcode &#038; Freezer Inventory"},"content":{"rendered":"\n<p>After plant watering\/recording app, which I use daily I wanted to move onto the Freezer Inventory. <\/p>\n\n\n\n<p>I have modified the Plant watering app for my beer brew recording, that is mainly typing in rather than barcode reading, but I inputted all the data pretty quickly, so now have a structured file with the data in it, a lot missing, but it&#8217;s a start. <\/p>\n\n\n\n<p>The Freezer inventory app is a bit more challenging. I&#8217;m going to use the template of the Plant watering app, as that has 1\/ A GUI interface with Text to Speech &amp; 2\/ It records data to a file. <\/p>\n\n\n\n<p>For the first try I want to keep this simple and use a<strong> Text file for records<\/strong>, I do not want to move to an Excel\/GSheets spreadsheets with code lookups using VLookup at this point. Although there is this AHK article <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/autohotkey.com\/board\/topic\/90000-please-help-using-of-vlookup\/\" target=\"_blank\">Please Help! Using of VLOOKUP<\/a><\/strong> that I may explore later. <\/p>\n\n\n\n<p>Items that I think I need to make this happen: <\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>popup&nbsp;to&nbsp;add&nbsp;items&nbsp;<\/li><li>Popup&nbsp;to&nbsp;search&nbsp;for&nbsp;items&nbsp;and&nbsp;return<\/li><li>Popup&nbsp;to&nbsp;add&nbsp;to\/take&nbsp;away&nbsp;from&nbsp;current&nbsp;count<\/li><\/ol>\n\n\n\n<p>I also want to use the<strong> <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/hi5\/TF\" target=\"_blank\">Text File Library<\/a><\/strong><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/hi5\/TF\" target=\"_blank\"> <\/a>that has a lot of useful functions that I can use, and I&#8217;ll use<strong> # include tf.ahk <\/strong>to work with some of  the following items in the library:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>TF&nbsp;_Find<\/li><li>TF_Replace<\/li><li>TF_ReplaceInLines<\/li><li>TF_CountLines<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Coding<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"692\" data-src=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-1024x692.jpg\" alt=\"\" class=\"wp-image-6753 lazyload\" data-srcset=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-1024x692.jpg 1024w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-300x203.jpg 300w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-768x519.jpg 768w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-50x34.jpg 50w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-74x50.jpg 74w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-100x68.jpg 100w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-148x100.jpg 148w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-946x640.jpg 946w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-640x433.jpg 640w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel-1136x768.jpg 1136w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_21_46-0-Inventory-Codes.xlsx-Excel.jpg 1254w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/692;\" \/><\/figure>\n\n\n\n<p>The first issue was getting an abbreviation code method that worked. Started witj Letters as abbreviation &#8211; Who For (dog or me, J or M), Raw or Cooked (R,C), then abbreviations for what they were, pretty simple for the dog , only one or 2 letters, for me a bit more elaborate. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"603\" data-src=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-1024x603.jpg\" alt=\"\" class=\"wp-image-6754 lazyload\" data-srcset=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-1024x603.jpg 1024w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-300x177.jpg 300w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-768x452.jpg 768w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-1536x904.jpg 1536w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-50x29.jpg 50w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-85x50.jpg 85w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-100x59.jpg 100w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-170x100.jpg 170w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-1087x640.jpg 1087w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-640x377.jpg 640w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-1305x768.jpg 1305w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-1835x1080.jpg 1835w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/2021-02-24-12_25_25-Freezer-Inventory-Google-Sheets-\u2014-Mozilla-Firefox-scaled.jpg 1600w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/603;\" \/><\/figure>\n\n\n\n<p>So, for just the naming I need to do some abbreviations on the more complex things in the freezer. <\/p>\n\n\n\n<p>The 2nd issue is count. There are individual items , eg Bones, and there are portions, such as a portion of chicken hearts or Giblets, or there are containers with cooked food in a package. <\/p>\n\n\n\n<p>So you can either reduce everything to a single unit in some complex calculation method, or work with at least 3 different quantity units. <\/p>\n\n\n\n<p>In some ways, I should start off with a single count unit, just to get a minimum prototype working, maybe using count, then extend to different  units.  Why is that? See next heading <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Populating file <\/h4>\n\n\n\n<p>The next thing I need to do is populate a file to start with. So best method for this is to have a pop-up GUI that will allow me to easily add things to the existing file. This is simple, the basis of the plant watering app. Just scan in a new code and a number (Quantity). <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Reading &amp; editing file<\/h4>\n\n\n\n<p>This is the biggy. You have to put in a <strong>Key search<\/strong>, so it needs to loop through all the lines in the file to find the one that you want.  <\/p>\n\n\n\n<p>This would be the Code of the item. It would then look up the code and return the quantity. At this point you know how many of the &#8220;code&#8221; thingy are available. <\/p>\n\n\n\n<p>If you use one or 2 of them, you need to be able to deduct this from the current amount in the file, so you need to edit the file for the update. <\/p>\n\n\n\n<p>If you add to the file more of a specific &#8220;code&#8221; then you need to be able to modify the file again as well. <\/p>\n\n\n\n<p>Date\/Time will be your friend here when you change records, you need to overwrite previous date\/times. <\/p>\n\n\n\n<p>The thinking is that you will only have one line pertaining for a single code item and you&#8217;ll modify it every time you do some action such as remove or add more of that specific item and you modify date\/time to identify last time that was updated. <\/p>\n\n\n\n<p>You could create a backup file with the datetime appended to it, so have stored lots of files with previous data, one method of having a record of all the transactions. <\/p>\n\n\n\n<p>I don&#8217;t want to have each transaction as another line in the file otherwise the search function will take longer and longer as the file gets bigger after many transactions. I&#8217;m only interested in what&#8217;s in the freezer at this point, so a simple lean file will be quick to loop through. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Actual working code<\/h2>\n\n\n\n<p>So after all the exploring and trying things, I ended up resolving  issues in the following ways:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Code, description, count &amp; file structure<\/h4>\n\n\n\n<p><strong>Code. <\/strong>As QR codes need to be simple if they are only going to ne 8mm high, I decided on 5 digits. Codes can give a hint of what they mean like<strong> jbone<\/strong> (bones for Jess)  or <strong>jht&amp;v<\/strong> (jess Heart &amp; vege), so you have a bit of an indication of what they mean. <\/p>\n\n\n\n<p><strong>Description<\/strong>. As the code is &#8220;coded&#8221; you need a description to explain what the item is, and this can be verbose :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>jbone<\/strong>&#8211; Jess beef bones, number<\/li><li> <strong>jht&amp;v<\/strong> -Jess Heart &amp; vege cooked meal container<\/li><\/ul>\n\n\n\n<p>As this can vary in length, I put it at the end of the row, therefore it can grow as long as you want without affecting file structure (see below)<\/p>\n\n\n\n<p><strong>Count<\/strong>. Now there will normally less than 10 items in batches, but to allow for some flexibility if you allow for 2 digits you can get up to 99 of anything. So I use 01, 02,&#8230;&#8230;09,10, 11 &#8230;..35, so I need a leading zero on the end of numbers to 9. <\/p>\n\n\n\n<p>As we are using a text file, this is not a problem, as txt files have no issue with a leading zero, whereas , if you brought the file into a spreadsheet it will get rid of the leading zero. As part of my coding learning I decided that I wanted to stick with a simple .txt file format. <\/p>\n\n\n\n<p>The leading zero is important, in that it allows you to have a simple file structure with different count types, such as number, portion &amp; container. <\/p>\n\n\n\n<p><strong>Fle structure<\/strong>. With all the items having the same format, <strong><em>Code, Number, Portion, Container, Date, Description <\/em><\/strong>all the items apart from the last (Description) have a standard length.<\/p>\n\n\n\n<p>jcdrm,08,00,00,26-02-2021,J chicken Drumsticks raw<br>jgibl,00,02,00,26-02-2021,J Giblets raw<br>mshmp,00,05,00,26-02-2021,m shrimp 1kg bag raw 200g\/portion<br>mprwn,00,05,00,26-02-2021,m prawn 1kg bag 200g \/portion<br>mpies,02,00,00,26-02-2021,m pies mince<br>mdump,00,02,00,26-02-2021,m dumplings portions (8 to 10)<br>mroti,10,00,00,26-02-2021,m roti chenai<br>mbacn,00,06,00,26-02-2021,m bacon 4 slices per portion<br>mmuff,08,00,00,26-02-2021,m muffins english breakfast count<br>msw&amp;s,00,00,01,26-02-2021,m sweet &amp; sour pork meal<br>mpkms,00,01,00,26-02-2021,m pork mince portion 500g<br>mtots,00,05,00,26-02-2021,m tatertots bag 750g<br>mbpat,02,00,00,26-02-2021,m beef burger patties<br>mfrnk,00,05,00,26-02-2021,m frankfurters portion<\/p>\n\n\n\n<p>When you do a search for a code, it returns a row of data, which is basically a long string. <\/p>\n\n\n\n<p>Although we used variables to put this information into the file in a specific method, once in the text file it is just a string, with deliminators between them.<\/p>\n\n\n\n<p>So on retrival of a searched code you get a row of data you can use SubSt() to assign each part a new variable and can therefore do string manipulation on those substrings. <\/p>\n\n\n\n<p>So once the specific string is broken down into variables you can then update those variables and pus them back into the file, updated to new condition. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Process<\/h3>\n\n\n\n<p>Although I had a script setup for submitting new items to the file, I actually found it easier just to use Google Sheets and a concatenation process to set it all up, it went a lot quicker. <\/p>\n\n\n\n<p>I&#8217;ve started using if\/else statements to simplify the input areas (eg if portion is not 00 then only show portion (for editing) and auto-populte number, container with 00. So this speeds up the process of setup. <\/p>\n\n\n\n<p>I was miserly with label tape and only printed the QR code, the rest I did by hand<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Text file line modify\/line delete.<\/h4>\n\n\n\n<p>I used the tf.ahk library (mentioned above) and spent a lot of time with it with minimal success, then found a simple function online that would delete a line in a file by looping though all the lines and re-writing them apart from the line that you want to delete. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Barcode scanner Enter command<\/h4>\n\n\n\n<p>When doing search, there is a pop-up inputbox that you need to put in code , then press enter. Also the Gui for altering the string returned needed a press OK at the bottom, another Enter.<\/p>\n\n\n\n<p>With the plants input for scanner you have Data + Tab or Data+ Carriage return (enter). I wanted just Enter on its own and couldn&#8217;t find it in the codebook, so I thought I&#8217;d try AHK <em>Send, {Enter}<\/em> and that seemed to work. So I didn&#8217;t have to reconfigure settings on the scanner.<\/p>\n\n\n\n<p>So, I haven&#8217;t refined the code yet to see if I can remove the enter buttons but just scan a <em>Send, {Enter}<\/em> QR code and that works. <\/p>\n\n\n\n<p>For the moment its another step, but the process is robust. I can always refine the code later. Great to know that there is a hack for that without reprogramming scanner. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">End comment<\/h2>\n\n\n\n<p>An interesting project fro learning about file \/string manipulation. I have a working process, so will use and see if its effective and usable. <\/p>\n\n\n\n<p>I&#8217;m glad I used the Text file instead of spreadsheet, evilC had some code on using bar scanner with excel, and it&#8217;s a bit complex and you have to fire up excel and a specific file to use. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code for download<\/h3>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/drive.google.com\/file\/d\/1HKuPzQchRTvl8fvzMn76RUJ0scGThWek\/view?usp=sharing\" target=\"_blank\"><strong>0-InventoryEdit.ahk <\/strong><\/a>&nbsp;, <a rel=\"noreferrer noopener\" href=\"https:\/\/drive.google.com\/file\/d\/1s6jko8h8GrC_bUw4S7m9YbXL8GuOnPzZ\/view?usp=sharing\" target=\"_blank\"><strong>0-InventoryNew.ahk<\/strong><\/a>, <a rel=\"noreferrer noopener\" href=\"https:\/\/drive.google.com\/file\/d\/1u-7UIhhaIcpTmBMAy3ftUizCM2sDkOMK\/view?usp=sharing\" target=\"_blank\"><strong>0-FreezerInv.csv<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>After plant watering\/recording app, which I use daily I wanted to move onto the Freezer Inventory. I have modified the Plant watering app for my beer brew recording, that is mainly typing in rather than barcode reading, but I inputted all the data pretty quickly, so now have a structured file with the data in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6757,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[204,464,42],"tags":[],"class_list":["post-6752","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-automation","category-barcode-scanner","category-productivity"],"featured_image_src":"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/IMG20210228130033-600x400.jpg","featured_image_src_square":"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/02\/IMG20210228130033-600x600.jpg","author_info":{"display_name":"Max Drake","author_link":"https:\/\/max-drake.cc\/?author=1"},"_links":{"self":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/6752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6752"}],"version-history":[{"count":0,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/6752\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/media\/6757"}],"wp:attachment":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}