Hi everybody!
I'm wondering if I can make this code snippet better, and in that case HOW?
Thx very much!Code:' My task: 'Write a program that receives a six-digit date for example 071019 'The program is suppose to find out if the date is correct. 'Rules '• April, June, September, November all have 30 days. '• february has 28 days if the year is not a leap year: then the month has 29 days '• all other months have 31 days '• if the year is a leap year then the two last digits in the year are even: dividable with 4. Dim d, m, y As String Dim dedate As Boolean If TextBox9.Text.Length > 0 And TextBox9.Text.Length = 6 Then y = TextBox9.Text.Substring(0, 2) m = TextBox9.Text.Substring(2, 2) d = TextBox9.Text.Substring(4, 2) 'leap year? y /= 4 If y = 0 Or y = 0.5 Or y = 1 Or y = 1.5 Or y = 2 Then y = True Else : y = False End If 'y = false => not leap year; y = true => leap year 'are months between 1 and 12? If m > 0 And m < 13 Then 'if month = apr, jun, sep or nov or d > 0 and d < 31 If (m = 4 Or m = 6 Or m = 9 Or m = 11) And d > 0 And d < 31 Then 'max days of teh month = 30 dedate = True ElseIf m = 2 And d > 0 Then 'Only februari If y = False And Not d > 28 Then 'february not leap year and days ok dedate = True ElseIf y = True And d < 30 Then 'february and leap year dedeate = True ElseIf (y = False And d > 28) Or d > 29 Then dedate = False End If ElseIf m = 1 Or m = 3 Or m = 5 Or m = 6 Or m = 7 Or m = 8 Or m = 10 Or m = 12 And d > 0 And d < 32 Then dedate= True Else dedate= False End If 'MsgBox("Your date: " & datum & vbNewLine & "Year: " & y & vbNewLine & "Month: " & m & vbNewLine & "Day: " & d, , "Result") Else dedate= False End If Else dedate= False End If Label26.Text = "The daet is " & dedate.ToString.ToLower & "."
//wally_91




Reply With Quote