Android Question How to exit sub in code and countinue

Makumbi

Well-Known Member
Licensed User
Good afternoon how can i modify this code to exit sub if the person is already registered or go to the registration code if that person is not registered thanks in advance

B4X:
If CCode.Text = "" Or Phone.Text = "" Or Emails.Text = "" Then
    Msgbox("You have to enter all fields","Missed data field")
    Else
        cursor1 = SQL1.ExecQuery("SELECT * FROM Register where Phone = '" & Phone.Text & "' ")
        For i = 0 To cursor1.RowCount - 1
            'cursor1.Position = i
            Msgbox("You are Already Registered","SMIS")
            Next
        Return
        'Else
        'If CCode.Text = "256" Then
        DBloadnew
        End If
End Sub
Sub DBloadnew
cursor1 = SQL1.ExecQuery("SELECT ID FROM Register")
If cursor1.RowCount > 0 Then
    For i = 0 To cursor1.RowCount - 1
        cursor1.Position = i
        Dim NewID As Int
        NewID = cursor1.GetInt("ID")
    Next
End If
NewID = NewID +1 '
SQL1.ExecNonQuery("INSERT INTO Register VALUES('" & CCode.Text & "','" & Phone.Text & "','" & Emails.Text & "','" & NewID & "')")
'SQL1.ExecNonQuery("INSERT INTO Register VALUES('" & CCode.Text & "','" & Phone.Text & "','" & Emails.Text & "')")
Msgbox("Registration Completed Successfully","SMIS")
'End If
 

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Hello

you should ask if the rowcount of the cursor returns any value to you.

I leave this code.

B4X:
If CCode.Text = "" Or Phone.Text = "" Or Emails.Text = "" Then
    Msgbox("You have to enter all fields","Missed data field")
    Else
        cursor1 = SQL1.ExecQuery("SELECT * FROM Register where Phone = '" & Phone.Text & "' ")
        If cursor1.RowCount<>0 then
            'user registered
             For i = 0 To cursor1.RowCount - 1
                  'cursor1.Position = i
                   Msgbox("You are Already Registered","SMIS")
            Next
        Else
           'user not registered  
            DBloadnew
     End If
End Sub
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Hello

you should ask if the rowcount of the cursor returns any value to you.

I leave this code.

B4X:
If CCode.Text = "" Or Phone.Text = "" Or Emails.Text = "" Then
    Msgbox("You have to enter all fields","Missed data field")
    Else
        cursor1 = SQL1.ExecQuery("SELECT * FROM Register where Phone = '" & Phone.Text & "' ")
        If cursor1.RowCount<>0 then
            'user registered
             For i = 0 To cursor1.RowCount - 1
                  'cursor1.Position = i
                   Msgbox("You are Already Registered","SMIS")
            Next
        Else
           'user not registered 
            DBloadnew
     End If
End Sub
Thanks man it has worked
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Make sure to close the Cursor when it is no longer needed.
2. Better to use ResultSet instead of Cursor.
3. Better to use MsgboxAsync instead of Msgbox.
4. You should never write queries such as this:
B4X:
SQL1.ExecQuery("SELECT * FROM Register where Phone = '" & Phone.Text & "' ")
Instead:
B4X:
SQL1.ExecQuery2("SELECT * FROM Register where Phone = ?", Array As String(Phone.Text))
 
Upvote 0
Top