Help asked: systemRPL ^IFMain question
01-27-2016, 09:51 PM
Post: #1
 brrm Junior Member Posts: 7 Joined: Jan 2016
Help asked: systemRPL ^IFMain question
Hi,

This my first post on this forum, sorry for starting with a rather detailed technical question for help. I hope this is the proper place to ask.

I am working on a simple systemRPL program for the 50g with an InformBox as a UI.

The program works fine but I want to improve usability. What I want to achieve is this:

I have defined a custom menu key to perform a calculation with (the content of) input Fields on the form. How things currently work is that if I enter a value in an input field, I push 'ENTER' to close the edit-line and move the new value to the Field, then I push the custom menu key (F6 in this case) to perform the computation and show the result. This is standard behavior.

What I would like to do is to include the 'ENTER' behavior in the KeyProcNS of my custom menu key. So there would be no separate 'ENTER' required, this would be handled by the custom key implicitly.

The desired result is that after keying a new value of the input field, pushing F6 would do two things: enter the value into the input field and close the command line, then perform the computation, all in one F6 keystroke. I hope this description of what I want to do is clear.

I read the books on systemRPL by Donnelly, by Malinowski and Dominic, and RPLMan. I find the documentation on ^IfMain quite limited in these publications and haven't found a clue on how to achieve what I want. I use Debug4x.

Any help is greatly appreciated.
02-02-2016, 08:19 PM (This post was last modified: 02-02-2016 08:21 PM by wojtek.)
Post: #2
 wojtek Member Posts: 131 Joined: Dec 2015
RE: Help asked: systemRPL ^IFMain question
Nobody will know how to help you until you provide a sample of the code you've written
02-03-2016, 09:23 AM (This post was last modified: 02-03-2016 09:27 AM by brrm.)
Post: #3
 brrm Junior Member Posts: 7 Joined: Jan 2016
RE: Help asked: systemRPL ^IFMain question
(02-02-2016 08:19 PM)wojtek Wrote:  Nobody will know how to help you until you provide a sample of the code you've written

Thanks.

Here's the code of the message handler.
Code:
 IfMsgGet3KeysMenu OVER#=case ::     DROP     {  * * two other key definitions are not shown here for brevity *             { "\8DREV."  ::  ( KeyProcNS for calculation of REV )          TakeOver          FLASHPTR IfEnterKeyPress        ( do 'enter' )          LAM 'Quit ITE ::             DROP 3DROP                       ( clean the stack )             FALSE ' LAM 'Quit STO           ( do not quit )      ; ::             ( To do: find out how to update the value of the current )             ( field so only 1 keypress is needed instead of 2 )                                  ;          #0 FLASHPTR IfGetFieldValue    ( Retrieve COST )          #2 FLASHPTR IfGetFieldValue    ( Retrieve Margin )          100. SWAP %- %/ %10* %10*  ( do computation )          #1 FLASHPTR IfSetFieldValue     ( show value on Form )        ; } }        TRUE                                       ( we handled the message )     ;         DROPFALSE ;

This works, except that following the IfEnterKeyPress, the current field is not updated with the contents of the edit line, so that the previous value of that field is used in the computation. Only after a second keypress the calculation is performed with all the correct values.

I am looking forward to any info on how to solve this.
02-04-2016, 01:58 AM
Post: #4
 DavidM Senior Member Posts: 754 Joined: Dec 2013
RE: Help asked: systemRPL ^IFMain question
(02-03-2016 09:23 AM)brrm Wrote:  I am looking forward to any info on how to solve this.

Thanks for posting your code snippet, it helped to better understand what you are attempting to do.

It appears to me that you may be running into trouble by making the call to ^IfEnterKeyPress in an effort to simulate the ENTER key while an EditLine is active. I believe that procedure was designed more for other situations where you might want to do some of your own processing as a result of responding to a message, then simulating the effect of the user pressing the enter key. There's a subtle difference in context here.

The following may work better for you:

Immediately after the TakeOver in your menu routine, test for the presence of an active EditLine and take care of storing the current value if there is one. Then proceed with your calculations as needed. Here's a sample of what that might look like (with absolutely no error checking!):

Code:
TakeOver EditLExists? IT ::    EDITLINE$DOSTR> ( Get the current edit string and parse it ) FLASHPTR IfSetCurrentFieldValue ( Set the value obtained as the current field value ) InitEd&Modes ( Clear the current EditLine ) ; ( ... further processing as needed for menu command ... ) This assumes, of course, that I've understood what you're trying to accomplish. I may have misunderstood your intent. If it helps to see a more complete example, here's the generated source code from an InputForm built using Debug4x. This is about as simple an example as I could think of to show how the code might work. In this case, the "SUM" menu command simply adds the three values in fields 1-3 and places the total into field 4. I'm hoping this works the way you want: Code: ( Inform Box File ) ( Inline Text ) ( Do not modify this line ) * Inform Box Simple Inform Test Source Code * Generated on 8:50:28 PM 2/3/2016 by HP InformBox Generator * Inform Box Designer is DavidM INCLUDE Header.h ( Include Standard RPL defs ) INCLUDE Informbox.h ( Include Definitions ) ( Field and Label Definitions ) DEFINE Field1 BINT0 DEFINE Field2 BINT1 DEFINE Field3 BINT2 DEFINE Field4 BINT3 DEFINE Label1 BINT0 DEFINE Label2 BINT1 DEFINE Label3 BINT2 DEFINE Label4 BINT3 ( Local Definitions ) NULLNAME _Simple_Inform_Test_ :: ( Internal Graphical Datas ) ASSEMBLEM STRING {$(5)#1202                       % Uncompressed string size      $(3)#0 % Y offset$(2)#0                          % Current Field     $(2)#4 % Number of labels$(2)#4                          % Number of fields     $(5)#269 % Offset to fields definition % Start of label definitions$11402D01E1002601E10F0F0F                     % Label Label1 definition     $114026100E1002601E10F0F0F % Label Label2 definition$11402F100E1002601E10F0F0F                    % Label Label3 definition     $11402E200E1002601E10F0F0F % Label Label4 definition % Start of field definitions$1CA02B01143C2801820F0F0F0F0F0F0F0F0F09       % Field Field1 definition     $1CA024100143C2801820F0F0F0F0F0F0F0F0F09 % Field Field2 definition$1CA02D100143C2801820F0F0F0F0F0F0F0F0F09      % Field Field3 definition     $1CA02C200143C2801820F0F0F0F0F0F0F0F0F09 % Field Field4 definition } !RPL FLASHPTR IsUncompressDataString ( Uncompress the string ) ( Labels graphic, string on the stack ) DUP BINT0 FALSE "Field 1:" FLASHPTR IfSetGrob3 DUP BINT1 FALSE "Field 2:" FLASHPTR IfSetGrob3 DUP BINT2 FALSE "Field 3:" FLASHPTR IfSetGrob3 DUP BINT3 FALSE "Sum:" FLASHPTR IfSetGrob3 ( Help strings, string on the stack ) BINT0 "first field" FLASHPTR IfSetHelpString BINT1 "second field" FLASHPTR IfSetHelpString BINT2 "third field" FLASHPTR IfSetHelpString BINT3 "output field" FLASHPTR IfSetHelpString " Simple Inform Test " FLASHPTR IfSetTitle ( Title String ) ( Inform Box Message Handler ) ' :: ( Inform Box Message Handler ) BINT12 OVER#=case :: ( Configures menu softkeys ) DROP { { "SUM" :: TakeOver EditLExists? IT :: EDITLINE$ DOSTR>                   FLASHPTR IfSetCurrentFieldValue                   InitEd&Modes               ;               Field1 FLASHPTR IfGetFieldValue               Field2 FLASHPTR IfGetFieldValue               Field3 FLASHPTR IfGetFieldValue               %+ %+               Field4 FLASHPTR IfSetFieldValue               ; }             { "CANCL" ::                 TakeOver               TRUE ' LAM 'Quit STO               ; }             { "OK" ::                 TakeOver                 FLASHPTR IfEnterKeyPress                 ; } }           TRUE       ;       DROPFALSE   ;     ( Field Definitions )                ( Field1 definition )                'DROPFALSE                        ( Field Message Handler )   IfFieldTypeText                   ( Field Type )   { IfObReal  }                     ( Allowed Types )   BINT2                             ( Decomp object )   MINUSONE                          ( No choose list )   MINUSONE                          ( No choose decomp )   %0                                ( Reset Value )   %0                                ( Initial Value )                                      ( Field2 definition )                'DROPFALSE                        ( Field Message Handler )   IfFieldTypeText                   ( Field Type )   { IfObReal  }                     ( Allowed Types )   BINT2                             ( Decomp object )   MINUSONE                          ( No choose list )   MINUSONE                          ( No choose decomp )   %0                                ( Reset Value )   %0                                ( Initial Value )                                      ( Field3 definition )                'DROPFALSE                        ( Field Message Handler )   IfFieldTypeText                   ( Field Type )   { IfObReal  }                     ( Allowed Types )   BINT2                             ( Decomp object )   MINUSONE                          ( No choose list )   MINUSONE                          ( No choose decomp )   %0                                ( Reset Value )   %0                                ( Initial Value )                                      ( Field4 definition )                'DROPFALSE                        ( Field Message Handler )   IfFieldTypeText                   ( Field Type )   { IfObReal  }                     ( Allowed Types )   BINT2                             ( Decomp object )   MINUSONE                          ( No choose list )   MINUSONE                          ( No choose decomp )   %0                                ( Reset Value )   %0                                ( Initial Value )                                    ( Group the Field Definitions in a List )    ASSEMBLEM $(5)BINT32 % #8*No fields !RPL {}N FLASHPTR IfMain2 ; ( end of form procedure ) ( % Count for the Message Table DCCP 0 _Simple_Inform_Test_MesBase ) ( Messages automatically copied by Inform Generator ) ( Messages added to the Library's Message Table ) ( Internal Datas: Do not touch! l00000000020C001C000100000014002000530069006D0070006C006500200049006E0066006F007​2006D002000540065007 S300740020 021100270020003A003A000D000A000900420049004E0054003100320020004F0056004500520023​003D0063006100730065 S0020003A003A0020002800200043006F006E00660069006700750072006500730020006D0065006​E007500200073006F0066 S0074006B00650079007300200029000D000A0009000900440052004F0050000D000A00090009007​B0020007B002000220053 S0055004D00220020003A003A000D000A00090009000900540061006B0065004F007600650072000​D000A0009000900090045 S006400690074004C004500780069007300740073003F0020004900540020003A003A000D000A000​900090009000900450044 S00490054004C0049004E0045002400200044004F005300540052003E000D000A000900090009000​90046004C004100530048 S00500054005200200049006600530065007400430075007200720065006E0074004600690065006​C006400560061006C0075 S0065000D000A00090009000900090049006E00690074004500640026004D006F006400650073000​D000A000900090009003B S000D000A000900090009004600690065006C0064003100200046004C00410053004800500054005​200200049006600470065 S0074004600690065006C006400560061006C00750065000D000A000900090009004600690065006​C0064003200200046004C S004100530048005000540052002000490066004700650074004600690065006C006400560061006​C00750065000D000A0009 S00090009004600690065006C0064003300200046004C00410053004800500054005200200049006​600470065007400460069 S0065006C006400560061006C00750065000D000A0009000900090025002B00200025002B000D000​A00090009000900460069 S0065006C0064003400200046004C004100530048005000540052002000490066005300650074004​600690065006C00640056 S0061006C00750065000D000A000900090009003B0020007D000D000A0009000900200020007B002​0002200430041004E0043 S004C00220020003A003A000D000A0009000900200020000900540061006B0065004F00760065007​2000D000A000900090009 S0054005200550045002000270020004C0041004D002000270051007500690074002000530054004​F000D000A000900090009 S003B0020007D000D000A0009000900200020007B00200022004F004B00220020003A003A000D000​A00090009002000200009 S00540061006B0065004F007600650072000D000A000900090020002000090046004C00410053004​800500054005200200049 S00660045006E007400650072004B0065007900500072006500730073000D000A000900090020002​00009003B0020007D0020 S007D000D000A000900090054005200550045000D000A0009003B000D000A000900440052004F005​000460041004C00530045 S000D000A003B000D000A 0002000D000A 0002000D000A f002C010400A0002000010006004600690065006C006400310006004600690065006C00640031000​00000000100300005004 S20049004E005400320000000300540057004F000200250030000200250030000B00660069007200​730074002000660069006 S5006C0064 f0050010400A0002000010006004600690065006C006400320006004600690065006C00640032000​00000000100300005004 S20049004E005400320000000300540057004F000200250030000200250030000C00730065006300​6F006E006400200066006 S90065006C0064 f0074010400A0002000010006004600690065006C006400330006004600690065006C00640033000​00000000100300005004 S20049004E005400320000000300540057004F000200250030000200250030000B00740068006900​720064002000660069006 S5006C0064 f00B0010400A0002000010006004600690065006C006400340006004600690065006C00640034000​00000000100300005004 S20049004E0054003200000008004D0049004E00550053004F004E00450002002500300002002500​30000C006F00750074007 S0007500740020006600690065006C0064 l003400780078001800010006004C006100620065006C00310008004600690065006C00640020003​1003A l005800780078001800010006004C006100620065006C00320008004600690065006C00640020003​2003A l007C00780078001800010006004C006100620065006C00330008004600690065006C00640020003​3003A l00B800780078001800010006004C006100620065006C0034000400530075006D003A 0002000D000A 0002000D000A 000600440061007600690064004D 0014005F00530069006D0070006C0065005F0049006E0066006F0072006D005F0054006500730074​005F 00040046004600460046 ) Hope this helps! - David 02-04-2016, 09:16 PM (This post was last modified: 02-04-2016 09:41 PM by brrm.) Post: #5  brrm Junior Member Posts: 7 Joined: Jan 2016 RE: Help asked: systemRPL ^IFMain question (02-04-2016 01:58 AM)DavidM Wrote: Hope this helps! - David It certainly does! Thank you very much! When I worked on it I ran into another problem. When I use your code, it works as desired, but ONLY if I enter the decimal separator to force a real (i.e. type '7.' followed by <SUM>) it gives the correct answer. If I omit the separator (i.e. type '7' followed by <SUM>) then the result is garbage. I was able to fix this with CK&DISPATCH1. The final source code is: Code: ' :: IfMsgGet3KeysMenu OVER#=case :: DROP { NullMenuKey { "CANCL" :: TakeOver FLASHPTR IfONKeyPress ; } { "\8DA+B" :: TakeOver ( KeyProcNS for calculation of A+B ) EditLExists? IT :: EDITLINE$ DOSTR>                 ( Get the current edit string and parse it )             :: CK&DISPATCH1                  ( check type and convert to real if necessary )                                                         BINT1 :: FLASHPTR IfSetCurrentFieldValue ; ( Set the value obtained as the current field value )                                                 ;                                           InitEd&Modes                     ( Clear the current EditLine )           ;           Field1 FLASHPTR IfGetFieldValue    ( Retrieve A )           Field2 FLASHPTR IfGetFieldValue    ( Retrieve B )           %+                                 ( A+B )           Field3 FLASHPTR IfSetFieldValue    ( Show result on Form )         ;                         }                 }     TRUE                                     ( We handled the message )   ;           DROPFALSE                                  ( We don't handle any other message ) ;

Regards bram
02-04-2016, 11:38 PM
Post: #6
 DavidM Senior Member Posts: 754 Joined: Dec 2013
RE: Help asked: systemRPL ^IFMain question
(02-04-2016 09:16 PM)brrm Wrote:  When I worked on it I ran into another problem.

When I use your code, it works as desired, but ONLY if I enter the decimal separator to force a real (i.e. type '7.' followed by <SUM>) it gives the correct answer.

If I omit the separator (i.e. type '7' followed by <SUM>) then the result is garbage.

I was able to fix this with CK&DISPATCH1.

CK&DISPATCH1 will do the conversion (as will CKREAL), but it also sets some other things that aren't desirable at the point in your code (protection word comes to mind). When I mentioned before that there was no error checking, this is part of what I was alluding to. Storing the value in the field in this manner bypasses the normal validation that IfMain does to make sure that the object is an acceptable type.

It may be a better approach to use the IfCheckFieldtype function that is part of the InputForm API. While I haven't tried all possible combinations of objects and field types, it did at least appear to convert a ZINT to a REAL automatically in this situation. It also returns a boolean that allows you to branch accordingly if the type wasn't acceptable.

When I was playing around with this earlier today, it seems that there's some fragility with this method of obtaining the data directly from the command line. I'm not sure, but I suspect that this comes from having several stacked "environments" active simultaneously. I tried the following code for the form's message handler and found that it was reasonably effective:
Code:
' ::     BINT12 OVER#=case :: ( Configures menu softkeys )         DROP         { { "SUM" ::             TakeOver             EditLExists? IT ::                 EDITLINE\$ InitEdLine                 DOSTR>                 FLASHPTR IfCheckFieldtype                 ITE                 ::                     FLASHPTR IfSetCurrentFieldValue                 ;                 ::                     # 202 JstGETTHEMSG FlashWarning                     DO>STR                     InitEdLine                     CMD_PLUS                     CMD_END_LINE                 ;             ;             Field1 FLASHPTR IfGetFieldValue             Field2 FLASHPTR IfGetFieldValue             Field3 FLASHPTR IfGetFieldValue             %+ %+             Field4 FLASHPTR IfSetFieldValue             ; }           { "CANCL" ::               TakeOver             FLASHPTR IfONKeyPress             ; }           { "OK" ::               TakeOver               FLASHPTR IfEnterKeyPress               ; } }         TRUE     ;     DROPFALSE ;

One of the potential problems that can occur is if the command line contains a string which will compile into multiple objects (ie. "123A" becomes % 123 and 'A' ). Things get a bit messier for that kind of scenario. Whatever you end up with, you'll want to run through a variety of scenarios to make sure it works the way you want.
02-09-2016, 11:37 AM
Post: #7
 brrm Junior Member Posts: 7 Joined: Jan 2016
RE: Help asked: systemRPL ^IFMain question
(02-04-2016 11:38 PM)DavidM Wrote:  ...
One of the potential problems that can occur is if the command line contains a string which will compile into multiple objects (ie. "123A" becomes % 123 and 'A' ). Things get a bit messier for that kind of scenario. Whatever you end up with, you'll want to run through a variety of scenarios to make sure it works the way you want.

Thanks for your reply. Over the weekend I have tested my code (based on CK&DISPATCH1) thoroughly with all kinds of wrong input in the edit line.

It is all handled correctly, I haven't yet found any undesired side-effects.
02-09-2016, 02:33 PM
Post: #8
 DavidM Senior Member Posts: 754 Joined: Dec 2013
RE: Help asked: systemRPL ^IFMain question
(02-09-2016 11:37 AM)brrm Wrote:  Thanks for your reply. Over the weekend I have tested my code (based on CK&DISPATCH1) thoroughly with all kinds of wrong input in the edit line.

It is all handled correctly, I haven't yet found any undesired side-effects.

...and that's what it's all about! Glad you got it working the way you wanted.

I went back and re-read the documentation for CK&DISPATCH1 and noticed that it doesn't set the protection word like the CKx and CKxNOLASTWD commands. So the only potential problem I was thinking of shouldn't even come up.

Glad to see that there are still some folks plugging away at SysRPL!
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)