cancel
Showing results for 
Search instead for 
Did you mean: 
JKova
Level 4
138 92 2 5
Message 1 of 11
2,367
Flag Post

Solved!

How to make a programe in User RPL which changes the type of input variables at INFORM input form

HP Recommended
HP 50g

Hello dear HP community , 

I wanted to know if anyhow possible to make a programe which checks if are input variables good entered , and if not then instead of showing me message "Bad argument type" program got back and change the input variable .

If you did not understand me , I' ll be clearer now .... supposed that I have realnum type and i wanted also in my program some other variable type to enter like list , let say . If I entered a list into programme which have predefined input variable like real number , I will probabli getting error "Bad Argument Type" because i entered different variable type if I compare this two types.

 

Ok i know that program will telling me error , but can I change if as example I had two variable type the one is 'Algebraic object' and other is 'Global Variable name' ,  and if I entered global variable name instead of algebraic object can my Program

somehow change the object type from 9 to 6 ? 

Because I'm working on programme which has to be able to do right that , if is entered variable type ( like number and i'm  lookinhg for algebraic object )  wrong that he ( program ) will 'automaticly' change input variable type as desired input variable type ( if we suppose at my particular case that we have only two options of variable types - number 9 and number 6 - global variable name and algebraic object ) !!here is my code , notice that my prefered variable was number , but iI want next - if I entered a algebraic expression that program will accept expresion too like as number didhere is my code , notice that my prefered variable was number , but iI want next - if I entered a algebraic expression that program will accept expresion too like as number didwatch ( look ) happened when i type at same code 'algebraic expression' instead of number ,  how to change when i had a multiple uses of programmme ?!watch ( look ) happened when i type at same code 'algebraic expression' instead of number , how to change when i had a multiple uses of programmme ?!

0 Kudos
10 REPLIES 10
David_M
Level 6
140 139 29 60
Message 2 of 11
Flag Post
HP Recommended

First, kudos for using INFORM!  It's a nice feature, but the complexity of using it effectively can sometimes discourage RPL programmers from taking advantage of this type of user interface presentation on the 50g.

 

INFORM allows you to give it a sequence of valid object types for any given field.  In your particular example, the field definition could be:

{ "input a number" "" 0 6 9 }

...thus allowing a real number, global name, or algebraic to be entered for that field.  It is then up to the rest of your program to choose an appropriate action for the resulting object that is returned.  In this particular case, it may be that you simply need to EVAL the result to obtain its underlying value.  One possible implementation of your INFORM box could then be:

«
   IF
      "INFORM"
      { { "input a number" "" 0 6 9 } }
      { 1 1 }
      { }
      { }
      INFORM
   THEN
      EVAL EVAL
   END
»

 

The above is constructed to allow for the possibility of the user simply pressing the CANCL key, in which case the program would just keep processing with no stack changes.  This may not be appropriate for what you're wanting to do, though.

 

I realize that this works in a different way than you were specifically asking about, but I believe it's more in keeping with the original design of INFORM's features.  User RPL doesn't really give you an option for changing field values while the dialog box is still executing, but you can definitely alter the results after the dialog is dismissed.  If appropriate, you could also encapsulate the process in a loop of some kind to repeatedly prompt for values if invalid input is given.  If you do that, though, be careful to test for the user pressing CANCL as one of the possible outcomes.

Tags (1)
JKova
Author
Level 4
138 92 2 5
Message 3 of 11
Flag Post
HP Recommended

Man , thank you you always reply on my questions and I get always back with an solution !!

Thank you very , very much now , and for an explanation too ... from my point of view I admire you and you're pure genius

I think that I'm a big newbie because i did not noticed at all that INFORM supports more than one type of input variables !!

 

 

Maybe I must go back to study all these stuff on some book on which writes all about that !!

 

Thank you and have a nice day  :OpenSmile:

Best regards ,

 

Josip Kova 

 

David_M
Level 6
140 139 29 60
Message 4 of 11
Flag Post
HP Recommended

I can assure you, I'm no genius!  There are definitely some participating here, though.  I enjoy seeing others trying new things with calculator programs, and if I see something posted that I've also run into, I generally try to help.  You are obviously not afraid to experiment and make use of a variety of your 50g's features, and you should have many years of fun ahead of you in the process.

David_M
Level 6
140 139 29 60
Message 5 of 11
Flag Post
HP Recommended

As a follow-up to my first post, consider the following:

«
   DO
      "INFORM"
      { { "input a number" "25 ≤ n ≤ 50" 0 6 9 } }
      { 1 1 }
      { }
      { }
      INFORM
      IF
         DUP
      THEN
         SWAP
         EVAL EVAL
         IF
            25 OVER ≤
            50 PICK3 ≥
            AND
         THEN
            SWAP 1
         ELSE
            "Number is out of range" MSGBOX
            DROP2 0
         END
      ELSE
         1
      END
   UNTIL
   END
»

This version provides a loop for INFORM which repeats until one of the following two conditions occurs:

1) A numeric value in the proper range is given

2) The user cancels the operation

 

Note that the output of this program differs from a stand-alone INFORM dialog box in that the result (left in stack level 2) is the EVAL'd value instead of a list.  A single 0 is still returned if a user cancels, though.  You could change all of that if needed, of course.

 

If the input value provided is out-of-range, the INFORM dialog box is still dismissed, but then it's immediately executed again.  It happens so quickly that it almost seems as though the dialog was never dismissed at all.  This gives the appearance of having validated the input while the dialog box was still executing, even though that doesn't actually happen.

JKova
Author
Level 4
138 92 2 5
Message 6 of 11
Flag Post
HP Recommended

Hey ... I'll tried out your new solution ... and I can not believed what you really did ... amazing solution ... your program is ... man awesome it prompts me if are my entered number in good interval or it does not . I will use that definetely !! Man , I never supposed to do things like you do :Sunglasses:

Look what I get ...

If I entered a number , let supposed 90Here is what happens ... awesome man ... good for you !!!Here is what happens ... awesome man ... good for you !!!

But hey David ... can I ask you one more question ... why I can not remove this  at bottom of your code , because I saw this one number in your code ( bottom part of code ) when it writes :

 

...

ELSE 

"Number is out of range" MSGBOX 

DROP2  0

END

ELSE

1  < --- THIS PART HERE 

END

UNTIL

END

>>

 

because when i entered a good number it appears this right underneath of entered number , so let we suppose to have an entered number 28 , because he is under specified interval ( 25 < n < 50 )

 

...anyway I'll post two pictures and maybe you figure out what I mean ( number 1 underneath my result of this programme ) ...Entered number  under proper borders of specified intervalEntered number under proper borders of specified interval

 

And this is what I get when I type "ENTER" ...notice that one underneath my resultAnd this is what I get when I type "ENTER" ...notice that one underneath my result

 So my question ( if you know the answer of course ) what will happen if I remove this number one from your source code ... will it program works and if you know why must be this one number if is needed to be at that place ?

0 Kudos
David_M
Level 6
140 139 29 60
Message 7 of 11
Flag Post
HP Recommended

Recall that the output of the INFORM command is in one of two forms.

If OK/ENTER was pressed:

02: { list of given values }
01: 1

...or if CANCL was pressed:

01: 0

 

This type of command result is common on the RPL calculators, in that a boolean (in the form of 0 or 1) is left on the stack to indicate whether something was completed successfully (indicated by a 1) or some other action occurred (in this case a CANCL causes a 0).

 

My intent with the second program is to leave a similar type of result.  If stack level 1 contains a 1 (TRUE), then your program knows that a valid value exists in stack level 2.  If stack level 1 contains a 0, then the user pressed the CANCL key and no other value was left on the stack.

 

The "1" that you are pointing to in your question is important and can't be removed; it designates that the loop should exit when the UNTIL clause is reached, which is a direct result of the user having pressed CANCL.

 

If you wanted, you could change the output of that example program to simply be a single number: 0 if the user pressed CANCL, or the actual (valid) number provided by the user.  That might make sense for this example, but what if 0 was actually a valid user-supplied number?  In that case, you'd have no way to distinguish that from the user pressing CANCL.  That's why this type of structure is commonly used.

 

Here's a commented (and re-formatted) version of the second example program.  The actual code is exactly the same:

«
   @ loop until valid input given or CANCL pressed
   DO
      @ display INFORM dialog box
      "INFORM"
      { { "input a number" "25 ≤ n ≤ 50" 0 6 9 } }
      { 1 1 } { } { }
      INFORM

      IF    @ was a value input?
         DUP

      THEN  @ INFORM returned 1, meaning a value was entered
         
         SWAP EVAL EVAL    @ convert input into numeric value
         
         IF    @ is the value valid?
         
            25 OVER ≤      @ 25 ≤ n
            50 PICK3 ≥     @ 50 ≥ n
            AND            @ both conditions must be met

         THEN  @ given value was in range
           
            SWAP     @ swap x<>y
            1        @ signal loop exit

         ELSE  @ value was out of range
         
            "Number is out of range" MSGBOX  @ show range error message
            DROP2    @ drop invalid value and 1 left by INFORM
            0        @ signal that loop should continue

         END   @ range check
         
      ELSE  @ no value to check (user pressed CANCL)
         
         1 @ signal loop exit

      END   @ value input or CANCL?

   UNTIL
      @ either a 0 or 1 should be in stack level 1 at this point
      @ 0 indicates that the loop should repeat
      @ 1 indicates that the loop should exit
   END   @ end of INFORM loop
» 

 

Maké
Level 9
3,551 3,490 180 541
Message 8 of 11
Flag Post
HP Recommended

Hi!: @JKova :

If needed learn with HP50G in RPN, you can see, the next help's ...

1) https://www.hpcalc.org/details/1771

2) https://www.hpcalc.org/details/7141

Too, if needed used the benefict of SysRPL, you can see ...

3) https://www.hpcalc.org/details/5142

The complementary tool's, are ...

EMAC'S 2.11

Extable

OT49

CQIF?

Nosy

You have many examples writed by me ... https://www.hpcalc.org/search.php?query=caporalini&hp49=1

Other's tools are ...

Debug4x, from ... http://www.debug4x.com/

HPUserEdit, from ... https://www.hpcalc.org/details/7587

Kind Regards !.
Have a nice day !.
@Maké (Technical Advisor Premium - HP Program Top Contributor).
Provost in HP Spanish Public Forum ... https://h30467.www3.hp.com/
JKova
Author
Level 4
138 92 2 5
Message 9 of 11
Flag Post
HP Recommended

Hey , 

Thank you and my apologize for picture that are not available to preview or especially view .

I had some problems with HTML on my Android device , because i used to shoot a photo of my HP 50g graphing calculator and something went wrong with that , 

so there I will post that picture so anyone that have a same "problems" can see , hopefully :generic:

photo number onephoto number onepicture number twopicture number twopicture number threepicture number three

thank you for your explanation , 

 Have I nice day  :OpenSmile:,

 

Josip Kova 

0 Kudos
JKova
Author
Level 4
138 92 2 5
Message 10 of 11
Flag Post
HP Recommended

Yeah ,

thank you very much for all these stuff that you put into your message !!

I'm sorry if I don't reply on your demand for accepting a solution , I can't to that because i already had one accepted solution and I give it to David M. 

I had a question for you , you mentioned in message a Debug4x , i think that is somehow name similar to this , but I watch for which systems is suported and I found that i only can get this software on Windows 7 , but I don't have any device ( instead of my PC which i had on other place ) , can i somehow  get this software on Windows 10 ?

 

Thank you for your advices , if you know how to programme in SysRPL than very very ... let supossed I'm saying that is very pleasant to you but I can't garantie that I will succeded that you succeded !

I heard some stuff about programing in SysRPL , but I don't know if all of this guesses true ...

So I'm interseted about speed of runing programs on SysRPL , some say that is much faster than User RPL , and If you know that you can't check your code as you do like in User RPL because compiler does not check your code and if code occures  failure the whole system crashes or something like that or program maybe :HalfEyes:

 

Thank you anyway , but I don't think so that I'll be able to learn SysRPL because lack of time :Crying:

Thank you for your consideration , 

 

Have I nice day ,

 

Josip Kova

 

 

0 Kudos
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation