﻿{"id":5290,"date":"2014-04-11T06:05:16","date_gmt":"2014-04-10T21:05:16","guid":{"rendered":"http:\/\/fujiitoshiki.com\/improvesociety\/?p=5290"},"modified":"2014-08-09T15:05:41","modified_gmt":"2014-08-09T06:05:41","slug":"how-to-fix-the-text-file-of-the-food-composition-of-the-diet-recipes-to-the-first-normal-form","status":"publish","type":"post","link":"https:\/\/www.fujiitoshiki.com\/improvesociety\/?p=5290","title":{"rendered":"How to fix the text file of the food composition of the diet recipes to the first normal form?"},"content":{"rendered":"<div class=\"theContentWrap-ccc\"><p>In this article, I&#8217;d like to describe how to fix the text file of the food composition of the diet recipes, which a facility have provided for one year, to the first normal form in order to insert into database. <\/p>\n<pre class=\"toolbar-overlay:true lang:vb decode:true\">Option Explicit\r\n\r\nSub LoopProcedure()\r\n    Dim Sh  As Worksheet\r\n    For Each Sh In Worksheets\r\n        If Sh.Name Like \"Sheet\" & \"*\" Then\r\n            Call TransportFromTxtToCSV(Sh)\r\n        End If\r\n    Next Sh\r\nEnd Sub\r\n\r\nSub TransportFromTxtToCSV()\r\n    Dim mySht               As Worksheet\r\n    Dim myRng               As Range\r\n    Dim myAr                As Variant\r\n    Dim RecAr()             As String\r\n    Dim i                   As Long\r\n    Dim j                   As Long\r\n    Dim k                   As Long\r\n    Dim Date_Serving_Meal   As Date\r\n    Dim Menu_Name           As String\r\n    Dim tmpStart            As Long\r\n    Dim Meal_Time           As String\r\n    Dim Dish                As String\r\n    Dim RecordNumber        As Long\r\n    \r\n    set mysht = sh\r\n    RecordNumber = Count_Record(mySht)\r\n    ReDim RecAr(RecordNumber - 1, 51)\r\n    Set myRng = mySht.UsedRange\r\n    myAr = myRng\r\n    k = 0\r\n    Date_Serving_Meal = \"2011\/1\/1\"\r\n    Menu_Name = myAr(1, 11) & myAr(1, 12) & myAr(1, 13)\r\n    tmpStart = InStr(Menu_Name, \")\")\r\n    Menu_Name = Mid(Menu_Name, tmpStart + 1)\r\n    Meal_Time = \"\u671d\u98df\"\r\n    For i = LBound(myAr) To UBound(myAr)\r\n        \r\n        Select Case True\r\n            Case myAr(i, 2) = \"\u5408      \u8a08\"\r\n                Date_Serving_Meal = DateAdd(\"d\", 1, Date_Serving_Meal)\r\n            Case myAr(i, 2) = \"\u300a\u671d\u98df\u300b\"\r\n                Meal_Time = \"\u671d\u98df\"\r\n            Case myAr(i, 2) = \"\u300a\u663c\u98df\u300b\"\r\n                Meal_Time = \"\u663c\u98df\"\r\n            Case myAr(i, 2) = \"\u300a\u5915\u98df\u300b\"\r\n                Meal_Time = \"\u5915\u98df\"\r\n            Case myAr(i, 2) = \"\u5c0f      \u8a08\"\r\n            Case myAr(i, 2) = \"^e12\u3010\u732e\u7acb\"\r\n            Case myAr(i, 2) Like \"\u52d5\u86cb\u6bd4\" & \"*\"\r\n            Case myAr(i, 2) = \"\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\"\r\n            Case myAr(i, 2) = \"\u6599\u7406\u540d\"\r\n            Case myAr(i, 2) = \"\"\r\n            Case Else\r\n                Dish = myAr(i, 2)\r\n        End Select\r\n        \r\n        Select Case True\r\n            Case myAr(i, 3) = \"\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\"\r\n            Case myAr(i, 3) Like \"EN\u6bd4\" & \"*\"\r\n            Case myAr(i, 3) = \"\u98df\u54c1\u540d\"\r\n            Case myAr(i, 3) Like \"\u4e00\u89a7\u8868\u3011 ^e11\" & \"*\"\r\n            Case myAr(i, 3) = \"\"\r\n            Case Else\r\n                RecAr(k, 0) = Date_Serving_Meal\r\n                RecAr(k, 1) = Menu_Name\r\n                RecAr(k, 2) = Meal_Time\r\n                RecAr(k, 3) = Dish\r\n                RecAr(k, 4) = myAr(i, 3)\r\n                For j = 5 To 22\r\n                    RecAr(k, j) = myAr(i, j - 1)\r\n                Next j\r\n                For j = 23 To 39\r\n                    RecAr(k, j) = myAr(i + 1, j - 18)\r\n                Next j\r\n                For j = 40 To 51\r\n                    RecAr(k, j) = myAr(i + 2, j - 35)\r\n                Next j\r\n                k = k + 1\r\n        End Select\r\n    Next i\r\n    Set mySht = Worksheets.Add\r\n    With mySht\r\n        .Name = Menu_Name\r\n        .Range(Cells(1, 1), Cells(RecordNumber, 52)) = RecAr\r\n    End With\r\n    \r\n    Set mySht = Nothing\r\n    Set myRng = Nothing\r\n    Erase RecAr\r\nEnd Sub\r\n\r\nFunction Count_Record(ByRef Sh As Worksheet) As Long    \r\n    Dim mySht       As Worksheet\r\n    Dim myAr        As Variant\r\n    Dim i           As Long\r\n    Dim j           As Long\r\n    Dim k           As Long\r\n    Set mySht = Sh\r\n    myAr = mySht.UsedRange\r\n    j = 0\r\n    k = 0\r\n    For i = LBound(myAr) To UBound(myAr)\r\n        Select Case True\r\n            Case myAr(i, 2) = \"\u5408      \u8a08\"\r\n            Case myAr(i, 2) = \"\u5c0f      \u8a08\"\r\n            Case myAr(i, 2) = \"\u300a\u671d\u98df\u300b\"\r\n            Case myAr(i, 2) = \"\u300a\u663c\u98df\u300b\"\r\n            Case myAr(i, 2) = \"\u300a\u5915\u98df\u300b\"\r\n            Case myAr(i, 2) = \"^e12\u3010\u732e\u7acb\"\r\n            Case myAr(i, 2) Like \"\u52d5\u86cb\u6bd4\" & \"*\"\r\n            Case myAr(i, 2) = \"\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\"\r\n            Case myAr(i, 2) = \"\u6599\u7406\u540d\"\r\n            Case myAr(i, 2) = \"\"\r\n            Case Else\r\n                j = j + 1\r\n        End Select\r\n        Select Case True\r\n            Case myAr(i, 3) = \"\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\"\r\n            Case myAr(i, 3) Like \"EN\u6bd4\" & \"*\"\r\n            Case myAr(i, 3) = \"\u98df\u54c1\u540d\"\r\n            Case myAr(i, 3) Like \"\u4e00\u89a7\u8868\u3011 ^e11\" & \"*\"\r\n            Case myAr(i, 3) = \"\"\r\n            Case Else\r\n                k = k + 1\r\n        End Select\r\n    Next i\r\n    Count_Record = k\r\nEnd Function\r\n<\/pre>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>In this article, I&#8217;d like to describe how to fix the text file of the food composition of the diet recip &hellip; <a href=\"https:\/\/www.fujiitoshiki.com\/improvesociety\/?p=5290\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;How to fix the text file of the food composition of the diet recipes to the first normal form?&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":6026,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1,6,4],"tags":[603,154,152,151,153],"class_list":["post-5290","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database","category-excel","category-nutrition","tag-excel","tag-first-normal-form","tag-food-composition","tag-recipe","tag-vba"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/5290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5290"}],"version-history":[{"count":2,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/5290\/revisions"}],"predecessor-version":[{"id":5333,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/5290\/revisions\/5333"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/media\/6026"}],"wp:attachment":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}