At the end of our last session we were looking at the code for the onPush event of our ‘Open Move Tracker’’ button.
form.load("TC_MC_MoveTracker","dialog","","right","middle")
TC_MC_MoveTracker.Activate()
TC_MC_MoveTracker.Show()
TC_MC_MoveTracker.close()
if CName <> "" then
movestate = "Return"
dim record_count as N
t = table.open("tcrubixmoves")
t.fetch_first()
record_count = t.records_get()
t.fetch_last()
for i = 1 TO record_count
eval("script_play('"+Alltrim(t.rtnbtnname)+"')")
sleep(4/10)
xbasic_wait_for_idle()
t.fetch_prev()
next i
movestate = "Move"
button5.push()
xbasic_wait_for_idle()
parentform.Refresh_Layout()
end if
I showed the onInit event code and how to filter a list on a list object choice properties tab. You can refer back to the previous post if you are unsure how to do that.
Once the form loads the user can scroll through the list to find the saved moves. When they select the move they want the browse table below is queried to that routine only. This is done by using the function queryrun with a filter on the moveDesc field being equal to our variable choice. The code for the onChange event of our list object is shown here.
DIM records_found as N
records_found = topparent.queryrun("movedesc = Var->SavedMoves","","","No","",.f.)
browse1.refresh()
After the query is run we refresh the browse object (browse1) and that is all we need to do.
At this point the user can choose to
- Load Saved Pattern
- Delete the Selected move or any specific record within the saved move
- Print a range of saved moves
- Close the Move Tracker form
Load Saved Pattern:
The onPush event of ‘Load Saved Pattern’ must first prepare the parent table before it appends the saved pattern records. This is done by pushing button1 on our calling form ‘TCMagicCube’. Since the current focus is not TCMagicCube I need to tell Alpha Software the form name as well as the object I wish to push. Next I set the variable CName to equal my list object variable value, then use CName to filter the records I wish to append.
Here is the code for the Load Saved Pattern onPush event.
'Date Created: 02-Mar-2016 10:44:00 AM 'Last Updated: 02-Mar-2016 10:44:00 AM 'Created By : NLaws 'Updated By : NLaws parentform.commit()
TCMagicCube:button1.push() TCMagicCube:button1.push() xbasic_wait_for_idle()
CName = Var->SavedMoves DIM Append as P
a_tbl = table.open("tcrubixmoves")
append.t_db = "hist_mc_moves"
append.m_key = ""
append.t_key = ""
append.m_filter = ""
append.t_filter = "Movedesc=Var->CName"
append.type = "All"
append.m_count = 3
append.m_field1 = "MOVBTNNAME"
append.m_exp1 = "@HIST_MC_MOVES->MOVBTNNAME"
append.m_field2 = "CFACE"
append.m_exp2 = "@HIST_MC_MOVES->CFACE"
append.m_field3 = "RTNBTNNAME"
append.m_exp3 = "@HIST_MC_MOVES->RTNBTNNAME"
append.t_count = 0
a_tbl.append()
a_tbl.close()
parentform.close()
Remember that since this form was loaded as a dialog,
parentform.close()
simply hides the form. Our original calling script must now close the form to remove it from memory and to continue with the code on that event.
if CName <> "" then
movestate = "Return"
dim record_count as N
t = table.open("tcrubixmoves")
t.fetch_first()
record_count = t.records_get()
t.fetch_last()
for i = 1 TO record_count
eval("script_play('"+Alltrim(t.rtnbtnname)+"')")
sleep(4/10)
xbasic_wait_for_idle()
t.fetch_prev()
next i
movestate = "Move"
button5.push()
xbasic_wait_for_idle()
parentform.Refresh_Layout()
end if
I wrapped this code in an If statement which test ‘CName’. if CName is blank the code is not needed and it does not run; otherwise it does. Next I set the value of ‘movestate’ to “Return”. This variable is used to tell the application to track the moves or not. The next step is to open the current table; ( I could have used t = table.current()); fetch the first record then use records_get() to get the number of records in the table. This value is used to build a simple array of 1 to record_counts). At this point the table has the moves in a descending order (last to first) so I use fetch_last to go to the end of the table then step through the array from bottom to top by using fetch_prev(). Each time a record is fetched the value of the field ‘rtnbtnname’ (which is the name of the script for that specific move ) is used in conjunction with the eval function to play the local script.
eval(“script_play(‘”+Alltrim(t.rtnbtnname)+”‘)”)
I use sleep to slow down the code so the user can see the values change on the screen and the wait for idle insures each step is finished before the next step begins.
Well that all we will cover for this application; I hope you enjoyed seeing it as much as I did creating it. Our next lesson will be to create a card game and we will start with blackjack. Now a card game does not require a dbf table to run, but neither did the chess game or the magic cube. This is however a blog on programming is Alpha Software which is a database development software application so we will build our cards and decks in a table and use xBasic to read and control the values of our deck. I hope all of you will stop by to follow along. Have a great day.
Leave a comment