Error handling with Null values

Hi,

I experience difficulties with null values in my WebPopUpMenus. Some of them are populated after a WebListBox.Cell(Row) “action” and might be empty in some circumstances. In those situations, I get OutOfBoudsExceptions when I want to save my controls content to the database.
Here is a code sample:

Dim row As New DatabaseRecord row.Column("nom_tache") = TachesPage.DGTContainerModify.NomField.Text row.Column("desc_tache") = TachesPage.DGTContainerModify.DescTextArea.Text row.Column("statut_tache") = TachesPage.DGTContainerModify.StatutPopupMenu.RowTag(TachesPage.DGTContainer.StatutPopupMenu.ListIndex row.Column("lien_projet") = TachesPage.TachesIdProjet row.Column("type_tache") = TachesPage.DGTContainerModify.TypePopupMenu.RowTag(TachesPage.DGTContainer.TypePopupMenu.ListIndex row.Column("responsable") = TachesPage.DGTContainerModify.RespPopupMenu.RowTag(TachesPage.DGTContainer.RespPopupMenu.ListIndex Session.DB.InsertRecord("taches", row)

The OutOfBoudsExceptions are caused by the RowTag’s indexes.

In Microsoft Access, I used to use the nz “function” that could replace null values by an empty string or ‘0’ when it was dealing with null values.

Function nz(i As Variant, j As Variant) As Variant
  If IsNull(i) Then
    Return  j
  Else
    Return i
  End if
End Function

It doesn’t work in the present case because whichever value I use for “j” as a replacement still triggers an OutOfBoudsException.

What would be the simplest way to deal with that?

I know I could go with “If x <> Nil Then…” but I’m wondering if there could be a more “elegant” and efficient way to do things…

Thanks!

Roger

Check the listcount of the popup before you try to access it.

if TachesPage.DGTContainer.TypePopupMenu.ListIndex <= TachesPage.DGTContainerModify.RespPopupMenu.ListCount then
   row.Column("statut_tache") = TachesPage.DGTContainerModify.StatutPopupMenu.RowTag(TachesPage.DGTContainer.StatutPopupMenu.ListIndex
else
   row.Column("statut_tache") = ""
end if

Thanks Tim,

So I guess I’ll have to verify every list I use individually… :frowning: