Solved

have users type just number into rich text box

Posted on 2014-12-23
3
72 Views
Last Modified: 2014-12-23
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

currently using in rich text box how i would like the user to input into the rich text box
0
Comment
Question by:cmed
  • 2
3 Comments
 
LVL 9

Expert Comment

by:dustock
ID: 40514971
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

0
 

Author Comment

by:cmed
ID: 40515006
@ dustock

How would i set the function inside my button?
0
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 40515047
Put the function inside of your code, just make sure its not inside of any other sub you have already created.  Then create a string and make it equal to the call of the function.

'Inside the button click event add this code
Dim strToken As String
strToken = replaceChars(RichTextBox1.Text)
'Call your update  with strToken as your argument

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question