|
Here is another version. This came from midrange computing back when they had a BBS: parse arg string parse value space(string) with "'"expression"'" interpret 'answer =' expression answer = strip(expression) '=' answer 'SNDPGMMSG MSG(&answer)' exit syntax: syntaxerr = errortext(rc) 'SNDPGMMSG MSG(&syntaxerr)' there was also a command and a panel group for help. the command was fairly simple also /* CRTCMD CMD(xxxxxxxxxx/XCALC) PGM(*REXX) + /* REXSRCFILE(zzzzzzzzzz/QREXSRC) /* where: /* xxxxxxxxxx = the object library for the command /* zzzzzzzzzz = the REXX source file library /* /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * CMD PROMPT('Expression Calculator') PARM KWD(EXP) TYPE(*CHAR) LEN(128) MIN(1) + PROMPT('Mathmatical expression') The help panel group is much to large to list here. Some snippets: XCALC '(14 * 63.5) ** 3' which will return the completion message: (14 * 63.5) ** 3 = 702595369 For example, if you want to convert decimal 179 to hexdecimal, enter: XCALC 'd2x(179)' which will return the completion message: d2x(179) = B3 d2x() is the REXX function to convert Decimal to heXdecimal. The data conversions available in the AS400 implementation of REXX are: b2x() binary to hex x2b() hex to binary c2d() character to decimal (EBCDIC) d2c() decimal to character (EBCDIC) c2x() character to hex (EBCDIC) x2c() hex to character (EBCDIC) d2x() decimal to hex x2d() hex to decimal Mixed conversion functions are also supported. For example, to multiply hexdecimal 8F times decimal 19 and receive the answer in hexdecimal format, enter the following: XCALC 'd2x(x2d(8F) * 19)' which will return the completion message: d2x(x2d(8F) * 19) = A9D This ability to mix data conversions also allows you to "fill in the gaps" that are missing in IBM's 400/REXX implementation. For example, there is no function that will directly convert binary to decimal. However you can combine two fuctions to get the job done. So to convert 100101 to decimal, enter: XCALC 'x2d(b2x(100101))' which will return the completion message: x2d(b2x(100101)) = 37 The binary number 100101 is converted to an intermediary hexdecimal value, which is then converted to a decimal value of 37. Extra Goodies: Even some non-math REXX functions can be executed through the XCALC command. For example, to get today's date, enter: XCALC 'date()' or to get the current day of the week, enter: XCALC 'date(W)' or for the current time try these: XCALC 'time()' XCALC 'time(C)' XCALC 'time(L)' or try this one for a little fun: XCALC 'reverse("this is a test")' Bryan Dietz 3X Corp. +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to MIDRANGE-L@midrange.com. | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.