Page 1 of 1

basic help - reading strings

Posted: Sun May 23, 2010 11:43 pm
by pucker22
Hi,

How do you read from a file and place that text into a field, I tried this with no luck:-

Code: Select all

read from file"C:\Users\Andrew\Desktop\demo.txt" for 1 and put into field 'Field'
Also how do you read multiple lines? How do you identify each line with its own string such as line1$ line2$ line3$ etc etc....

Also how do you save multiple lines??

Sorry I have no clue I never used runrev much!

Re: basic help - reading strings

Posted: Mon May 24, 2010 10:47 am
by jmburnod
Hi Pucker 22,

Try this :

Code: Select all

    put "C:\Users\Andrew\Desktop\demo.txt" into MyFile
    open file MyFile 
    read from file MyFile until eof
    close file MyFile
    put it into fld TheField
Best

Jean-Marc

Re: basic help - reading strings

Posted: Mon May 24, 2010 12:18 pm
by Klaus
Hi Pucker,

to avoid too much typing you could also use the "url" systax!

1. Read a text file and put it into a field:
(Hint: Rev always uses the UNIX path delimiter SLASH internally!)
...
put url("file:C:/Users/Andrew/Desktop/demo.txt") into field "Name of your field here"
...

2. You can also specify CHUNKS of text to be read:
...
## Only first three character
put CHAR 1 to 3 of url("file:C:/Users/Andrew/Desktop/demo.txt") into field "Name of your field here"
...
## Only line 1, 2 and 3
put line 1 to 3 of url("file:C:/Users/Andrew/Desktop/demo.txt") into field "Name of your field here"
...
## Last line of file
put line - 1 url("file:C:/Users/Andrew/Desktop/demo.txt") into field "Name of your field here"
...

3. To read non contiguous lines you need to read the whole file and then extract the lines (or characters) you need
## Read complete file into a variable
put url("file:C:/Users/Andrew/Desktop/demo.txt") into tVariable
put line 1 of tVariable & CR & line 4 of tVariable & CR & line 88 of tVariable into field "Name of your field here"
...

To wite content to a file do this the other way round :-)

1. Write content of variable to file
...
put tVariable into url("file:C:/Users/Andrew/Desktop/demo.txt")
...

2. Content of a field
...
put field "Your field" of cd 1 of stack "whatever stack the field is in" into url("file:C:/Users/Andrew/Desktop/demo.txt")
...

3. Non contiguous lines of variable oor field
put line 1 of tVariable & CR & line 4 of tVariable & CR & line 88 into url("file:C:/Users/Andrew/Desktop/demo.txt")
...

Hope that helps!


Best from germany

Klaus

Re: basic help - reading strings

Posted: Mon May 24, 2010 2:46 pm
by dunbarx
Hi.

But much more importantly, you need to first play around with a stack, making a few objects work in different ways. Your introductory post indicates that you need to become more familiar with the basic syntax of writing scripts.

Make a button that calculates the tax on an item. You will have fun making the interface and functionality work the way you (finally) like it to. Make an address book.

You will be amazed at how soon you will see what was wrong (basically, not conceptually) with your line of code.

And always ask for help.

Craig Newman

Re: basic help - reading strings

Posted: Mon May 24, 2010 3:13 pm
by Klaus
And don't forget to go through all these insanely great tutorials 8) :
http://www.runrev.com/developers/lesson ... nferences/


Best

Klaus