470,619 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,619 developers. It's quick & easy.

Format() in Public Shared Function

I'm trying to write a shared function that will convert all my phone numbers
from format 1234567890 to (123) 456-7890.

Here is my function that I wrote:
Public Shared Function CheckPhone(byVal val as String) as String
dim strCheckPhone as String
If val = "" Then
strCheckPhone = ""
Elseif val = nothing then
strCheckPhone = ""
else
strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####")
End If

return strCheckPhone
End Function

Here is my compile command:

c:\windows\microsoft.net\framework\v1.1.4322\vbc.e xe /t:library
/r:System.Data.dll /r:System.dll functions.vb

Here is what I am importing:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Text.UTF8Encoding
Imports System.configuration
Imports System.Security.Cryptography
Imports System.Web
Imports System.Text.Encoding

(There are some other functions in this file, so I know that most of those
don't relate to this function.)

And here are the errors I receive:

C:\Documents and Settings\m\Desktop\functions.vb(180) : error BC30451:

************************************************** ****************
Name 'Format' is not declared.
strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####")
~~~~~~
************************************************** ****************

C:\Documents and Settings\m\Desktop\functions.vb(180) : error BC30561:
************************************************** ****************
'Convert' is ambiguous, imported from the namespaces or types
'System.Text.Encod
ing, System'.

strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####")
~~~~~~~
************************************************** ****************

Thanks for your help.

Matt
Nov 18 '05 #1
4 1725
Microsoft.VisualBasic.Format

"Matt" <aw***********@aol.com> wrote in message
news:votld.402825$D%.107828@attbi_s51...
I'm trying to write a shared function that will convert all my phone numbers from format 1234567890 to (123) 456-7890.

Here is my function that I wrote:
Public Shared Function CheckPhone(byVal val as String) as String
dim strCheckPhone as String
If val = "" Then
strCheckPhone = ""
Elseif val = nothing then
strCheckPhone = ""
else
strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####")
End If

return strCheckPhone
End Function

Here is my compile command:

c:\windows\microsoft.net\framework\v1.1.4322\vbc.e xe /t:library
/r:System.Data.dll /r:System.dll functions.vb

Here is what I am importing:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Text.UTF8Encoding
Imports System.configuration
Imports System.Security.Cryptography
Imports System.Web
Imports System.Text.Encoding

(There are some other functions in this file, so I know that most of those
don't relate to this function.)

And here are the errors I receive:

C:\Documents and Settings\m\Desktop\functions.vb(180) : error BC30451:

************************************************** ****************
Name 'Format' is not declared.
strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####") ~~~~~~
************************************************** ****************

C:\Documents and Settings\m\Desktop\functions.vb(180) : error BC30561:
************************************************** ****************
'Convert' is ambiguous, imported from the namespaces or types
'System.Text.Encod
ing, System'.

strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####") ~~~~~~~
************************************************** ****************

Thanks for your help.

Matt

Nov 18 '05 #2
Thanks.

What about this one?

'Convert' is ambiguous, imported from the namespaces or types
'System.Text.Encoding, System'.

strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####")
~~~~~~~

Thanks again!

Matt
<je**@removeemergencyreporting.com> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
Microsoft.VisualBasic.Format

"Matt" <aw***********@aol.com> wrote in message
news:votld.402825$D%.107828@attbi_s51...
I'm trying to write a shared function that will convert all my phone

numbers
from format 1234567890 to (123) 456-7890.

Here is my function that I wrote:
Public Shared Function CheckPhone(byVal val as String) as String
dim strCheckPhone as String
If val = "" Then
strCheckPhone = ""
Elseif val = nothing then
strCheckPhone = ""
else
strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####")
End If

return strCheckPhone
End Function

Here is my compile command:

c:\windows\microsoft.net\framework\v1.1.4322\vbc.e xe /t:library
/r:System.Data.dll /r:System.dll functions.vb

Here is what I am importing:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Text.UTF8Encoding
Imports System.configuration
Imports System.Security.Cryptography
Imports System.Web
Imports System.Text.Encoding

(There are some other functions in this file, so I know that most of
those
don't relate to this function.)

And here are the errors I receive:

C:\Documents and Settings\m\Desktop\functions.vb(180) : error BC30451:

************************************************** ****************
Name 'Format' is not declared.
strCheckPhone = Format(Convert.ToDouble(val), "(###)

###-####")
~~~~~~
************************************************** ****************

C:\Documents and Settings\m\Desktop\functions.vb(180) : error BC30561:
************************************************** ****************
'Convert' is ambiguous, imported from the namespaces or types
'System.Text.Encod
ing, System'.

strCheckPhone = Format(Convert.ToDouble(val), "(###)

###-####")
~~~~~~~
************************************************** ****************

Thanks for your help.

Matt


Nov 18 '05 #3
I got this to work, but what I had to do was System.Convert.ToDouble.

I don't understand why I need to do this since I was already importing
System.

Matt
"Matt" <aw***********@aol.com> wrote in message
news:WWzld.94474$R05.27292@attbi_s53...
Thanks.

What about this one?

'Convert' is ambiguous, imported from the namespaces or types
'System.Text.Encoding, System'.

strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####")
~~~~~~~

Thanks again!

Matt
<je**@removeemergencyreporting.com> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
Microsoft.VisualBasic.Format

"Matt" <aw***********@aol.com> wrote in message
news:votld.402825$D%.107828@attbi_s51...
I'm trying to write a shared function that will convert all my phone

numbers
from format 1234567890 to (123) 456-7890.

Here is my function that I wrote:
Public Shared Function CheckPhone(byVal val as String) as String
dim strCheckPhone as String
If val = "" Then
strCheckPhone = ""
Elseif val = nothing then
strCheckPhone = ""
else
strCheckPhone = Format(Convert.ToDouble(val), "(###) ###-####")
End If

return strCheckPhone
End Function

Here is my compile command:

c:\windows\microsoft.net\framework\v1.1.4322\vbc.e xe /t:library
/r:System.Data.dll /r:System.dll functions.vb

Here is what I am importing:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Text.UTF8Encoding
Imports System.configuration
Imports System.Security.Cryptography
Imports System.Web
Imports System.Text.Encoding

(There are some other functions in this file, so I know that most of
those
don't relate to this function.)

And here are the errors I receive:

C:\Documents and Settings\m\Desktop\functions.vb(180) : error BC30451:

************************************************** ****************
Name 'Format' is not declared.
strCheckPhone = Format(Convert.ToDouble(val), "(###)

###-####")
~~~~~~
************************************************** ****************

C:\Documents and Settings\m\Desktop\functions.vb(180) : error BC30561:
************************************************** ****************
'Convert' is ambiguous, imported from the namespaces or types
'System.Text.Encod
ing, System'.

strCheckPhone = Format(Convert.ToDouble(val), "(###)

###-####")
~~~~~~~
************************************************** ****************

Thanks for your help.

Matt



Nov 18 '05 #4
"Matt" <aw***********@aol.com> wrote in message news:WWzld.94474$R05.27292@attbi_s53...
What about this one?

'Convert' is ambiguous, imported from the namespaces or types
'System.Text.Encoding, System'.


You should remove the,

Imports System.Text.Encoding

statement because Encoding is a Class, not a Namespace, and you've already
imported System.Text (which is the Namespace containing the Encoding class)
so there's no benefit to importing the Class individually.

The error is telling you that the VB.NET compiler can't tell whether you are
referring to the System.Convert Class or the Encoding.Convert Method (it's
System.Convert; as soon as you remove the extraneous Import it'll cease
being ambiguous.)
Derek Harmon
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by May | last post: by
3 posts views Thread by Joe Fallon | last post: by
10 posts views Thread by darrel | last post: by
10 posts views Thread by KJ | last post: by
1 post views Thread by David Sanschagrin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.