Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert a phone number problem
#1
Hello. I'm stuck on a problem for a class I'm taking and wondering if anybody could help me. The user enters an alphabetic phone number (ABC-DEFG) and then the program is supposed to convert it to its numeric values (222-3334). I've tried everything I could think of, with MID$, LEFT$, and ASC but nothing seems to be working. Any help would be appreciated.
Reply
#2
s$ = "abcdefg"


s$ = ucase$(s$)
for i = 1 to len(s$)
print asc(mid$(s$, i, 1)) - asc("A");
next i
Reply
#3
Quote:s$ = "abcdefg"


s$ = ucase$(s$)
for i = 1 to len(s$)
print asc(mid$(s$, i, 1)) - asc("A");
next i

Almost, except that there's several numbers on each key... let the man figure how to do that himself, tho.

(worst case scenario, you could always just use a CASE statement)
Reply
#4
hehe... my mistake. But yeah, I think it says in the FAQ that when posting homework problems, one should show that one has at least attempted the problem. Big Grin
Reply
#5
I made one and it is BIG
It uses a lot of IF statements.
:wink:
But it works!
You input:

1-800-CALL-SAM

and it outputs:

1-800-2255-726
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#6
If statements arent necessary with smart programming.

HINT:
Code:
dim alphabet as string

for x = 2 to 9
  read append$
  alphabet = alphabet + append$
next x

DATA "222", "333", "444", "555", "666", "7777", "888", "9999"

but way to go on the effort, i would never have that kind of patience Smile
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
#7
or you could do this:

Code:
s$ = "abcdefg"


s$ = ucase$(s$)
for i = 1 to len(s$)
print asc(mid$(s$, i, 1)) / 3 - asc("A") + 1;
next i

oh wait... that doesn't work for the keys with 4 letters... nevermind. :oops:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)