Advertisement
bluebunny72

IsStringValid

Jan 4th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Public Function StdFormSave() As Integer
  2.         Dim returnValue As Integer = 0
  3.  
  4.         Dim startRow As Integer
  5.         Dim endRow As Integer
  6.  
  7.         startRow = 0
  8.         endRow = ThisForm.PrimaryIDOCollection.GetNumEntries - 1
  9.  
  10.         For i As Integer = startRow To endRow
  11.  
  12.             'NOTE:  a new row will return TRUE for both IsObjectNew and IsObjectModified
  13.            If (ThisForm.PrimaryIDOCollection.IsObjectModified(i) = True) Then
  14.                 Dim item As String = ThisForm.PrimaryIDOCollection.GetObjectProperty("Item", i)
  15.  
  16.                 If (IsStringValid(item, False) = False) Then
  17.                     Application.ShowMessage(String.Format("Item {0} has spaces or special characters.", item))
  18.                     returnValue = -1
  19.                     Exit For
  20.                 End If
  21.             End If
  22.         Next
  23.  
  24.         Return returnValue
  25.     End Function
  26.  
  27.     Private Function IsStringValid(s As String, allowSpaces As Boolean) As Boolean
  28.         Dim isValid As Boolean = True
  29.  
  30.         Dim lowerRange As Integer = 32
  31.  
  32.         ' set lower range for the function check
  33.        If allowSpaces = False Then
  34.             lowerRange = 33
  35.         End If
  36.  
  37.         For Each c As Char In s
  38.             ' do not allow pipe |
  39.            If (AscW(c) < lowerRange OrElse AscW(c) > 126 OrElse AscW(c) = 124) Then
  40.                 isValid = False
  41.                 Exit For
  42.             End If
  43.         Next
  44.         Return isValid
  45.     End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement