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

Multi Point USB Charger

  USB Plug Charger, 4-Port USB Fast Charger Plug with 33W Intelligent Quick Charge 3.0 Wall Charger, Multi USBPower Adapter UK Fast Charging...