Testing for a null value

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Can you show me some sample coding that will allow me to test for a null value?

Thanks.
 

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Thanks for the coding to test for nulls.

I came across nulls while developing in this scenario using a database table of 5 columns:

1. Get the app working fully.
2. Add some new columns in the table.
3. Run the app and there will be errors because the new columns have null values while the rest of them don't.

This is the code that I will need to add testing for nulls:
B4X:
Sub ListViewPeopleEventHandler_ItemClick (PositionInListClicked As Int, ValuesInListClicked As Object)

   ' Update the details area.
   '-------------------------
   Dim valuesFromTheListView() As String
   Dim oRecordSet As Cursor

   valuesFromTheListView = ValuesInListClicked   
   
   ' This value is the primary key to the database table and is hidden from the user.
   '---------------------------------------------------------------------------------
   intCurrentId = valuesFromTheListView(0)

     oRecordSet = SQL.ExecQuery( _
        "SELECT Id, FirstName, LastName, Address1, Address2, City, State, Zip, DateOfLastVisit " & _
          "FROM PeopleToVisit " & _
         "WHERE id = " & intCurrentId)

   If oRecordSet.RowCount > 0 Then
      oRecordSet.Position = 0

      EditTextFirstName.Text = oRecordSet.GetString("FirstName")
      EditTextLastName.Text = oRecordSet.GetString("LastName")
      EditTextAddress1.Text = oRecordSet.GetString("Address1")
      EditTextAddress2.Text = oRecordSet.GetString("Address2")
      EditTextCity.Text = oRecordSet.GetString("City")
      EditTextState.Text = oRecordSet.GetString("State")
      EditTextZip.Text = oRecordSet.GetString("Zip")
      EditTextDateOfLastVisit.Text = oRecordSet.GetString("DateOfLastVisit")
   End If
      
   EditTextFirstName.RequestFocus
   EditTextFirstName.SelectAll
   EditTextFirstName.Color = Colors.Cyan
   EditTextFirstName.RequestFocus

   EditTextLastName.Color = Colors.Cyan
   EditTextAddress1.Color = Colors.Cyan
   EditTextAddress2.Color = Colors.Cyan
   EditTextCity.Color = Colors.Cyan
   EditTextState.Color = Colors.Cyan
   EditTextZip.Color = Colors.Cyan
   EditTextDateOfLastVisit.Color = Colors.Cyan

   tableMode = "Edit"
   Activity.Title = "Maintenance - People To Visit *** EDIT ***"
   ButtonDelete.Enabled = True
End Sub
 
Last edited:
Upvote 0

bees

Member
Licensed User
Longtime User
Hi Erel,

Thanks for the coding to test for nulls.

I came across nulls while developing in this scenario using a database table of 5 columns:

1. Get the app working fully.
2. Add some new columns in the table.
3. Run the app and there will be errors because the new columns have null values while the rest of them don't.




Design your database so it won't accept NULL Values and set the default value to an empty string
CREATE TABLE [MyTable] (
[Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT (0),
[FirstName] CHAR(40) NOT NULL DEFAULT (''),
[LastName] CHAR(40) NOT NULL DEFAULT (''),
[Adress1] CHAR(40) NOT NULL DEFAULT ('')
[Adress2] CHAR(40) NOT NULL DEFAULT (''));

Or use the 'AS' Clause in your query
http://www.b4x.com/forum/basic4andr...te-values-query-into-multiple-text-boxes.html


HTH,

Stephen
 
Upvote 0
Top