Link to home
Start Free TrialLog in
Avatar of cmed
cmed

asked on

have users type just number into rich text box

Currently, I am trying to enhance this code to have users types numbers into rich text box to do an update.  I would like to have the user just type in the numbers without commas and create a code to add the commas before performing the update.  Have been searching to no avail. I will continue to research, but any suggestions?



Public Class Form1

    'DATABASE CONNECTION'
    Private Const connectionString As String = "Data Source=mddbsqlpfqa.loe.corp; Database=PowerFaids; " _
& "Trusted_Connection=Yes;"

    'Clear Rich Text Box Values'

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        rtbdisplay.Clear()
    End Sub

    'FUNCTION FOR PERFORM UPDATE'

    Private Sub CreateUpdate(ByVal rtf As String)

        Using cnn As New SqlConnection(connectionString)
            cnn.Open()

            'Run SQL'
            Using mysda As New SqlDataAdapter()

                Using mycmd As New SqlCommand(My.Resources.update_ud, cnn)

                    mycmd.CommandTimeout = 0
                    mysda.SelectCommand = mycmd
                    mycmd.Parameters.AddWithValue("@ROSTER_TOKEN", rtf)
                    mysda.SelectCommand = mycmd

                    Dim RowsEffected As Integer = mycmd.ExecuteNonQuery()
                    MsgBox(RowsEffected.ToString & " " & "rows have been updated", MsgBoxStyle.Information, "Update User Date")

                End Using
            End Using
        End Using
    End Sub

    'UPDATE UD'

    Dim tempInt As String

    Private Sub btnUpdateUd_Click(sender As Object, e As EventArgs) Handles btnUpdateUserDate.Click

        Dim RT As Integer = 0
        Dim rtSplit() As String = rtbdisplay.Text.Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)
        For Each item In rtSplit
            If Integer.TryParse(item, tempInt) Then
                If MsgBox("Roster Token" & " " & item & " " & "has been selected!" & vbCrLf & vbCrLf & "DO YOU WANT TO PROCEED?", MsgBoxStyle.YesNo, "Update User Date") = DialogResult.No Then
                    rtbdisplay.Clear()
                    rtbdisplay.ResetText()
                Else
                    CreateUpdate(tempInt)
                End If
            End If
        Next
    End Sub

    'EXIT APPLICATION'
    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Dim x As Integer = MsgBox("Are you sure you want to quit?", MsgBoxStyle.YesNo, "Quit")
        If x = DialogResult.Yes Then
            Me.Close()
        End If
    End Sub

End Class

Open in new window

User generated image User generated image
Avatar of dustock
dustock
Flag of United States of America image

Try this function I wrote that will replace a space with a comma and also a newline with a comma to give you 1 string.

    Public Function replaceChars(strText As String)
        Dim result As String

        result = strText

        If result.Contains(ControlChars.Lf) Then
            result = result.Replace(ControlChars.Lf, ",")
        End If

        If RichTextBox1.Text.Contains(" ") Then
            result = result.Replace(" ", ",")
        End If

        Return result
    End Function

Open in new window

Avatar of cmed
cmed

ASKER

@ dustock

How would i set the function inside my button?
ASKER CERTIFIED SOLUTION
Avatar of dustock
dustock
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial