Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

have users type just number into rich text box

Posted on 2014-12-23
3
Medium Priority
?
77 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

604 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