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

Chrome 138 the last supported

Chrome 138 the last supported  Hey Everyone, Chrome 138 is the last version of Chrome that will support Android 8.0 (Oreo) and Android 9.0 (...