473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1823
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: May | last post by:
greetings, i came across a function while browsing thru the net. This function is created in a component. what i am curious to know is, is this the correct way to create a function using: Public...
3
by: Joe Fallon | last post by:
I have a Shared varibale in a base class and all the Shared methods in the sub-classes use it (and CHANGE it). I thought I was saving myself the "trouble" of Dimming this variable inside each...
10
by: darrel | last post by:
I'm still trying to sort out in my head the differences between public and shared when referring to declaring properties or variables. This is my understanding: shared - akin to a 'global'...
4
by: Chris | last post by:
Hello, I'm just getting started with VB and am new to the group, so please excuse what may seem to be a rudimentary question. I've been writing basic programs and have noticed that the...
10
by: KJ | last post by:
Hello, Why does this not work? txtMoney.Text.Format("#,##0.00") If I type 100 in txtMoney, it returns #,##0.00 I have never gotten the format function to work in .NET.
1
by: David Sanschagrin | last post by:
(I previously posted this problem on vb.general.discussion but I've been told that this question is more related to VB.NET than VB6 and so that I should post that here.) I'm trying to call a...
2
by: Jon Paal | last post by:
In a 2.0 vb code class, I have a private property and a shared public function The property value has already been passed into the class, now I am trying to use a public finction which also needs...
2
by: Darrel | last post by:
I'm working on an app where the ASPX pages aren't precompiled with the class.vb files I'm. This is so people can add their own ASPX pages down the road to the app (the .aspx pages become...
6
by: sjohnson1984 | last post by:
Hello all, Thanks for reading firstly. I am looking to format seconds into a format similar to that of an Excel "custom" format :mm:ss I have crafted the following however I am getting an...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.