Page 5 of 10

Re: MealMaster: Decoding text file format to database

Posted: Sun Jan 06, 2013 9:42 pm
by Fangbeast
Moderator, Please remove this post, outdated.

Re: MealMaster: Decoding text file format to database

Posted: Sun Jan 06, 2013 10:47 pm
by Fangbeast
Whoever uploaded the icon, it looks good even in 48x48 view on my desktop, thanks for that.

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 1:37 am
by Charles556
Change this line:

Code: Select all

If Len(Line.s) = 5 And (Line.s = "MMMMM" Or Line.s = "-----")
to this:

Code: Select all

If Line.s = "MMMMM" Or Line.s = "-----"
Remove the comment marks in these lines;

Code: Select all

Debug "----------**********//////////\\\\\\\\\\**********----------"
                    ;CloseFile(RecipeFileHandle.i )
                    ;ProcedureReturn
                    State = #RecipeNone
to get just one recipe. Other wise it will run thru the whole file.
Some very good work, open my eyes to a different way of coding.
Thanks, hope this helps.
Charles556

P.S. this is from the code snippet on page 4 by Fangbeast

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 2:47 am
by Fangbeast
to get just one recipe. Other wise it will run thru the whole file.
I do want it to go through the whole file. It's doing that but not ending when it has finished and I don't know why.

Logic isn't my strong suit:)

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 3:02 am
by OldSkoolGamer
Fangbeast wrote:Whoever uploaded the icon, it looks good even in 48x48 view on my desktop, thanks for that.
That was me, found it on a free icon site when I first d/l the program, been meaning to upload it, but kept forgetting.... :oops:

Unfortunately I haven't had any time to take a good look at the source this weekend, but maybe this week at work I can.....

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 8:17 am
by JackWebb
Nice job guys, I love to cook!

Hope you don't mind if I butt in.. I pasted the code from the forum into my PB it and works very well. I found a bug where you load a file. If you then cancel the action it will no longer display a recepie that you click on. I fixed the bug, and I wanted to upload my fix to box but now everything has changed. Not only that but the program no longer works for me. Am I downloading the wrong file perhaps?

Thanks for the code!
Jack 8)

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 8:28 am
by Fangbeast
Moderator, Please remove this post, outdated.

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 11:01 am
by Lost
Great project, I'm planning to take a look at it when time permits.

Fangbeast, like LuCiFeR[SD] said, BitBucket is probably the best place to host the code. That way anyone can easily download the lastest version of the code.

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 12:02 pm
by Fangbeast
Moderator, Please remove this post, outdated.

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 1:55 pm
by infratec

Code: Select all

Enumeration
  #RecipeNone
  #RecipeVersion
  #RecipeCategory
  #RecipeServes
  #RecipeIngredients
  #RecipeInstructions
EndEnumeration

; Get and display recipe details when a title is clicked on

Procedure ImportMealMaster()
 
  ;

  Protected.i Result.i, File.i, State.i, Pos.i, Count, i
  Protected   Line.s, Text.s, Version.s, Title.s, Category.s, Yield.s, Ingredients.s, Method.s
 
  ;
 
  RecipeFileName.s = OpenFileRequester("Choose a Meal-Master file", "", "MealMasterFile|*.mmf|TextFile|*.txt|All|*.*", 1)
 
  ;
 
  If RecipeFileName.s <> ""
   
    ;

    RecipeFileHandle.i = ReadFile(#PB_Any,  RecipeFileName.s)
   
    ;

    If RecipeFileHandle.i
     
      ;

      While Not Eof(RecipeFileHandle.i)
       
        ; Read a line of text from the file
        
        Line.s = ReadString(RecipeFileHandle.i)
        
        ; Check which part of the file we are processing
        
        Select State
          
          ; No recipe found yet
          
          Case #RecipeNone
            Pos = FindString(Line.s, "Meal-Master")
            If Pos
              Version.s     = Trim(Mid(Line.s, Pos + 11))
              For i = 1 To Len(Version)
                If ValF(Mid(Version, i)) > 0
                  Version = Mid(Version, i)
                  Break
                EndIf
              Next i
              Title.s       = ""
              Category.s    = ""
              Yield.s       = ""
              Ingredients.s = ""
              Method.s      = ""
              State         = #RecipeVersion
            EndIf
            
          ; Recipe version number found
          
          Case #RecipeVersion
            Pos = FindString(Line.s, "Title:")
            If Pos
              Title.s       = Trim(Mid(Line.s, Pos + 7))
              State         = #RecipeCategory
            EndIf
            
          ; Recipe category found
          
          Case #RecipeCategory
            Pos = FindString(Line.s, "Categories:")
            If Pos
              Category.s = Trim(Mid(Line.s, Pos + 12))
              State = #RecipeServes
            EndIf
          
          ; Recipe yield found
          
          Case #RecipeServes
            Count = Len(Line.s)
            For i = 1 To Count
              If Val(Mid(Line.s, i)) > 0
                Yield.s = Trim(Mid(Line.s, i))
                State = #RecipeIngredients
                Break
              EndIf
            Next i
          
          ; Recipe ingredients found
          
          Case #RecipeIngredients
            If Trim(Line) <> ""
              If Val(Trim(Line.s)) > 0
                Line.s = Trim(Line.s)
                Pos = FindString(Line.s, "   ")
                If Pos
                  Ingredients.s + Trim(Left(Line.s, Pos)) + " "
                  Ingredients.s + Trim(Mid(Line.s, Pos)) + #LF$
                Else
                  Ingredients.s + Trim(Line.s) + #LF$
                EndIf
              Else
                If Trim(Left(Line.s, 3)) <> ""
                  If Left(Line.s, 5) = "MMMMM"
                    Ingredients.s + Trim(Mid(Line.s, 6), "-") + #LF$
                  Else
                    Method.s = Line.s + #LF$
                    State    = #RecipeInstructions
                  EndIf
                Else
                  Line.s = Trim(Line.s)
                  If Left(Line.s, 1) = "-"
                    Ingredients.s = Left(Ingredients.s, Len(Ingredients.s) - 2) + " " + Trim(Mid(Line.s, Pos), "-") + #LF$
                  Else
                    Ingredients.s + Trim(Mid(Line.s, Pos), "-") + #LF$
                  EndIf
                EndIf
              EndIf
            EndIf
            
          ; Recipe method found
          
          Case #RecipeInstructions
            If Len(Line.s) = 5 And (Line.s = "MMMMM" Or Line.s = "-----")
              ;Debug Version.s
              ;Debug Title.s
              ;Debug Category.s
              ;Debug Ingredients.s
              ;Debug Yield.s
              ;Debug Method.s
              ;Debug "----------**********//////////\\\\\\\\\\**********----------"
              
              RecipeCounter + 1
              
              Debug Str(RecipeCounter.i) + "   Recipes"
              
              State = #RecipeNone
              
            Else
              If Len(Line.s) <> 0
                Method.s + Line.s + #LF$
              EndIf
            EndIf
            
            ; No more headings to see
            
        EndSelect
        
        ; Continue processing the current recipe until the end marker is found
        
         
      Wend
      
      CloseFile(RecipeFileHandle.i)
     
    Else
      
      Debug "File wasn't opened slughead, no file handle"
   
    EndIf
  
  Else
   
    Debug "User cancelled the file open operation"
   
  EndIf
  
EndProcedure

ImportMealMaster()

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 2:02 pm
by Lost
Fangbeast wrote:@Lost I just had a quick look at BitBucket and it's not for me. Way, way too complicated for my life!!!

@Everyone else. I have uploaded the latest version 'RecipeMuncher0.00b.7z' to Box.com, same link as before.
No worries mate. I ended up registering an account with Box and downloaded your code.

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 8:12 pm
by Fangbeast
Moderator, Please remove this post, outdated.

Re: MealMaster: Decoding text file format to database

Posted: Mon Jan 07, 2013 8:22 pm
by Fangbeast
Moderator, Please remove this post, outdated.

Re: MealMaster: Decoding text file format to database

Posted: Tue Jan 08, 2013 12:30 pm
by Fangbeast
Moderator, Please remove this post, outdated.

Re: MealMaster: Decoding text file format to database

Posted: Tue Jan 08, 2013 8:21 pm
by Fangbeast
Moderator, Please remove this post, outdated.