Validating and Clearing Forms

ashmoloy

New Member
Hello, im new to Basic4ppc and have two questions.

1. Is there a way to clear all my form fields at one go?

2. Can i check/validate if any of the form fields(text) is left empty at one go?

the code snippet would help :)

Thx,
Bakshi
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Globals
    Dim controls(0)
    
End Sub

Sub App_Start
    Form1.Show
    Msgbox(IsEmpty)
    ClearAllTextboxes
    Msgbox(IsEmpty)
End Sub

Sub ClearAllTextboxes
    controls() = GetControls("form1")
    For i = 0 To ArrayLen(controls()) - 1
        If ControlType(controls(i)) = "TextBox" Then 'note that the control type is case sensitive.
            Control(controls(i), Textbox).Text = ""
        End If
    Next
End Sub

Sub IsEmpty
    controls() = GetControls("form1")
    For i = 0 To ArrayLen(controls()) - 1
        If ControlType(controls(i)) = "TextBox" Then
            If Control(controls(i), Textbox).Text <> "" Then Return False
        End If
    Next
    Return True
End Sub
 
Top