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.
def var myvar as char.
myvar = "c:\file.txt".
output to value(myvar).
....
....
HTH
j d
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#.
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.
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.
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
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
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.
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.
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.
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.
I agree, but I was just highlighting it as an option. Perhaps you can store it away and re-instate if if required.
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.