2010-01-12 8 views
1

ceci est mon code -vb état null .net

  Dim provider As CultureInfo = CultureInfo.InvariantCulture 
      Dim a1 As DateTime = Nothing 
      insexp = DateTime.ParseExact(date1.SelectedValue, "MMMM yyyy", provider) 
      If a1.Month = Today.Month AndAlso a1.Year = Today.Year Then 
       a1 = Today.Date 
      End If 

cela ne fonctionnera que si date1.selectedvalue est non nul, mais se bloque si elle est nulle. comment puis-je donner si la condition pour exécuter ceci seulement si non null? grâce

Répondre

5
If date1.SelectedValue IsNot Nothing Then 
    ... 
End If 
1
Dim provider As CultureInfo = CultureInfo.InvariantCulture 
     Dim a1 As DateTime = Nothing 
     If not String.IsNullOrEmpty(date1.SelectedValue) Then   
    insexp = DateTime.ParseExact(date1.SelectedValue, "MMMM yyyy", provider) 
     End If 
    If a1.Month = Today.Month AndAlso a1.Year = Today.Year Then 
     a1 = Today.Date 
    End If