Monday, 11 May 2015

Truncate a field in VB Before Entry

 

If you do a lot of importing of files and do not have control over what the user puts in i.e. long names passed the field width of the DB or Textbox, This could be imports from a CSV or spreadsheet then try validating the field length.
         The following VB Function takes the string and the field length truncates the string and returns it.

 Private Function truncate(mystring As String, mylength As Int16)


        If mystring.Length >= mylength - 1 Then
            mystring = mystring.Substring(0, mylength - 1)
        End If

        Return mystring
    End Function

No comments:

Post a Comment

Samsung Android Keyboard

  If you have a Samsung phone or pad and the keyboard is set to Google give the Samsung one a try. Just go into the keyboard settings and ...