How to "OUTPUT TO" to a variable?

Posted by Admin on 13-Mar-2007 22:58

Need help, I want to pass the content created by OUTPUT TO statement to a variable, can I do this? how to do this?

Thanks in advanced.

Benny.

All Replies

Posted by Admin on 14-Mar-2007 09:21

def var myvar as char.

myvar = "c:\file.txt".

output to value(myvar).

....

....

HTH

j d

Posted by Admin on 14-Mar-2007 14:55

With "INPUT THROUGH" you can capture standard input from an OS-command. With "INPUT FROM" you can read a file, directory.

You normally associate a STREAM with INPUT or OUTPUT statements, so you explicitly say that you're using something else than standard input/output.

You can't write something "transparantly" to a string like you can via a StringWriter in Java/C#.

Posted by Admin on 14-Mar-2007 20:59

thanks wahabstl.

actually what I want here is the result from output to can be stored inside the myvar, not as a file, so that i can just read the myvar, not read it from the text file.

is there a workaround for this?

thanks.

Posted by Admin on 14-Mar-2007 21:02

thanks theo.

what i want here is the result of output to can be stored in a variable (not to a text file), so that I can just read (programatically) the variable, not read from the text file.

so that from your reply i assume that i cannot do that, right?

is there a workaround for this?

thanks.

Posted by akjump on 15-Mar-2007 06:03

Benny,

It is not possible to use the OUTPUT TO statement to a variable. Neither can you use a memptr.

I am not sure why you need to use the OUTPUT TO statement to be stored in a variable, but if the OUTPUT TO statement is a neccesity, then have you tried outputting to the clipboard? This is basically using the standard windows clipboard memory to store the information, which can be read back into the code quite easily!

The only downside, is the fact that the clipboard is restricted in size to 64kb of data, apparently.

If this is not an option, then I would find an alternative to using OUTPUT TO!!

Andy

Posted by Alon Blich on 15-Mar-2007 06:22

Hi Benny,

You can't redirect OUTPUT TO into a variable but you can just as well read the file into varable afterwards.

With INPUT FROM/IMPORT into either a CHARACTER, RAW or MEMPTR. Starting from OE10 there's also COPY-LOB.

Have a look at the some of the examples in the online help (F1) or the Language Reference doc. HTH

Posted by Thomas Mercer-Hursh on 15-Mar-2007 10:41

And, of course, in order to get what you want in a variable, you don't need output to at all ... just compose the variable.

Posted by jquerijero on 03-Feb-2011 11:00

Can you give a case where "OUTPUT TO" a variable is more convenient if it is supported? I don't quite get it why appending to a CHAR or LONGCHAR will not suffice.

Posted by AdrianJones on 03-Feb-2011 11:34

If you're GUI you could use the clipboard option...

DEFINE VARIABLE cMyVar AS CHARACTER   NO-UNDO.

OUTPUT TO "clipboard".

PUT "hello" SKIP.
PUT "world" SKIP.

OUTPUT CLOSE.

ASSIGN cMyVar = CLIPBOARD:VALUE.

MESSAGE cMyVar
  VIEW-AS ALERT-BOX INFO BUTTONS OK.

Posted by Admin on 03-Feb-2011 11:41

As a user I would hate the developer for this abuse of the clipboard. The clipboard should be reserved for the users purpose, not a programmers vehicle.

When GUI for .NET is an option, consider the use of their StringWriter class, which extends the .NET stream.

Posted by AdrianJones on 03-Feb-2011 11:54

I agree, but I was just highlighting it as an option. Perhaps you can store it away and re-instate if if required.

Posted by Admin on 03-Feb-2011 12:11

I am very skeptical about that. Consider other clipboard formats than plain text...

But this thread is 4 years old. I'm sure the OP has a solution by now.

This thread is closed