Set a Variable in Hexadecimal Value RPG or CL

5 pts.
Tags:
AS/400
AS400 Command
Hexadecimal values
Hi everybody, I would like to use variable value for settin color on display, I usually do as follow: D $color S 1A INZ C eval $color = X'28' and obtain color red ! Now my user would like to change it and type 38 into the numeric variable $V1. $v1 = 38 . It seems to me that new command could be: Eval $color = X+''''+$v1+'''' Compiler doesn't issue error, but unfortunatly, in debug mode $color contains 'X' insted of x'38'. Can Someone help me, for RPGLE or CL please ? thanks

Software/Hardware used:
OS400, RPGLE

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    More info is needed. You say "...type 38 into the numeric variable $V1", but you don't show us how the input field is defined nor how variable $V1 is defined. We can't guess how the input operation will behave without knowing the definitions. Then you show the [ Eval $color = X+''''+$v1+'''' ] instruction. But you don't show the definition of variable X nor of variable $color. It's not clear if that is an exact copy of the instruction or if you typed it into your question and made an error in typing. You might intend the "X" to be a literal, in which case it probably makes sense that variable $color contains "X". That's what you put into it. If you put an "X" into a variable, you should expect to find an "X" there. We need to see the definitions along with the entire sequence of instructions that alter the values. Beyond that, having a user type a numeric value into an input variable in order to change a display attribute is trouble. The value is a hexadecimal value, not a decimal value. A user shouldn't be expected to know anything about hexadecimal display attribute values. Please describe the actual business problem that you are trying to solve. We can suggest good ways to solve that problem, and it's almost certain that it won't be done by typing numeric values in. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Not my styl but perhaps some logic like this. D CRed C X'28' Select; when $v1 = 28; $Color = CRed; But why not have the user enter or select the value RED instead of 28? Phil
    49,960 pointsBadges:
    report
  • bvining
    I consider this a rather dangerous thing to give a user unless you're editting to make sure they only key in numeric values corresponding to display attributes, but since you asked... The following RPGLE example shows how to take a 2-digit numeric field an then convert it to a 1-byte character field where the first digit is the first nibble of the byte and the second digit the second nibble. (Note that this editor has historically done very nasty things to my code, so you may have to be just a little flexible when reading this) h dftactgrp(*No) bnddir('QC2LE') d CvtCH pr extproc('cvtch') d Target 1a d Source 2s 0 d LenSource 10i 0 value d $V1 s 2s 0 d $Color s 1a /free $V1 = 38; CvtCh($Color :$V1 :%len($V1)); *inlr = *on; return; /end-free The variabe $Color is set to the value x'38'. The same can be do using ILE CL. Bruce Vining.
    6,495 pointsBadges:
    report
  • TomLiotta
    The whole idea of typing into a numeric field to control a hex value needs more thought since it'll be tricky typing "2A", "2B" or any of the other values that use non-numeric hex digits. What is the point? What is the business problem that needs to be solved? -- Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following