Computer Science Canada REALLY LONG TEXT "Formatting" |
Author: | nate [ Mon Apr 14, 2003 5:45 pm ] |
Post subject: | REALLY LONG TEXT "Formatting" |
I am wondering what how you would use a procedure and make a 3 - 5 not have anywords cut off when they reached the end of the run window. I want the text to wrap after the 40th character? How do I do that? What is the code? Any help would be greatly apreciated -Nate |
Author: | Blade [ Mon Apr 14, 2003 5:48 pm ] | ||
Post subject: | |||
it auto-wraps for me.... like if i went
if that isnt what you mean, then please specify |
Author: | nate [ Mon Apr 14, 2003 5:51 pm ] |
Post subject: | |
No becuase when you type something very long it will cut off some of the words if they are near the end. I wan't it to cut off after 40 characters. Do you know how 2 do that? -Nate LOOK BELOW FOR REAL QUESTION!!!! |
Author: | nate [ Mon Apr 14, 2003 5:53 pm ] |
Post subject: | MY MISTAKE |
How do you make sure that text (words) is not cut off at the end off each line? ex. Hello this is just an example becuase you might not understand me but thi s has been cut off like what would happen in turing I want to make sure that is does not happen. "THIS" WAS CUT off how do u make that not happen? using a procedure SRY -Nate |
Author: | Blade [ Mon Apr 14, 2003 6:55 pm ] |
Post subject: | |
ooh i understand hahah.... use multiple puts |
Author: | Tony [ Mon Apr 14, 2003 7:07 pm ] | ||
Post subject: | |||
ahh... I suppose you use a counter for each line and see if there's enough space left for the next word. If not you use
|
Author: | Mephi [ Mon Apr 14, 2003 7:55 pm ] |
Post subject: | Wrap |
how do you put a counter? cuz i wanna do the same thing....tony i added you to my msn, chann23@hotmail.com thats me...plz explain, i really need to know!! |
Author: | Ancalagon The Black [ Mon Apr 14, 2003 8:19 pm ] |
Post subject: | |
Or you could use locate statements just befor the put statement to centre it or watever. |
Author: | DarkHelmet [ Mon Apr 14, 2003 8:28 pm ] |
Post subject: | |
The following coding will wrap text at the fortieth character. This is just in case the program isn't supposed to know what text it is outputting before it is run. The only problem is that if you somehow give it a word with more than 40 characters, it will never finish. var strtext : string var intwords : int var intcounter : int get strtext : * var intcount : int var strline : string var intline : int intwords := 0 for i : 1 .. length (strtext) if i > 1 then if strtext (i - 1) not= " " then if strtext (i) = " " then intwords += 1 end if end if end if if i = length (strtext) then if strtext (i) not= " " then intwords += 1 end if end if end for var strwords : array 1 .. intwords of string for i : 1 .. intwords strwords (i) := "" end for intcounter := 1 for i : 1 .. length (strtext) if i > 1 then if strtext (i - 1) not= " " then if strtext (i) = " " then intcounter += 1 end if end if end if if strtext (i) not= " " then strwords (intcounter) += strtext (i) end if end for intcounter := 0 intcount := 0 intline := 1 cls strline := "" loop intcount += 1 if intcounter + length (strwords (intcount)) <= 40 then intcounter += length (strwords (intcount)) + 1 strline += strwords (intcount) + " " else put strline if intline = maxrow then Input.Pause intline := 0 cls end if intline += 1 intcounter := length (strwords (intcount)) + 1 strline := strwords (intcounter) + " " end if exit when intcount = intwords end loop |
Author: | Prince [ Mon Apr 14, 2003 8:29 pm ] |
Post subject: | |
yea but then if u had like a full out paragraph (y u would hav this in turing i dont kno but...) ud fill up the source code with locates |
Author: | nate [ Mon Apr 14, 2003 8:33 pm ] |
Post subject: | Rest of Text |
How do you make it so that the rest of the text shows up below it? What you have done is awsome but I still need to know this I will donate 15 bits if you can tell me -Nate |
Author: | DarkHelmet [ Mon Apr 14, 2003 8:33 pm ] |
Post subject: | |
That still has bugs in it. still fixing it. |
Author: | nate [ Mon Apr 14, 2003 8:35 pm ] |
Post subject: | thanks |
thanks could you sort of explain a little what you have done? It is sort of confusing! -Nate |
Author: | Mephi [ Mon Apr 14, 2003 8:38 pm ] |
Post subject: | Text Wrap |
yea i need to kno too! i only got 2 bits cuz this is a new account but im willin to give those up! btw, thx...i really appreciate this! |
Author: | DarkHelmet [ Mon Apr 14, 2003 8:49 pm ] |
Post subject: | |
var strtext : string var intwords : int var intcounter : int get strtext : * var intcount : int var strline : string var intline : int intwords := 0 for i : 1 .. length (strtext) if i > 1 then if strtext (i - 1) not= " " then if strtext (i) = " " then intwords += 1 end if end if end if if i = length (strtext) then if strtext (i) not= " " then intwords += 1 end if end if end for var strwords : array 1 .. intwords of string for i : 1 .. intwords strwords (i) := "" end for intcounter := 1 for i : 1 .. length (strtext) if i > 1 then if strtext (i - 1) not= " " then if strtext (i) = " " then intcounter += 1 end if end if end if if strtext (i) not= " " then strwords (intcounter) += strtext (i) end if end for intcounter := 0 intcount := 0 intline := 1 cls strline := "" loop intcount += 1 if intcount > intwords then put strline exit end if if intcounter + length (strwords (intcount)) <= 40 then intcounter += length (strwords (intcount)) + 1 strline += strwords (intcount) + " " else put strline if intline = maxrow then Input.Pause intline := 0 cls end if intline += 1 intcounter := length (strwords (intcount)) + 1 strline := strwords (intcount) + " " end if end loop this works a bit better the first loop it has runs through the coding counting the number of words by looking for spaces. When it finds a space, it knows to add 1 to the number of words. The next loop separates each word, so they can be rearranged later. The last loop has a variable for how long the line of text is, and to store the lines of text. It adds the individual words to the line of text, until it knows that line of text will be over 40 digits with the next word. When that happens, it outputs the current line of text to the screen, clears the variable with the line of text in it, and then starts over at the next word. |
Author: | Mephi [ Mon Apr 14, 2003 9:00 pm ] |
Post subject: | Text Wrap |
THX MAN!! i really needed that! i gave ya 2 bits... hope it helps! |
Author: | DarkHelmet [ Mon Apr 14, 2003 9:10 pm ] |
Post subject: | |
No problem. I used coding similar to that when i was making my final project. Needed it for the chance cards in my monopoly. |
Author: | nate [ Mon Apr 14, 2003 9:25 pm ] |
Post subject: | Variable meaning? |
What do some of the variables mean? like you have var intcount :int and var intcounter : int does str mean string or start or something elsecould you tell me plz -Nate |
Author: | Tony [ Tue Apr 15, 2003 10:11 am ] |
Post subject: | |
I belive that its a programming standart where you put variable type in front of varaible name to remember what values it can hold. such as intCounter:int and Counter:int are no different. but int in front reminds you its of int variable type |
Author: | Ancalagon The Black [ Tue Apr 15, 2003 8:14 pm ] |
Post subject: | |
Usually you want to try to declare your variable names something that is easy to remember. I usually capitalize mine (cause it looks better and because our teacher wants us to) but ultimately it doesn't matter. You can call a variable "Name" and use it to get someone's age. The program doesn't care, just as long as you keep them consistent throughout the entire program. |
Author: | Dan [ Tue Apr 15, 2003 9:06 pm ] |
Post subject: | |
it dose not relay matter but uhsley you only fully captiozae varible names if they are gloab or constants. |
Author: | DarkHelmet [ Tue Apr 15, 2003 9:19 pm ] |
Post subject: | |
i just use that way of naming because that is the only method that my teacher accepted. I got used to it, now it's the only way i usually name my variables. i also find it's inconvient to capitalize my variables. When you declare them with upper case, i think you have to type them as upper case every time. I could be wrong. Whenever i have to type them upper case i always forget to do it one or two times. Then it gives me an error. It is just easier to keep everything lower case. |
Author: | Catalyst [ Tue Apr 15, 2003 9:47 pm ] |
Post subject: | |
i usually do vars lower and const upper the classes with caps on first letter |
Author: | Tony [ Tue Apr 15, 2003 10:19 pm ] |
Post subject: | |
mine are small letters unless varaible is more then 1 word. I dont like using _ so I just capitalize the following word. var userType, userSize, userWhatever:string |
Author: | Catalyst [ Tue Apr 15, 2003 10:22 pm ] |
Post subject: | |
ya same for me, i was taught that way |