what is the best code routine for word wrapping? I am making a simple TIWORD program for my calc., and when it stores the pages, if a line is over 23 characters it runs the message off the screen! Sad CAN ANYONE HELP ME?!?!?!?! Surprised

PLEASE I NEED HELP its the first real program ive made that isnt a volume equation for cylinders. if you have knowledge of a word wrapping code for entering text as a picture, please post a reply! thanks! TI-84+ SE
Hmmm, *word* wrapping would be hard. I can help you with character wrapping, check the length of the string, and if its greater than or equal to 23, you can use sub( to get part of it, and only display that part.
ok, but ive tired a simple code, something like:
:If length(Str1)<23:Text (1,1,Str1
:If length(str1)>23:Text (1,1,length(Str1)<23:Text (1,6,length(Str1)>23

what am i doing wrong here? how does the sub( routine work? not that i havent made programs before but these complicated commands are allitle over my head...
Ah, I see what you are doing wrong here. Change the second line:
:If length(str1)>23:Text (1,1,sub(Str1,1,23
This won't wrap the text, though, it will just stop at the edge of the screen. If you want to wrap it, I would suggest a different method, where you use a variable to keep the index of your pointer in the string, and update the index with the next position.
Welcome to Cemetech, rcplanegy! I'm glad to see that you took my suggestion of posting your question here, and I very much hope that you'll stick around to continue telling us about your projects and asking any questions we may be able to answer. So, I'll expand on the correct solution that SirCmpwn suggested. Based on your code fragments, I'll offer some code that will print Str1 on the graphscreen, using *letter* wrapping (as opposed to word wrapping, just to be pedantic, which doesn't split words in the middle but which is uselessly difficult for your purposes).


Code:
:1->X:0->A
:While X<length(Str1)
:min({23,length(Str1)-X+1
:Text(A,0,sub(Str1,X,Ans
:X+Ans->X:A+6->A
:End


So, let me explain my code line-by-line:

:1->X:0->A
We'll use X as the current offset into the string. 1 is the first character in the string, of course. A will be the y-coordinate of the text to be printed onscreen, and we'll move A down by 6 pixels per line.

:While X<length(Str1)
We'll be increasing our offset pointer until we get to the end of the string. Unfortunately, this assumes that the string no larger than the screen, (23*(62/6)) = 230 characters, but I think you told me in your email that 230 characters was your max. Smile

:min({23,length(Str1)-X+1
This line finds how many characters we need to display. If there are only 10 characters left in the string that we haven't displayed, we only want to display 10 characters, so length(Str1)-X+1 will be smaller than 23. If there are more than 23 characters left undisplayed in the string, we still only want 23, so 23 will be the smaller of the two.

:Text(A,0,sub(Str1,X,Ans
Display the substring! Up to 23 characters

:X+Ans->X:A+6->A
Ans is still the min({23,length(Str1)-X+1) value, so we'll move X forward by the number of chars we displayed. We'll also move A down 6 pixels.

:End
Loop back up to the While
oh,wow.. i nevre thought of it that way... hmm... could this be expanded to, say, 10 strings? my program inputs 10 strings then stores them on a picture. if this could be done X10, that would greatly decrease the size of my program. would this need 10 variables though? or would i just repeat that code ten times? or do i even need to do it X10? is there a way to keep 'letter' wrapping for ten lines? sooo many questions... but thanks this is helping alot! Laughing
rcplanegy wrote:
oh,wow.. i nevre thought of it that way... hmm... could this be expanded to, say, 10 strings? my program inputs 10 strings then stores them on a picture. if this could be done X10, that would greatly decrease the size of my program. would this need 10 variables though? or would i just repeat that code ten times? or do i even need to do it X10? is there a way to keep 'letter' wrapping for ten lines? sooo many questions... but thanks this is helping alot! 0x5
So the code that I presented above already renders ten lines from Str1, perhaps I'm misunderstanding your question? When you say ten different strings, do you want ten different "documents", or do you mean to store ten different lines of the same "document"?
ten diffenet lines, sorry. it stores 10 lines of text and #'s on 1 page (picture) and i have it so that there are 5 pictures, or five documents. so this little code will work then? i guess im asking: this code will take up to 230 carachters stored on Str1 and enter them on a graph screen, putting 23 characteers on 10 lines, correct?
rcplanegy wrote:
ten diffenet lines, sorry. it stores 10 lines of text and #'s on 1 page (picture) and i have it so that there are 5 pictures, or five documents. so this little code will work then? i guess im asking: this code will take up to 230 carachters stored on Str1 and enter them on a graph screen, putting 23 characteers on 10 lines, correct?
That's exactly correct. It'll display anywhere from 1 character on one line to 230 characters spanning ten lines, depending on the length of Str1. I didn't provide any explicit error-checking on the max length of Str1, so more than 230 characters will cause a domain error (ERR:DOM) as it tries to draw off of the bottom edge of the screen.

Sidebar: Do you use Doors CS? Smile
http://dcs.cemetech.net
ok thanks Kerm ill try that out thats what i was looking for.
rcplanegy wrote:
ok thanks Kerm ill try that out thats what i was looking for.
Excellent, post here when you give it a try. Was my explanation of how the code works clear? Do you follow its flow?
yeah i get it. i remember when i started programing 3 years ago i always wondered what While and End were for... Razz
... ITS NOT WORKIING Sad ill keep you updated, changing some things around...
no double posting Razz
sorry i got it to work at last Very Happy forgot to input Str1 DUH im an idiot but yes it works thanks Kerm.
rcplanegy wrote:
... ITS NOT WORKIING Sad ill keep you updated, changing some things around...
As qazz42 says, if it's within 12 to 24 hours of your last post in the topic, please edit your post rather than doubleposting. After about 24 hours, double-posting to "bump" a topic is generally acceptable.

Can you be more specific about the code not working? Does it malfunction? Does it throw an error? Both? Did you double-check that you copied it properly?
no i got it to work and oh... i didnt know you could edit sorry bout that
rcplanegy wrote:
no i got it to work and oh... i didnt know you could edit sorry bout that
Sure thing, don't worry about it; now you know. I'll be angrier if you continue to double-post though, as Qazz42 did before he learned some netiquette. Smile So now that your original request is coded and working, how can I/we help you expand this fairly simplistic routine to do more?
well... some other questions i have dont have much to do with word wrapping, but it would make my program awsomer! like on the MEM RESET menu <2nd><+><7> is there any way to make multiple menus side-by-side and use the left and right arrows to choose between menus? and also, menus that are longer than 7 options: i tried it once and kept getting error messages; how it that accomplished?
Sadly, both of those things are impossible. You can make menus with a lot of options with DoorsCS libraries Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement