
-----------------------------------
xmdxtreme
Tue May 11, 2004 7:38 pm

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  :roll: 
btw:if you dont understand sorry for bad english :oops:

-----------------------------------
Paul
Tue May 11, 2004 8:05 pm


-----------------------------------

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


-----------------------------------
xmdxtreme
Tue May 11, 2004 8:08 pm


-----------------------------------
thank you it helped alot  :lol:

-----------------------------------
xmdxtreme
Tue May 11, 2004 8:36 pm


-----------------------------------
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?

-----------------------------------
Paul
Tue May 11, 2004 8:41 pm


-----------------------------------
well ord("0") is 48 and ord("9") is 57 then

loop
getch (key)
if ord (key) >=48 or ord(key)=48 or ord(key)= 48 and ord (key)  9
end loop


-----------------------------------
Tony
Wed May 12, 2004 4:56 pm


-----------------------------------
... :? 

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


-----------------------------------
Paul
Wed May 12, 2004 5:08 pm


-----------------------------------
I like mine better tony, mine remebers the phone number ;)

-----------------------------------
xmdxtreme
Wed May 12, 2004 5:12 pm


-----------------------------------
sorry one more thing last question :roll: 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?

-----------------------------------
Paul
Wed May 12, 2004 5:14 pm


-----------------------------------
uh... my code already does it, or rather we64's modified code, just go


put num


-----------------------------------
xmdxtreme
Wed May 12, 2004 5:17 pm


-----------------------------------
nvm lol edit i asked a stupid question thank all of you guys you helped me alot  :lol:

-----------------------------------
xmdxtreme
Wed May 12, 2004 8:13 pm


-----------------------------------
lol omg another question sorry guys  :oops: backspace doesnt work...

-----------------------------------
Paul
Wed May 12, 2004 8:14 pm


-----------------------------------
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

-----------------------------------
xmdxtreme
Wed May 12, 2004 8:22 pm


-----------------------------------
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.

-----------------------------------
Paul
Wed May 12, 2004 8:24 pm


-----------------------------------
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.

-----------------------------------
xmdxtreme
Wed May 12, 2004 8:36 pm


-----------------------------------
yeah ill look into that thx :roll:

-----------------------------------
we64
Wed May 12, 2004 8:58 pm


-----------------------------------
you can't minus strings.... I think

-----------------------------------
Paul
Wed May 12, 2004 9:10 pm


-----------------------------------
yea you can
num:= num(1..*-1)

-----------------------------------
we64
Wed May 12, 2004 9:22 pm


-----------------------------------
oh I see, forgot it, let's try

-----------------------------------
we64
Wed May 12, 2004 9:35 pm


-----------------------------------
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......


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)  9
end loop


-----------------------------------
xmdxtreme
Wed May 12, 2004 10:16 pm


-----------------------------------
thank you now someone else help plz  :roll:

-----------------------------------
we64
Thu May 13, 2004 6:44 am


-----------------------------------
finally, here now it works well I hope....

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)  11
end loop

