Changing letters - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: Changing letters (/thread-125.html) Pages:
1
2
|
Changing letters - Lanzaa - 02-01-2003 First off its not homework i only dream that im in a qbasic class right now, I'm 12, but i was wondering how to change and "a" to a "b" or "abc" to "bcd" and so on. Any ideas? :-? Changing letters - toonski84 - 02-01-2003 you'd need to extract each letter, and change them individually. you can use mid$ for that. once you do that, you can use asc to convert each number to its ascii value, add one, and revert to a string using mid$ again and the chr$. i'm not going to tell you how to do it, that's for you to figure out, i've given you the tools. try it and come back if you have any problems. this was actually the first program i ever made, something to do exactly what you are, that i copied out of a code book and studied until i had every statement down. Changing letters - Lanzaa - 02-01-2003 30 min after 7:00am edited 15 times for gramar I've done it!!!!! Code: CLS Changing letters - Lanzaa - 02-03-2003 Well now i have an answer for one of the challenges. The encoding one look :o Code: CLS hehe tx and anyone that can help me make ths smaller more efficient, ect. plz do Changing letters - toonski84 - 02-03-2003 well, efficiency can mean many things, but for code clarity it isnt. for instance, your code is very clear. but if you wanted to compress it: b = ASC(MID$(a$, letter, 1)) b = b + letter d$ = CHR$(b) MID$(a$, letter, 1) = d$ could be: MID$(a$, letter, 1) = chr$(ASC(MID$(a$, letter, 1)) + letter) if you actually wanted to make it faster, well, that's a different story. string functions are difficult because qb handles them all, so the only way to increase the speed of such a program is to use peek and poke with sadd, which can be VERY dangerous if you dont know what you are doing (as is anything involving peek and poke). and while skipping spaces can be easily performed with an if...then statement, if you only want this to apply to a-z letters (and have z revert to a) then Code: function encode$ (message$) WARNING: THIS CODE IS UNTESTED AND PULLED OUT OF MY POSTERIOR. USE WITH CAUTION. NO MEMBERS OF QBASICNEWS CAN BE BLAMED IN THE EVENT THAT IT DOES NOT WORK!! Changing letters - Lanzaa - 02-03-2003 Well i changed both with that except i can't figure out in 5 min how to decode so im going to try tomarrow here are the codes :lol: Code: CLS Code: CLS Changing letters - toonski84 - 02-03-2003 okie dokie enjoy. Code: function decode$ (message$) hey, if you want to know how this works i'll break it down for you when i have some time later. Changing letters - Neo - 02-03-2003 I think I have a more efficient piece of code. Code: MyText$="abc" Hope you can do something with it Changing letters - LooseCaboose - 02-04-2003 IMHO Toonski's code is much more effecient because it is understandable (and modifiable) at a glance, Neo's code may produce slightly more effecient machine code, but its meaning isnt instantly clear to a beginner and its not easily changed. In terms of computer science, both Neo's and Toonski's algorithms are almost exactly the same speed (Toonski's takes 5 assignments and Neo's only 3) but both execute in O(1) constant time. The percieved speed difference on a modern computer, even for several hunderd iterations of either algorithm would be almost impossible to detect. Would anyone be interested in reading some simple tutorials on algorithm complexity, ie discussions of the big-O notation, what makes certain algorithms faster than others and good selection of algorithms. I could write some Qbasic relevant tuts on the subject. Changing letters - toonski84 - 02-04-2003 well, something as simple and quick as this is is difficult to compare complexity. peek and poke with sadd is definately faster, but it's hard to tell if our friend here will understand it. of course, there are some improvements to be made to neo's version, which is well done as a note, too. y% = PEEK(I) IF y% = 255 THEN y% = -1 POKE I, y% + 1 coud be POKE I, (PEEK(I) + 1) AND 255 which is more efficient and compressed. and i could be dimmed as an integer to boot. but like you said, i doubt with modern speeds it makes a difference. |