Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing letters
#5
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$)
  for x = 1 to len(message$)
    a = mid$(message$, x, 1)

    select case a
      case 65 to 90
        a = (((a-65) + 1) mod 26) + 65
      case 97 to 122
        a = (((a-97) + 1) mod 26) + 97
    end select
    
    mid$(message$, x, 1) = chr$(a)
  next x
  
  encode$ = message$
end function

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
Reply


Messages In This Thread
Changing letters - by Lanzaa - 02-01-2003, 11:14 AM
Changing letters - by toonski84 - 02-01-2003, 11:26 AM
Changing letters - by Lanzaa - 02-01-2003, 08:00 PM
Changing letters - by Lanzaa - 02-03-2003, 06:16 AM
Changing letters - by toonski84 - 02-03-2003, 07:04 AM
Changing letters - by Lanzaa - 02-03-2003, 09:55 AM
Changing letters - by toonski84 - 02-03-2003, 03:22 PM
Changing letters - by Neo - 02-03-2003, 04:04 PM
Changing letters - by LooseCaboose - 02-04-2003, 02:02 AM
Changing letters - by toonski84 - 02-04-2003, 04:56 AM
Changing letters - by Lanzaa - 02-04-2003, 07:27 AM
Changing letters - by toonski84 - 02-04-2003, 08:14 AM
Changing letters - by Neo - 02-04-2003, 04:31 PM
Changing letters - by Lanzaa - 02-05-2003, 09:01 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)