The Museum of HP Calculators

HP Forum Archive 09

 x=4? FunctionMessage #1 Posted by Shawn on 30 Sept 2002, 8:04 p.m. Hi, I have a HP 42s. I'd like to write my own function or have the calculator evaluate whether x=1? x=2? x=3? x=4?, but the only function that it offers is the relationship to 0. Once the prog. prompts the user to enter 1,2,3 or 4 then it will goto a sub-routine based on the # entered labled w/ corresponding value. Thnx for any help, Shawn

 Re: x=4? Function (correct version)Message #2 Posted by Vieira, Luiz C. (Brazil) on 1 Oct 2002, 6:38 a.m.,in response to message #1 by Shawn Hi; I posted a solution before (30 Sept 2002, 9:24 p.m.) with mistyped values; this is correct. There is an X=Y? function that will do what you want. Look at the samples bellow: (consider FIX 04 as default) - you already have a number in the X-register; the display looks: ``` Y: (anything) X: (your #)``` - you place the number you want to compare: (eg: 4) the display looks: ``` Y: (your #) X: 4.0000 ``` - now you use the function X=Y?; if your number is 4.0000, the display looks: ``` Yes X: 4.0000 ``` - if your number is not 4.0000, the display looks: ``` No X: 4.0000 ``` If you are entering a program, you can choose from both: 1) use specific LBL functions (LBL 01, LBL 02, etc.) If you get in a point where the integer part of the number in the X-register is 1, 2, 3 or 4, you do not need to use X=Y? function; instead, GTO IND ST X will work better. Your program would look like this: (consider step # 20 as a personal choice) ``` (first program steps) . 19 PROMPT (you will input your control # here: 1, 2, 3 or 4) 20 GTO IND ST X 21 LBL 01 (steps when X=1) . 29 RTN 30 LBL 02 (steps when X=2) . 39 RTN 40 LBL 03 (steps when X=3) . . 49 RTN 50 LBL 04 (steps when X=4) . . 59 RTN 60 (rest of the program)``` 2) If your labels have different numbers, your program can be like this: ``` (first program steps) . 19 PROMPT (you input your control # here) 20 1 21 X=Y? 22 GTO xx (label with steps when X=1) 23 CLX 24 2 25 X=Y? 26 GTO yy (label with steps when X=2) 27 CLX 28 3 29 X=Y? 30 GTO zz (label with steps when X=3) 31 CLX 32 4 33 X=Y? 34 GTO ww (label with steps when X=4) 35 ... . . nn LBL xx (steps when X=1) . . .``` If you only have options for 1, 2, 3 or 4, you can eliminate steps 31 to 34; like this: ``` (first program steps) . 19 PROMPT (you input your control # here) 20 1 21 X=Y? 22 GTO xx (label with steps when X=1) 23 CLX 24 2 25 X=Y? 26 GTO yy (label with steps when X=2) 27 CLX 28 3 29 X=Y? 30 GTO zz (label with steps when X=3) (steps when X=4) . . RTN nn LBL xx (steps when X=1) . . .``` If you still need help OR want to know other possibilities and techniques, post your specific problem or e-mail me directly. Best regards.

 I forgot to post my e-mail addressMessage #3 Posted by Vieira, Luiz C. (Brazil) on 1 Oct 2002, 10:12 a.m.,in response to message #2 by Vieira, Luiz C. (Brazil) Just to add my e-mail address I forgot when rewriting the post. Cheers.

Go back to the main exhibit hall