Sub returning a Boolean value

isuru

Member
Licensed User
Longtime User
In this app I'm creating, I've written a Sub to validate user input on a EditText.

B4X:
Sub btnSearch_Click
   Dim selection, search_string As String
   
   selection = spnrSearchBy.SelectedItem.Trim
   search_string = txtSearch.Text.Trim

   If selection = "Area" OR selection = "Service Name" OR selection = "Hotline" Then
      NormalInputVerify
   Else If selection = "Cost" Then
      CostInputVerify
   End If
End Sub   'End of the btnSearch_Click Sub

Sub NormalInputVerify As Boolean
   If txtSearch.Text.Trim.Length = 0 Then
      ToastMessageShow("Please enter a search string", False)
      Return False
   Else If txtSearch.Text.Trim.Length < 3 Then
      ToastMessageShow("Search string must be at least 3 characters long", False)
      Return False
   End If
End Sub

The problem is even if the conditions in the NormalInputVerify Sub are met or not, after executing the Sub, it returns to the End of the btnSearch_Click Sub.

Can anyone tell me how to correct this?

Thank you :)
 

margret

Well-Known Member
Licensed User
Longtime User
Something like this:

B4X:
Sub btnSearch_Click
   Dim selection, search_string As String
   
   selection = spnrSearchBy.SelectedItem.Trim
   search_string = txtSearch.Text.Trim

   If selection = "Area" OR selection = "Service Name" OR selection = "Hotline" Then
      If NormalInputVerify = False Then
           txtSearch.RequestFocus
           Return
        End If
   Else If selection = "Cost" Then
      CostInputVerify
   End If

End Sub   'End of the btnSearch_Click Sub

Sub NormalInputVerify As Boolean
   If txtSearch.Text.Trim.Length = 0 Then
      ToastMessageShow("Please enter a search string", False)
      Return False
   Else If txtSearch.Text.Trim.Length < 3 Then
      ToastMessageShow("Search string must be at least 3 characters long", False)
      Return False
   End If
    Return True
End Sub
 
Upvote 0
Top