Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,558 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,921 people online right now. Registration is fast and FREE... Join Now!




Using the Remove method of String

 
Reply to this topicStart new topic

Using the Remove method of String, I need some help. The question nine on page 662

marpar
12 Apr, 2008 - 10:17 AM
Post #1

New D.I.C Head
*

Joined: 12 Apr, 2008
Posts: 1

This question asks me to code the remove dashes button so that it first verifies that the social security number contains exactly 11 characters. It then should remove the dashes from the social security number for displaying the number in the xNumberLabel. Use the remove method to remove the dashes. This is my code but it doesn't work for me:
CODE

' Project name:     Social Security Project
' Project purpose:  The project removes the dashes
'                   from a social security number.
' Created/revised:  <Mark Parsons> on <April 11, 2008>

Option Explicit On
Option Strict On

Public Class MainForm

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

    Private Sub xNumberTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumTextBox.Enter
        Me.xNumTextBox.SelectAll()
    End Sub

    Private Sub xRemoveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xRemoveButton.Click
        ' removes the dashes from a social security number
        Dim SSNum As String
        Dim NewSSNum As String
        SSNum = Me.xNumTextBox.Text
        Do Until SSNum.Length = 11
            SSNum = Me.xNumTextBox.Text
        Loop
        NewSSNum = SSNum.Trim("-"c)
        NewSSNum = Me.xNumLabel.Text

        Me.xNumTextBox.Focus()
    End Sub
End Class


Can anyone help? Please
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Using The Remove Method Of String
12 Apr, 2008 - 03:16 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



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

My Contributions
Moved to VB.Net (Will look through your code after work)
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Using The Remove Method Of String
13 Apr, 2008 - 10:53 AM
Post #3

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,947



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Renamed topic title to be more descriptive.

The quick and easy way using the Remove method would look something like this.
CODE

Private Sub xRemoveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xRemoveButton.Click
        If Me.xNumTextBox.Text.Length = 11 Then
            Dim ssn As String = Me.xNumTextBox.Text

            ssn = ssn.Remove(ssn.IndexOf("-"), 1)
            ssn = ssn.Remove(ssn.IndexOf("-"), 1)

            Me.xNumLabel.Text = ssn
        Else
            MessageBox.Show("SSN must be 11 characters including dashes")
        End If
End Sub

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:29PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month