Hello everyone
Today we will continue from the last session looking at our Recipe Builder application.
We will start this session with copying data from a website and adding it to the recipe memo field on our form. To accomplish this we are using the function
clipboard.get_data()
In the not to distant past many websites were static and extracting data from the web page was easy using
html_text = file.to_string(“somewebpage.htm”)
extract_string(html_text, “<body”, “</body>”)
html_text = right(html_text, len(html_text)-1)
*html_to_plain(html_text)
Now most sites use jscripting or some other method to display text and or data simply by streaming it to the page live via a script. So the simple solution is to have the user highlight the desired text on the page and copy. This puts the data into the clipboard of their computer. Once the data is there the clipboard.get_data() function will collect the info and write it to where ever you say. The code on our Post From Website button onPush event is
parentform.commit()
rNbr = recno("recipehdr")
t = table.current()
t.fetch_goto(rNbr)
t.change_begin()
t.memoinstr = :clipboard.get_data()
t.change_end(.t.)
parentform.Refresh_Layout()
What this code does is simple. It assigns the current record number to a variable then points to the current table and fetches the desired record. The table is then put into change mode and the clipboard data is written to our memo field. The table entry is saved with change_end(.t.) and the layout is refreshed.
This approach allows them to go to any recipe website and copy any recipe they desire which will then be added to their recipe database.
Now lets examine our New Recipe button onPush event. When the form is opened, it is in view mode and our conditional object at the top of our form looks like this.
parentform.commit() xNR = 2 Recipe_Entry_Form:cond2.refresh() text1.text = "Enter name for new recipe." topparent.new_record()
First we insure any previous edits are saved. Next we change the value of our variable xNR which switches our conditional object to page 2 and finally we refresh our cond2 object and start a new record.
Now our cond2 object look like this,
and our form is in data entry mode. Now this method for controlling entry on our form is simple, but lacks important features such as attaching an image to our recipe. A better solution would be to pop up a xdialog form which prompts for the name of the recipe and the name of the image. When Continue is pressed a new record would be started and the two value would automatically be written to the table and focus would to given to the browse window for ingredient entry. For those of you feeling adventurous see if you can do just that. I would be happy to review your solution and give feedback if you send it to me.
The final xBasic code we will look at in this session is for the portion control section of our application.
After the recipe is entered, the user can use the above Portion Control section of the form to adjust the number of servings needed for a dinner and recalculate the amount of each ingredient needed for the specified servings. They can choose form the static choices of one half up to 5 times the default recipe or the can use the Adj Servings field and select any value they want.
Here is the code for the one half of recipe size.
parentform.commit()
vRecID = Recipe_Entry_Form:rec_id.text
a_tbl = table.open("RecDetail")
update.fields = 1
update.field1 = "EXTQTY"
update.expr1 = "if(Rec_Id = Var->vRecID,Qty/2,EXTQTY)"
a_tbl.update()
a_tbl.close()
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
parentform.commit()
In this case I am using a high level update operation which was converted to xBasic. I assigned the recipe ID for the selected recipe to my variable then used an inline if statement to determine what ExtQty should equal. In this case, it is Qty / 2. Each of the portion control options work the same way. It’s fast and simple.
In our next session we will review how to maintain multiple data views of a table on one single form at the same time. I think you will find it interesting.
Thanks again for stopping by and Remember, if you need help with an Alpha Software application or wish to inquire about a custom application for your business go to our website
and inquire or contact
NLawson@cdc-TakeCharge.com
Have a great day.


Leave a comment