mario.deghetto

Visual Basic & .NET
posts - 332, comments - 79, trackbacks - 0

#5: [VB.NET] Verifica se anno bisestile

Spesso è necessario conoscere se un anno sia bisestile. Nel tempo si sono trovate molte soluzioni diverse a questo problema.

Con VB.NET il problema è stato risolto alla fonte: è fornito un opportuno metodo, IsLeapYear, che accetta in input un valore intero (l’anno) e restituisce un valore booleano (True = bisestile, False = non bisestile).

Per provare questa funzione, creare una form, aggiungere due TextBox di nome rispettivamente TextBox1 e TextBox2 ed un pulsante e infine, nell’evento Click del pulsante inserire il seguente codice:

If TextBox1.Text = "" Then
  TextBox2.Text = "anno non indicato"
Else
  If (DateTime.IsLeapYear(Integer.Parse(TextBox1.Text)) = True) _
        Then
     TextBox2.Text = "L'anno " & TextBox1.Text & " è bisestile."
  Else
     TextBox2.Text = "L'anno " & TextBox1.Text & " NON è bisestile."
  End If
End If

Print | posted on domenica 11 ottobre 2009 6.00 |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 3 and type the answer here:

Powered by: