Re: Question about print,puts,get,gets,...
- Posted by david at aldred.demon.co.uk Jun 11, 2001
- 381 views
In message <0.1700008810.705892030-212058698-992210473 at topica.com>, Frank <sekret7 at hotmail.com> writes >I need help. I am new to Euphoria or any other programing language. >For start I was learning how to devenlope a diferent kind of windows >in Windows mode. Now I am trying to learn how to open-close file, >type of variable, work with different kind of data. > >Here is my problem: Here are some answers! (NB: I haven't tested exactly what's given below). >1.I want to enter text data to EditText control in window. If you want your program to enter the text, then you need to use setText (EditText, "Your Text") (Assuming EditText is the name of your control). >2.Get it from control and put it to file.dat as part of sequence. > {"Tim","Mary","David",...} To get what is in the EditText control, use MyString = getText (EditText) where MyString has been declared as a sequence. Then you need to put MyString into a sequence. If you have three of them, you can do this simply by saying: seq = {MyString1, MyString2, MyString3} To write this to a file, open the file using fn = open ("Filename","w") then print the Euphoria sequence to the file using: print (fn, seq) then close the file: close (fn) >If I look file.dat I wish to see it as writen above. Actually, you won't. You'll see it written in a series of character codes separated by commas and braces. If you really want it legible outside Euphoria, you'll probably need to use printf (fn,"{\"%s\",\"%s,\",\"%s\"}", {MyString1,MyString2,MyString3}) instead of that print statement above: what that is doing is outputting a {, followed by a " and the first string, followed by "," then the next string, and so on, finishing off with a }. Unless you actually need to be able to read the file outside Euphoria, this approach is messier and less flexible: you have to know the number of items in the sequence, for example, which isn't always the case. >3.Get the data from file.dat as sequence, becouse I will need >seq[1] or seq[2],... to be writen in window. Open the file for reading fn = open ("Filename","r") ..then use 'get' to get the sequence: result = get(fn) ..if it worked, then result[1] will be equal to GET_SUCCESS, and result[2] will contain your sequence: if result[1] = GET_SUCCESS then seq = result[2] end if ..then close the file... close (fn) Hope this helps, -- ------------------ ------------------------- |\avid Aldred / David at aldred.demon.co.uk \ Nottingham, England |/ --------------------------------