Computer Science Canada

Phone number using -

Author:  xmdxtreme [ Tue May 11, 2004 7:38 pm ]
Post subject:  Phone number using -

Ok one part of my program i want to do this when you type like a phone number 4162340942 the dashes pops up by it self like first 3 digits then a dash pops up:
416-
then you type
416-234- another dash pops up...
like that plz help me i dont have much time Rolling Eyes
btw:if you dont understand sorry for bad english Embarassed

Author:  Paul [ Tue May 11, 2004 8:05 pm ]
Post subject: 

code:

var key : string (1)
var num : string := ""
put "Enter your phone number"
for a : 1 .. 10
    getch (key)
    cls
    put "Enter your phone number"
    num += key
    put num ..
    if a mod 3 = 0 and a not= 9 then
        num += "-"
        put "-" ..
    end if
end for

Author:  xmdxtreme [ Tue May 11, 2004 8:08 pm ]
Post subject: 

thank you it helped alot Laughing

Author:  xmdxtreme [ Tue May 11, 2004 8:36 pm ]
Post subject: 

but the user can type letters lol i know for phone numbe its ok but for date i change it to slashes and fixed up the loop and mod for it but they can type letters anyway to prvent that?

Author:  Paul [ Tue May 11, 2004 8:41 pm ]
Post subject: 

well ord("0") is 48 and ord("9") is 57 then
code:

loop
getch (key)
if ord (key) >=48 or ord(key)<=57 then
exit
end if
end loop

Author:  xmdxtreme [ Tue May 11, 2004 9:29 pm ]
Post subject: 

sorry its my first year i dont get this can someone explain this or be a bit more specific sorry man Embarassed

Author:  Paul [ Wed May 12, 2004 3:24 pm ]
Post subject: 

all characters has its on code, ASCII? I think, anyhow, in the code above, it specified that if the code of the numbers entered is between 0 and 9 then, it exits the loops, or else (its not a number) it keeps asking for input.

Author:  xmdxtreme [ Wed May 12, 2004 4:28 pm ]
Post subject: 

it doesnt work i even tried changing the code like this:
code:

var key : string (1)
var num : string := ""
put "Enter your phone number"
loop
getch (key)
exit when ord (key) >=48 or ord(key)<=57
end loop
for a : 1 .. 10
    getch (key)
    cls
    put "Enter your phone number"
    num += key
    put num ..
    if a mod 3 = 0 and a not= 9 then
        num += "-"
        put "-" ..
    end if
end for

Author:  we64 [ Wed May 12, 2004 4:52 pm ]
Post subject: 

to prevent not entering letters:
code:

var key : string (1)
var num : string := ""
var a := 1
put "Enter your phone number"

loop
    getch (key)
    cls
    if ord (key) >= 48 and ord (key) <= 57 then
        put "Enter your phone number"
        num += key
        put num ..
        if a mod 3 = 0 and a not= 9 then
            num += "-"
            put "-" ..
        end if
        a += 1
    else
        put "Enter your phone number"
        getch (key)
    end if
    exit when a > 9
end loop

Author:  Tony [ Wed May 12, 2004 4:56 pm ]
Post subject: 

... Confused
code:

var c : string (1)
put "enter your phonenumber"
for i : 1 .. 3
    getch (c)
    put c ..
end for
put "-" ..
for i : 1 .. 3
    getch (c)
    put c ..
end for
put "-" ..
for i : 1 .. 4
    getch (c)
    put c ..
end for

Author:  Paul [ Wed May 12, 2004 5:08 pm ]
Post subject: 

I like mine better tony, mine remebers the phone number Wink

Author:  xmdxtreme [ Wed May 12, 2004 5:12 pm ]
Post subject: 

sorry one more thing last question Rolling Eyes i want to store the final phone numbe in a variable how i mean like that ends the you want to use the saved phone number and put it somewhere else.
put phonenumber
I mean i just want to save the final phone number entered including dashes to a variable how?

Author:  Paul [ Wed May 12, 2004 5:14 pm ]
Post subject: 

uh... my code already does it, or rather we64's modified code, just go
code:


put num

Author:  xmdxtreme [ Wed May 12, 2004 5:17 pm ]
Post subject: 

nvm lol edit i asked a stupid question thank all of you guys you helped me alot Laughing

Author:  xmdxtreme [ Wed May 12, 2004 8:13 pm ]
Post subject: 

lol omg another question sorry guys Embarassed backspace doesnt work...

Author:  Paul [ Wed May 12, 2004 8:14 pm ]
Post subject: 

yea its getch
so just ask the user at the end, if they had a mistake and would like to reenter the number, then if yes restart loop, reset all values. and cls

Author:  xmdxtreme [ Wed May 12, 2004 8:22 pm ]
Post subject: 

yeah thats a way but my teacher was like you better error proof completely but is there any other way i can acctually use backspace i just knw char value for backspace is 8.

Author:  Paul [ Wed May 12, 2004 8:24 pm ]
Post subject: 

well u can do it in a roundabout way, have an if statement that if backspace is detected, then erase the last letter in the variable of "num" and then use locate to put a space where u wrote last.

Author:  xmdxtreme [ Wed May 12, 2004 8:36 pm ]
Post subject: 

yeah ill look into that thx Rolling Eyes

Author:  we64 [ Wed May 12, 2004 8:58 pm ]
Post subject: 

you can't minus strings.... I think

Author:  Paul [ Wed May 12, 2004 9:10 pm ]
Post subject: 

yea you can
num:= num(1..*-1)

Author:  we64 [ Wed May 12, 2004 9:22 pm ]
Post subject: 

oh I see, forgot it, let's try

Author:  we64 [ Wed May 12, 2004 9:35 pm ]
Post subject: 

everything works, except it can't erase the dash, I mean it can, but if you do, it will mess things up.... someone try to figure it out, I got other English work to do tonight, so I will leave it like this......

code:

var key : string (1)
var num : string := ""
var a := 1
put "Enter your phone number"

loop
    getch (key)
    cls
    if ord (key) = 8 then
        a -= 1
        put "Enter your phone number"
        num := num (1 .. * -1)
        put num ..

    elsif ord (key) >= 48 and ord (key) <= 57 then
        put "Enter your phone number"
        num += key
        put num ..
        if a mod 3 = 0 and a not= 9 then
            num += "-"
            put "-" ..
        end if
        a += 1
    else
        put "Enter your phone number"
    end if
    exit when a > 9
end loop

Author:  xmdxtreme [ Wed May 12, 2004 10:16 pm ]
Post subject: 

thank you now someone else help plz Rolling Eyes

Author:  we64 [ Thu May 13, 2004 6:44 am ]
Post subject: 

finally, here now it works well I hope....
code:

var key : string (1)
var num : string := ""
var a := 1
put "Enter your phone number"

loop
    getch (key)
    cls
    if ord (key) = 8 then
        put "Enter your phone number"
        a -= 1
        if a = 4 or a = 8 then
            num := num (1 .. * -2)
            put num ..
            a -= 1
        else
            num := num (1 .. * -1)
            put num ..
        end if
    elsif ord (key) >= 48 and ord (key) <= 57 then
        put "Enter your phone number"
        num += key
        put num ..
        if a = 3 or a = 7 then
            num += "-"
            put "-" ..
            a += 1
        end if
        a += 1
    else
        put "Enter your phone number"
    end if
    exit when a > 11
end loop


: