Solved

have users type just number into rich text box

Posted on 2014-12-23
3
68 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now