VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 307,023 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,180 people online right now. Registration is fast and FREE... Join Now!




Phone number

 

Phone number

jessx12

4 Nov, 2009 - 12:40 PM
Post #1

New D.I.C Head
*

Joined: 4 Nov, 2009
Posts: 4

This is what i have so far.. i got the number to display in the label. however my replace method is not working. the ouput label is exactly what was the input.

the point of this assignment is to elimate any hyphens spaces and parenthesis from a phone number to make it look like 1234561234


vb

' ' Project name: Phone Project
' Project purpose: Removes any hyphens, spaces, and
' parentheses from a phone number

Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm

Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub

Private Sub numberTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PhoneNumberTextBox.Enter
PhoneNumberTextBox.SelectAll()
End Sub

Private Sub numberTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PhoneNumberTextBox.TextChanged
numberLabel.Text = String.Empty
End Sub

Private Sub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click

Dim PhoneNumber As String

PhoneNumber = numberLabel.Text
PhoneNumber = PhoneNumber.Replace("-", "")
PhoneNumber = PhoneNumber.Replace(" ", "")
PhoneNumber = PhoneNumber.Replace("(", "")
PhoneNumber = PhoneNumber.Replace(")", "")




numberLabel.Text = PhoneNumberTextBox.Text



End Sub
End Class


End Sub
End Class


*** MOD EDIT: Added code tags. Please code.gif ***

This post has been edited by jessx12: 4 Nov, 2009 - 01:37 PM

User is offlineProfile CardPM
+Quote Post


bytelogik

RE: Phone Number

4 Nov, 2009 - 10:13 PM
Post #2

D.I.C Head
**

Joined: 6 Oct, 2009
Posts: 63



Thanked: 5 times
My Contributions
This is a VB6 forum. Anyways, try this:

Dim phoneNum As String
Dim modifiedPhoneNum As String
Dim i As Integer, LenOfPhoneNum As Integer
Dim c As String
phoneNum = "12-234 34,2234"
LenOfPhoneNum = Len(phoneNum)
modifiedPhoneNum = ""
For i = 1 To LenOfPhoneNum
c = Mid(phoneNum, i, 1)
If IsNumeric© Then
modifiedPhoneNum = modifiedPhoneNum & c
End If
Next i
MsgBox modifiedPhoneNum
User is offlineProfile CardPM
+Quote Post

thava

RE: Phone Number

8 Nov, 2009 - 04:24 PM
Post #3

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 905



Thanked: 52 times
Dream Kudos: 75
My Contributions
the thing your are done wrong are

1) this is a not a vb.net forum
2) there is some logic miss there
CODE

        numberLabel.Text = PhoneNumberTextBox.Text

instead of this
CODE

        numberLabel.Text = PhoneNumber


next time when you post please post it in correct forum

happy coding icon_up.gif

User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Phone Number

8 Nov, 2009 - 04:35 PM
Post #4

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,919



Thanked: 517 times
Dream Kudos: 11525
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Moved to VB.NET smile.gif
User is offlineProfile CardPM
+Quote Post

CharlieMay

RE: Phone Number

8 Nov, 2009 - 05:15 PM
Post #5

D.I.C Head
Group Icon

Joined: 25 Sep, 2009
Posts: 239



Thanked: 43 times
Dream Kudos: 25
My Contributions
NumberLabel.Text should equal PhoneNumber since that is the variable for the string you are building from the Replace method.

This is assuming that the phonenumber is displayed in the NumberLabel.text

I see you are setting NumberLabel.Text = String.Empty in the textchange event of the numberTextBox. I'm not sure of your form layout but if the above change doesn't work, I would remove that line and then re-check the code.

This post has been edited by CharlieMay: 8 Nov, 2009 - 05:18 PM
User is offlineProfile CardPM
+Quote Post

motcom

RE: Phone Number

9 Nov, 2009 - 05:36 AM
Post #6

D.I.C Addict
Group Icon

Joined: 16 Jun, 2008
Posts: 548



Thanked: 94 times
Dream Kudos: 175
My Contributions
Hi,

Use this to replace

CODE

'for hyphen
txtPhoneNumber.Text = txtPhoneNumber.Text.Replace("-","")

'for comma
txtPhoneNumber.Text = txtPhoneNumber.Text.Replace(",","")

'for space
txtPhoneNumber.Text = txtPhoneNumber.Text.Replace(" ","")


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 08:11AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month