Switching pages


Recommended Posts

Speed keys only work with normal characters (A, B, C, 1, 2, 3), not special keys like page up / page down. If you want to use page up/page down you'll have to use the OnKeyUp event to capture it and then change the page in script. The OnKeyUp event is described in the Sequences chapter of the help, under System Events.

I never know what the control character codes actually are (and Windows keeps adding new ones), so I typically just put a ? Key at the beginning of the OnKeyUp event and simply press the keys I want, and write down the numbers. OnChar uses a different set of codes (straight ASCII I believe) and doesn't capture special keys, so you'll need to use OnKeyUp.

I've attached a sample that marches through 3 pages using PgUp and PgDn. Its really quite simple. First, in an autostart sequence called startup, I declared a global string array of the page names I want to loop through in the order I want them. I also created a global variable containing the index of the page I'm currently viewing in the list:

global curpageindex = 0
global string pagenames = {"Page_1","Page_2","Page_3"}

Then, in the OnKeyUp event (which is just a sequences names "OnKeyUp", I look for key code 33 (pgup) and 34 (pgdn), adjust the index appropriately, then change the current page to the appropriate array element.

if (key == 33) // pgup
   curpageindex--
   if (curpageindex < 0)
	  curpageindex = numrows(pagenames) - 1
   endif
   page.strCurrentPage = pagenames[curpageindex]
endif
if (key == 34) // pgdn
   curpageindex++
   if (curpageindex >= numrows(pagenames))
	  curpageindex = 0
   endif
   page.strCurrentPage = pagenames[curpageindex]
endif

You could of course do many other cool things with the keyboard in a similar fashion, for example using function keys to trigger relays or the like. Just be careful when designing this. You don't want all your relays to suddenly trigger because an operator lost their balance and palmed the keyboard. This is actually why component speedkeys require both the speedkey and the space bar to trigger the action. Of course if you have an industrial panel this might not be as much of an issue, but keep it in mind when designing your system.

The samples requires 5.78, though the concepts would work in any recent release.

pageupPageDn.ctl

Link to comment
Share on other sites

Thank you Guru. This worked.

But I'm curious about how I was SUPPOSED to enter the code because the way I did it was a little tedious.

I tried to just run it, but since it was a CTL, it just replaced my other document.

I tried to rename both parts to *.txt and Open these, but same thing occured.

I looked for an import button or a Save To button for the scripts but none are available.

Finally I opened up the document that had both pieces of the script, CUT it, then pasted it into my document. I'm working between a couple computers. designing on my computer at work, sending the files to my home and my laptop that will run all this. So I need a good way of exporting/importing.

Is there one? If not, I'll do the cut and paste thingy but it seems kinda crude.

Link to comment
Share on other sites

The sample was designed to be standalone so as to only show the required details. The only choice for getting it into your app is to cut and paste, and of course do a few edits. It goes the same if you want to copy screen elements from one place to another. Release 6 will have a better method for this.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.