|
Comments
|
Today's Top SOA Links
Features Building a Scoreboard in PowerBuilder
The results were well worth it
Feb. 16, 2009 10:15 AM
My favorite sport is artistic roller skating, where I act as the tabulator. It's a wonderful sport, a bit like ice skating, except that most events are skated on quad skates (four wheels in a rectangular layout). We do freestyle (with jumps and spins), figure skating (on the circles), and dance. A few of us do inline skating, too. We had a tabulating program: a Visual Basic 3 application. It did its job, but the score sheets which it printed had only the skaters' numbers, not their names. Data was kept in flat files. Skaters and their parents would crowd around the score sheets once we posted them, trying to figure out how they did. The font was small, but you could figure it out with a little patience. We never had a scoreboard for this sport. There are many scoreboard programs for sale on the Internet, but none were designed for this sport. Even if we found such a program, re-keying the information just to show it on the scoreboard would not be fun. A local contest can have up to 60 events, averaging 10 skaters each. I wondered how hard it would be to create a real scoreboard for this application. The requirements were as follows: 1) it had to Multiple Monitors This same procedure works great for S-Video too. I hooked up my TV and saw the scoreboard come to life. My 27-inch TV did work, but the picture was not as crisp as it was on my 17-inch LCD monitor. Also, the colors needed a bit of adjustment to look good on my TV. Which Events to Display The Display button simply does a SaveAs() function to save the datawindow to the "Server Folder", and loops through the rows, copying the files needed for the events that are checked. That's all the main window has to do. The scoreboard will read these files, as we will see. Long ll_row,ll_max RegistryGet(‘HKEY_CURRENT_USER\Software\ScoreMax', 'ServerFolder',RegString!,ls_server_folder) FileDelete(ls_server_folder+'\schedule.txt') ll_max=dw_01.RowCount() FOR ll_row=1 TO ll_max ls_round=dw_01.GetItemString(ll_row,'type') RETURN 0 To make coding easier, whenever there are DataWindows on tabs, I create an instance variable for it, and initialize it in the open event of the window. Then, you can refer to the datawindow using the instance variable. It's easier to type dw_01 than tab_1.tabpage_2.dw_1. DataWindow dw_01 // Open event: Scoreboard Layout The top DataWindow will show up to 12 skaters, sorted by placement, and also show skater number, name, and the ordinals. (An ordinal tells you how a particular judge ranked you in that event. An ordinal of one means the judge put you in first place.) The bottom DataWindow has the judge's number and name, as well as the current time (see Figures 1 and 2). Paging // Instance variables: // Add blank lines dw_2.InsertRow(0) il_pmax=ll_max/12 // Set number of pages Scoreboard Position We needed four buttons to "nudge" the screen up, down, left and right. Then, a "Save" button will store the coordinates in the Registry, so the next time you open the scoreboard, it shows up in the right place. The code for these buttons is in Listing 1. Networking Scoreboards I installed Apache on the main laptop, and unit tested it. Apache is very easy to install, and you don't have to run Windows XP Pro - it's content to run on Windows XP Home. Then the Tabulating program had to copy the scoring files to the Apache folder (by default, this is C:\Program Files\Apache Group\Apache2\htdocs.) This is done via a simple FileCopy() function in PowerBuilder. Be aware that you have to set the third argument of FileCopy() to TRUE to replace an existing file. Then, on another laptop, you run another copy of the same application, and configure it to be a client. It will read from an address such as http://192.168.1.100, using the Microsoft XMLHTTP component. This component lets you read the contents of any Web page, allowing you to write your own "spider" program. Some code that does this reading is in Listing 2. Overcoming Caching By adding a dummy parameter "r" with the value of the current date, you can defeat this caching issue. Main Logic The first thing wf_timer() does is to determine if it needs to "Page Down" - there are more than 12 skaters, and there is an additional page. If so, it does the ScrollNextPage(), increments the page number, and returns. Next, wf_timer() checks to see if we have finished showing the last event. If so, it calls wf_begin() to start the cycle over. This has to be done using POST to prevent a call loop. If this is not the last event, wf_timer() will find the next checked event, and calls wf_show(), which actually displays the first page of an event. Wf_show() is responsible for reading the flat files, and putting the data into both the upper and lower DataWindow. As discussed above, it also adds blank lines if needed so that the upper DataWindow's row count is a multiple of 12, and it calculates the number of pages. Handling Network Downtime Now, if Apache goes down, the Scoreboard can simply reuse the last copy of its files in the Scoreboard directory. Bottom Line Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||