none
Adjust check with Tag if they are empty RRS feed

  • Question

  • Hello,

    On this Question , i found the answer from IronRazorz that i am using .

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/a8b7ace3-e312-4e13-a86e-a2b832c03c7f/check-if-textboxes-are-empty-then?forum=vbgeneral#6d96164e-b1e3-4286-9479-1ee2cbac607e

    Now for another project i want to adjust this a little bit for Datetimepicker with a Customformat  (" ") at start form so it is not showing date only (" ").

    This is the original code

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim sb As New System.Text.StringBuilder
    
            Dim ctrl As Control = Me.GetNextControl(Me, True)
            While ctrl IsNot Nothing
                If (TypeOf ctrl Is TextBox OrElse TypeOf ctrl Is ComboBox) AndAlso ctrl.Tag IsNot Nothing AndAlso ctrl.Tag.ToString = "CheckMe" AndAlso String.IsNullOrEmpty(ctrl.Text) Then
                    sb.AppendLine(ctrl.Name & " is empty")
                End If
                ctrl = Me.GetNextControl(ctrl, True)
            End While
    
            If Not String.IsNullOrEmpty(sb.ToString) Then MessageBox.Show(sb.ToString, "Empty...")
        End Sub

    I try to put also Datetimepicker into it , i think it is oke because there is no error ?

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim sb As New System.Text.StringBuilder
    
            Dim ctrl As Control = Me.GetNextControl(Me, True)
            While ctrl IsNot Nothing
                  If (TypeOf ctrl Is TextBox OrElse TypeOf ctrl Is ComboBox OrElse TypeOf ctrl Is DateTimePicker) AndAlso ctrl.Tag IsNot Nothing AndAlso ctrl.Tag.ToString = "CheckMe" AndAlso String.IsNullOrEmpty(ctrl.Text) Then
                    sb.AppendLine(ctrl.Name & " is niet ingevuld !")
                End If
                ctrl = Me.GetNextControl(ctrl, True)
            End While
    
            If Not String.IsNullOrEmpty(sb.ToString) Then MessageBox.Show(sb.ToString, "Empty...")
        End Sub
    But what do i ad that it is also searching for (" ") ?

    Monday, August 20, 2018 9:25 AM

All replies

  • Using framework 3.5 so this is not working

    string.IsNullOrWhiteSpace was added to .net framework 4.0 and up

    Monday, August 20, 2018 9:42 AM
  • Using framework 3.5 so this is not working

    string.IsNullOrWhiteSpace was added to .net framework 4.0 and up

    Hi,

    The specific implementation code of the IsNullOrWhiteSpace() is:

    Public Shared Function IsNullOrWhiteSpace(ByVal value As String) As Boolean
        If value IsNot Nothing Then
    
            For i As Integer = 0 To value.Length - 1
    
                If Not Char.IsWhiteSpace(value(i)) Then
                    returnfalse
                End If
            Next
        End If
    
        return true
    End Function

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Monday, August 20, 2018 9:58 AM
  • Hello Alex,

    When  i put the function in there is a error on this line

      returnfalse
    Error	BC30451	'returnfalse' is not declared. It may be inaccessible due to its protection level.

    Monday, August 20, 2018 5:51 PM
  •  Try making the following changes...

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim sb As New System.Text.StringBuilder
    
            Dim ctrl As Control = Me.GetNextControl(Me, True)
            While ctrl IsNot Nothing
                If (TypeOf ctrl Is TextBox OrElse TypeOf ctrl Is ComboBox OrElse TypeOf ctrl Is DateTimePicker) AndAlso ctrl.Tag IsNot Nothing AndAlso ctrl.Tag.ToString = "CheckMe" AndAlso ctrl.Text.Trim = "" Then
                    sb.AppendLine(ctrl.Name & " is niet ingevuld !")
                End If
                ctrl = Me.GetNextControl(ctrl, True)
            End While
    
            If sb.ToString.Trim <> "" Then MessageBox.Show(sb.ToString, "Empty...")
        End Sub
    


    If you say it can`t be done then i`ll try it

    Monday, August 20, 2018 9:19 PM
  • Hello Alex,

    When  i put the function in there is a error on this line

      returnfalse
    Error	BC30451	'returnfalse' is not declared. It may be inaccessible due to its protection level.

    Hi,

    Sorry, it should be

    return false

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 21, 2018 1:00 AM