l'ho risolto così, anche se non sò se sia veramente efficente:
codice:
Try
If MaskedTextBox1.Text.Substring(3, 2) = MaskedTextBox2.Text.Substring(3, 2) Then
For i As Long = MaskedTextBox1.Text.Substring(0, 2) To MaskedTextBox2.Text.Substring(0, 2)
Dim d = i.ToString("00") & "/" & MaskedTextBox1.Text.Substring(3, 2) & "/" & MaskedTextBox1.Text.Substring(6, 4)
If Convert.ToDateTime(d).DayOfWeek <> DayOfWeek.Sunday Then
ListBox1.Items.Add(d)
End If
Next
TextBox1.Text = ListBox1.Items.Count
Else
For z As Long = MaskedTextBox1.Text.Substring(0, 2) To Date.DaysInMonth(MaskedTextBox1.Text.Substring(6, 4), MaskedTextBox1.Text.Substring(3, 2))
Dim da = z.ToString("00") & "/" & MaskedTextBox1.Text.Substring(3, 2) & "/" & MaskedTextBox1.Text.Substring(6, 4)
If Convert.ToDateTime(da).DayOfWeek <> DayOfWeek.Sunday Then
ListBox1.Items.Add(da)
End If
Next
For n As Long = 1 To MaskedTextBox2.Text.Substring(0, 2) 'To TextBox1.Text
Dim dd = n.ToString("00") & "/" & MaskedTextBox2.Text.Substring(3, 2) & "/" & MaskedTextBox2.Text.Substring(6, 4)
If Convert.ToDateTime(dd).DayOfWeek <> DayOfWeek.Sunday Then
ListBox1.Items.Add(dd)
End If
Next
TextBox1.Text = ListBox1.Items.Count
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
0