Posted: Wed Oct 21, 2009 1:31 pm Post subject: How to edit files that you open onto a turing run window (text files)
What is it you are trying to achieve?
I am trying to edit text files that are opened onto a run window. I am trying to create microsoft word for a class project, to put you all in context, so think of it as an open file extention that would appear in the file option in the menu.
What is the problem you are having?
I can open the files fine using a GUI.CreateTextBoxFull, but unable to modify the text that appears.
Describe what you have tried to solve this problem
I am stuck, I tried to use the GUI.OpenFileFull before finding out in these forums that it is just a filler, and because Holt's is no longer in operation, it's never going to be of use.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
N/A, but if you can think of anything I can use please include in answer
Please specify what version of Turing you are using
4.0.5
Sponsor Sponsor
Kharybdis
Posted: Wed Oct 21, 2009 2:11 pm Post subject: RE:How to edit files that you open onto a turing run window (text files)
Making even a bad copy of some of the functions of Microsoft Word is extremely hard on Turing.
To start, i would suggest looking into the Open, Get, Close, Seek, and all the statements that would go into File Input/Output.
Don't use Turing's GUI. There's very little you can do to customize it and it limits your options when doing a project.
efan41
Posted: Thu Oct 22, 2009 1:04 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
So are you saying that by using those input/output files I should be able to modify text that appears on my screen? And do you have any suggestions on how I can write it into the program?
BigBear
Posted: Thu Oct 22, 2009 4:31 pm Post subject: RE:How to edit files that you open onto a turing run window (text files)
You do not need to use a GUI text field to get input from the user in fact you do not need to use any GUI commands to make a text editor such as microsoft word.
you can use
"get"
to accept input from the user
once you have gotten information you will need to write it or "put"it to the file
while in Turing press F10 to open help and search for "get", "put" and "open"
efan41
Posted: Fri Oct 23, 2009 1:06 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
BigBear I don't think you understand what I'm trying to say.
Picture a microsoft word screen. Now picture that screen opening a file. I can do that with my turing program, but I can't figure out how to edit the text that has appeared on the screen.
If any of you would like to see what I have so far let me know and I can send you the program via e-mail, and if you have any suggestions don't hesitate to mention them.
Zren
Posted: Fri Oct 23, 2009 3:09 pm Post subject: RE:How to edit files that you open onto a turing run window (text files)
View.Set("text")
This line will allow normal put "" output to be selectable and copyable. However, you still can't edit it.
For a small implementation. You could create a string, that you might modify after every keypress in a loop.
Take a look at string manipulation and advanced input from this thread for help with getting input. I suggest the chr() and ord() functions mixed with the Input.KeyDown() method of input in order to determine what to add to the string. If the backspace flag was pressed, you can take the last character out of the string.
saltpro15
Posted: Fri Oct 23, 2009 3:51 pm Post subject: RE:How to edit files that you open onto a turing run window (text files)
Look in the Turing examples folder, there's a netchat program that has exactly what you're looking for.
efan41
Posted: Fri Oct 23, 2009 8:30 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
Well Zren, as a matter of fact I have been using the chr () but I'm having difficulty with the ord() Is that normal? And For the backspace it was a big pain because of the fact that I have to re-arrange the x and y parameters for my locate, but anyways, thanks for the advice.
Sponsor Sponsor
efan41
Posted: Fri Oct 23, 2009 8:39 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
thanks for the tip Saltpro15,
but how does this program relate to opening a pre-saved text and then modifying that text?
I don't see the relation, but I'm really tired and not exactly what you would call an expert with Turing. If you wouldn't mind pointing out what in the netchat program would help me, I would really be greatfull.
efan41
Posted: Wed Nov 04, 2009 2:54 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
K well I figured it out on my own. Thanks for all the replies!
Kharybdis
Posted: Wed Nov 04, 2009 3:18 pm Post subject: RE:How to edit files that you open onto a turing run window (text files)
Post what you have. I'm just curious as to what you have done.
Superskull85
Posted: Wed Nov 04, 2009 9:31 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
efan41 @ Fri Oct 23, 2009 8:30 pm wrote:
...And For the backspace it was a big pain because of the fact that I have to re-arrange the x and y parameters for my locate, but anyways, thanks for the advice.
If you are using a string to store the document text in you do not need to worry about positioning the cursor. Instead just delete the character directly before the current cursor position within the string.
I created a similar program a while back where I stored the document in a "TextString" class I created that allowed me to store as much characters as I wanted, and at the same time allowed me to modify the contents of the TextString object using methods. I used a flexible array of characters as the main storage (could of used a linked list or similar), and manipulated the array to change the text of the document.
I was able to visually keep track of where the cursor was by inserting a "|" into the TextString object where the cursor currently lied within the document. For navigation I used the arrow keys to move back and forth between characters, and used a grid approach to move the cursor up or down relative to its previous position. For example, if the length of two rows A and B were 5 and 9 characters long respectively, the grid would be 5x2. If the previous cursor position was 3 on row B, than I would move it up to position 3 on row A. If the position was 7 on row B, I would move the cursor to position 5 on row A.
The length of each row was determined by searching for the new line character (\n) relative to where the cursor lied. For example, if a section of the document contained:
"\nThis is an example row.\nThis is another example row which is longer.\n"
Row A would be, "This is an example row." and row B would be, "This is another example row which is longer."
Anyways it took me a bit to figure out and create, and I only created it to prove that a text editor created using Turing was possible.
efan41
Posted: Thu Nov 05, 2009 2:08 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
Well what I have so far isn't perfect, it's a semester-long project that isn't due until january, so I still have things to do to it. And it's kind of long to put on here, so I'll have it as an attachment.
As for the backspace, I am doing it in a string, but I'm not sure I understand how you got the backspace to work, and I would like it if you could explain how you managed to save as many charatcers as you want, seeing as Turing will only let you save something like 250 per variable..
Turing_Word_Stephane_ v3.t
Description:
This is what I have so far. Suggestions and modifications are welcomed
Posted: Thu Nov 05, 2009 4:50 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
For the storage of the text I used a flexible array of characters. Every time I wanted to add more text I would extend the array and add the text/characters in. I could of used a linked list (each link would contain a char attribute) or similar, but I thought of using a flexible array first so I stuck with it.
Anyways, for the backspace say the cursor is at the end of the text (which I will refer to as length). The backspace button in a text editor deletes the character directly before it. So by pressing the backspace you would delete the character at position (length - 1). For example if you had the text, "This is an example", and the cursor was at the end of the text you would delete the character "e" from the end when the backspace button is pressed.
To delete a character from the end of a string:
Turing:
MyString = MyString (1.. * - 1)
Where MyString is any string variable (var MyString : string).
You can check for the backspace key (including all other keys) using Turing's Input module.
efan41
Posted: Fri Nov 06, 2009 2:20 pm Post subject: Re: How to edit files that you open onto a turing run window (text files)
Well Superskull that would have solved my problem if I were using a variable for all my characters that I type onto the screen, however that isn't quite the case.
Turing:
if chars ('z')then%If the user hits the "z" key if chars (KEY_SHIFT)then%If the user hits the "z" key while holding the shift button put"Z" .. %Obviously, put a capital "z" on the screen
characteres :="Z"%Used to save the file
backspace %Procedure called that changes the value of y. (y:= y + 1) else%If the user dosen't hold the shift key while pressing "z" put"z" .. %Puts a "z"
characteres :="z"%Used to save the file
backspace %Procedure called that changes the value of y. (y:= y + 1) endif endif
This is an example of what would happen if the "z" key was pressed. My teacher told me I couldn't just use a get because it'd be to easy...So because I'm not using a variable for the caracters, I can't use your method.
Here's what I have so far for the backspace procedure from earlier:
Turing:
proc backspace
if y < 125then%If y is smaller than 125Because a "y" value in a locate cannot excede 125
y := y + 1%Add 1 to "y"'s value else%If "y" is = or superior to 125
y :=1%Reset's "y"
x := x + 1%Add's 1 to "x"'s value, so it'll change rows when it locates endif end backspace
The character that is supposed to be erassed is erassed, but the cursor seems to be corresponding with the else part of that last procedure, even though y is smaller than 125.. Any thoughts?