Author |
Message |
xmdxtreme
|
Posted: 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
btw:if you dont understand sorry for bad english |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Paul
|
Posted: Tue May 11, 2004 8:05 pm Post subject: (No 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
|
|
|
|
|
|
|
xmdxtreme
|
Posted: Tue May 11, 2004 8:08 pm Post subject: (No subject) |
|
|
thank you it helped alot |
|
|
|
|
|
xmdxtreme
|
Posted: Tue May 11, 2004 8:36 pm Post subject: (No 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? |
|
|
|
|
|
Paul
|
Posted: Tue May 11, 2004 8:41 pm Post subject: (No 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
|
|
|
|
|
|
|
xmdxtreme
|
Posted: Tue May 11, 2004 9:29 pm Post subject: (No subject) |
|
|
sorry its my first year i dont get this can someone explain this or be a bit more specific sorry man |
|
|
|
|
|
Paul
|
Posted: Wed May 12, 2004 3:24 pm Post subject: (No 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. |
|
|
|
|
|
xmdxtreme
|
Posted: Wed May 12, 2004 4:28 pm Post subject: (No 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
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
we64
|
Posted: Wed May 12, 2004 4:52 pm Post subject: (No 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
|
|
|
|
|
|
|
Tony
|
|
|
|
|
Paul
|
Posted: Wed May 12, 2004 5:08 pm Post subject: (No subject) |
|
|
I like mine better tony, mine remebers the phone number |
|
|
|
|
|
xmdxtreme
|
Posted: Wed May 12, 2004 5:12 pm Post subject: (No subject) |
|
|
sorry one more thing last question 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
|
Posted: Wed May 12, 2004 5:14 pm Post subject: (No subject) |
|
|
uh... my code already does it, or rather we64's modified code, just go
|
|
|
|
|
|
xmdxtreme
|
Posted: Wed May 12, 2004 5:17 pm Post subject: (No subject) |
|
|
nvm lol edit i asked a stupid question thank all of you guys you helped me alot |
|
|
|
|
|
xmdxtreme
|
Posted: Wed May 12, 2004 8:13 pm Post subject: (No subject) |
|
|
lol omg another question sorry guys backspace doesnt work... |
|
|
|
|
|
|