Hot Topic (More than 10 Replies) @tonumber? (Read 1511 times)
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
@tonumber?
Nov 2nd, 2005 at 4:55pm
Print Post Print Post  
Hi -

Once again, I've been going bonkers and must be overlooking something simple.

I want to format a phone field - a certain way - regardless of how the number is entered.

Let's say the entry is:  Tel:352-243-9795

How do I get it changed to 3532439795 (so I can then manipulate it futher?)

I tried @tonumber(phonenumber) and just can't seem to get anywhere. 

Thanks!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: @tonumber?
Reply #1 - Nov 2nd, 2005 at 5:00pm
Print Post Print Post  
@ToNumber converts the value to a numeric value.

@Num will do what you want.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: @tonumber?
Reply #2 - Nov 2nd, 2005 at 5:06pm
Print Post Print Post  
Hi -

I don't know what is wrong with me, because I used to do this all the time in Q&A and it would seem to work the same.

I just tried it with @number on

Tel:352-243-9795

and my result was

4172

  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @tonumber?
Reply #3 - Nov 2nd, 2005 at 5:18pm
Print Post Print Post  
Not @number. Use @Num.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: @tonumber?
Reply #4 - Nov 2nd, 2005 at 5:29pm
Print Post Print Post  
OH FER CRY'N OUT LOUD!  lol

When you said @num originally, I just thought it was an abbreviation for @number (like @tn is for @tonumber).  It would have taken me days to find out that @num is a totally separate and completely different command.

And, by the way, before I tried @tonumber, I had tried @number ... so I was going back and forth between the two and, of course, getting nowhere.

Thank you - thank you -
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: @tonumber?
Reply #5 - Nov 2nd, 2005 at 8:22pm
Print Post Print Post  
Hi -

I had hoped that when I got the "number" issue resolved, I would be able to handle the rest of the programming.  Unfortunatley, I am still missing something.

I am simply trying to convert any phone number to a standard format of:

   (###) ###-####

which might have been entered in any of several formats, such as:

   Tel:(###) ###-####
   ###-###-####
   ###.###.####

etc.

I was trying to do this with a sub-routine (since I have 5 phone fields that would be affected).  I thought the following would work; however, it does nothing. Admittedly, I am "weak" in the area of  sub-routines.  (The first subroutine has to do with dialing phone numbers and that works just fine). 

[code]var vPhonenumber as String

Subroutine DialPhone ( )
var VSuccess as Int
var vAreacode as string = "813"
var vName as String = Mail Name 
var vPath as String = "C:\sesame\utilities\" 
 
 
vPhonenumber = @num (vPhonenumber)
 
If @len (vPhonenumber) = 10 then
{
  If @left (vPhonenumber, 3) = vAreacode then
  { 
   vPhonenumber = @Right (vPhonenumber, 7)
  }
  Else
  If @left (vPhonenumber, 3) = "727" then
  { 
   vPhonenumber = (vPhonenumber)
  }
  Else
  {
   vphonenumber = 1 + vPhonenumber
  }
}

 

vsuccess = @Shell(@Chr(34) + vPath + "dial.exe" + @Chr(34) + " " + vPhonenumber  + " [" + vName +"]")   
 
If not vSuccess = 0 then
{
  @msgbox ("Problem!!! Dialer did not work.", "", "")
 

end subroutine




Subroutine formatphonenumber ( )

vPhonenumber = @num(vPhonenumber)


if @len(vPhonenumber)=10 then

vPhonenumber = "(" + @Left(vPhonenumber, 3) + ") " + @Mid(vPhonenumber, 4, 3) + "-" + @Right(vPhonenumber, 4)
end subroutine
[/code]

If I use the "parsing" code in a particular phone field (Home, Work, Cell, Other1 or Other2) it works just fine, but I didn't want to repeat the programming in each field.

The above code is entered in the "Global Code" and in each phone field (on element entry) I have the following:

[code]vPhonenumber = ThisElement[/code]

Also in each phone field (on element exit) I have the following:

[code]formatphonenumber ( )[/code]

Where am I going wrong, please?
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: @tonumber?
Reply #6 - Nov 2nd, 2005 at 8:38pm
Print Post Print Post  
Hello Spencer,

One of the cleanist ways to do this would probably be with a function. For example something like

Code
Select All
Function FormatPhoneNumber(vPhoneNum as String) as String

vPhoneNum = @Num(vPhoneNum)

If @len(vPhoneNum)=10 Then
{
	vPhoneNum = "(" + @Left(vPhoneNum, 3) + ") " + @Mid(vPhoneNum, 4, 3) + "-" + @Right(vPhoneNum, 4)
}
Else
{
	//Display an Error to tell the user that the numebr can not be formatted
}

Return vPhoneNum
End Function 

 

To call it you would say

Code
Select All
ThisElement = FormatPhoneNumber(ThisElement) 



The reason your current code is not working is because of the scope of the variable declared in Global Code.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: @tonumber?
Reply #7 - Nov 2nd, 2005 at 8:51pm
Print Post Print Post  
Ray -

Works like a charm!  THANK YOU!!!!

Could you please tell me what you mean by

Quote:
The reason your current code is not working is because of the scope of the variable declared in Global Code.

I'm not clear as to why it works in one instance (the phone dialer) and not the other (the formatting). 

Also, what would be the greatest distinction between the "function" and a "subroutine?"

Thanks!

  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: @tonumber?
Reply #8 - Nov 2nd, 2005 at 9:11pm
Print Post Print Post  
Hello Spencer,

Well one reason is because you never assigned the value in vPhonenumber back to the calling element. The other thing that can cause you some troubles is the fact that vPhonenumber is declared using var, which creates a dynamic variable in global code, and not using stat which creates a static variable. You will want to change that var to stat as soon as you can.

There is one difference between the two. A Function returns a Value, a Subroutine does not.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: @tonumber?
Reply #9 - Nov 2nd, 2005 at 10:20pm
Print Post Print Post  
Hi Ray -

Thanks for the info.

I never realized that so many words began with the letters s-t-a-t until I did a search in the PDF programming guide.  lol

Anyhow, a little better educated and programming has been changed.
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
digimom1962
Junior Member
**
Offline


Natalie Gann

Posts: 92
Location: here
Joined: Nov 26th, 2004
Re: @tonumber?
Reply #10 - Nov 4th, 2005 at 5:39pm
Print Post Print Post  
Would you have any idea why I can not get any of the phone formatting to work? It either changes the numbers to a 0, adds lots of zeros at the end (and does not format anything anyway) or does not even let me type. I tried the one bob scott had in programming examples, tried the one posted after that. tried the function listed here. I MUST have missed something very basic. I even changed the field to text thinking that must be the problem.

All I do is copy/paste the code and change the field name where necessary. If the sample says where to put the code I do that, if not I try in element change or exit.

I think I will just give up trying to figure this out for the day and go do something more productive like hit my head with the programming book.
  

So much time and so little to do . . . strike that, reverse it.
Back to top
YIM YIM  
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: @tonumber?
Reply #11 - Nov 4th, 2005 at 6:38pm
Print Post Print Post  
Make sure that your phone number is bound to type Text. If you are going to use the code that spencer posted, then put this code in global code.

Code
Select All
Function FormatPhoneNumber(vPhoneNum as String) as String

vPhoneNum = @Num(vPhoneNum)

If @len(vPhoneNum)=10 Then
{
 vPhoneNum = "(" + @Left(vPhoneNum, 3) + ") " + @Mid(vPhoneNum, 4, 3) + "-" + @Right(vPhoneNum, 4)
}
Else
{
 //Display an Error to tell the user that the numebr can not be formatted
WriteLn("You must enter ten numbers")
}

Return vPhoneNum
End Function 



and put this code in your phone numbers on element exit event.

Code
Select All
ThisElement = FormatPhoneNumber(ThisElement) 



You must enter all ten numbers in order for it to format the number. So if you just enter 567.8901 no formatting will happen.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: @tonumber?
Reply #12 - Nov 4th, 2005 at 6:43pm
Print Post Print Post  
Ray -

I was just alerted to this "new" reply and it reminded me that I wanted to thank you again.

This code works like a charm.  Just as long as the correct 10 digits of the phone number are in the field - in the proper sequence .. and no other numbers exist, it doesn't matter what kind of other garbage I put in there.

I have been doing cutting and pasting and this just makes it so much easier on me - I've been "thanking you" every time I copied something into the phone number field ... and believe me, with all the data entry I've been doing, I've been thanking you a lot!   Grin
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
digimom1962
Junior Member
**
Offline


Natalie Gann

Posts: 92
Location: here
Joined: Nov 26th, 2004
Re: @tonumber?
Reply #13 - Nov 4th, 2005 at 6:46pm
Print Post Print Post  
Grin

Thanx Mr Reaper

I suspect I had just left bits of programming around from previous attempts and it confused Sesame.

For this one I started from scratch and it worked beautifully.

Thanx again
  

So much time and so little to do . . . strike that, reverse it.
Back to top
YIM YIM  
IP Logged