control string in variable

sguccione

New Member
I'm attempting to take a character string out of a database and pass it to my printer as a control string. When I use PUT CONTROL CHR(27) "m", with the values hard-coded, it works fine. Once I try to reference the character database field or a variable, the string no longer works. I can also use :

Define Variable w-Control as character.
w-Control = Chr(27).
w-control = w-control + "m".
Put control w-control.

But since I need to retrieve the control string from the database, I can't use either hard-coded version. Any help on this would be greatly appreciated. My deadline is coming up fast!

Stacy
 
Try storing the integer value of the control string and then putting CHR(value) "m" as before. Bit of a cheat but if it works....!
 
I used the sports database to do the following test and it works fine.
Code:
output to c:\test.dat.
create Customer.
assign Customer.Address = "~033M".
put control Customer.Address.
output close.
delete Customer.
How are you getting the control characters into the database field using the octal representation shown above?

Many people prefer not to use octal representations and develop their own method. If you are using your own layout will need to parse it first and replace the user entered data with actual control characters. (eg. if the entered string is "\027m" you will need to find the "\027" string and replace with the actual character chr(27)).

Here is a little function that converts user entered control codes (in the format shown above) to the proper asc strings. Your code then just needs to do a PUT CONTROL expand-string( <table>.<field>).
Code:
function expand-string returns char (ipc_string as char) :
def var li_pos as int init 1 no-undo.
def var li_asc as int no-undo.
def var lc_tmp as char no-undo.
def var lc_return as char no-undo.

  do li_pos = 1 to length(ipc_string):
      lc_tmp = substring(ipc_string, li_pos, 1).
      if lc_tmp = "\"
      then do:
          if substring(ipc_string, li_pos + 1, 1) = "\"
          then assign
              lc_return = lc_return + "\"
              li_pos = li_pos + 1.
          else do:
              li_asc = int(substring(ipc_string, li_pos + 1, 3)) no-error.

              if error-status:error or li_asc > 255
              then lc_return = lc_return + "\".
              else assign
                  lc_return = lc_return + chr(li_asc)
                  li_pos = li_pos + 3.
          end.
      end.
      else assign
        lc_return = lc_return + substring(ipc_string, li_pos, 1).

    end.
    return lc_return.
end function.
 
Back
Top