Solved

have users type just number into rich text box

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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