02-01-2003, 11:14 AM
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? :-?
Any ideas? :-?
Changing letters
|
02-01-2003, 11:14 AM
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? :-?
02-01-2003, 11:26 AM
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.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
02-01-2003, 08:00 PM
30 min after 7:00am edited 15 times for gramar
I've done it!!!!! Code: CLS
02-03-2003, 06:16 AM
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
02-03-2003, 07:04 AM
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!!
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
02-03-2003, 09:55 AM
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
02-03-2003, 03:22 PM
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.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
02-03-2003, 04:04 PM
I think I have a more efficient piece of code.
Code: MyText$="abc" Hope you can do something with it
02-04-2003, 02:02 AM
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.
esus saves.... Passes to Moses, shoots, he scores!
02-04-2003, 04:56 AM
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.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
|
« Next Oldest | Next Newest »
|