Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Module ApplicationValidation
- Sub Main()
- ' Input from user
- Console.Write("Enter city of birth: ")
- Dim cityOfBirth As String = Console.ReadLine()
- Console.Write("Enter city where birth certificate was issued: ")
- Dim certificateCity As String = Console.ReadLine()
- Console.Write("Enter CNAM paper issue date (yyyy-mm-dd): ")
- Dim issueDateInput As String = Console.ReadLine()
- Dim cnamPaperIssueDate As DateTime
- ' Validate the entered date
- If DateTime.TryParse(issueDateInput, cnamPaperIssueDate) Then
- ' Call validation method
- ValidateApplication(cityOfBirth, certificateCity, cnamPaperIssueDate)
- Else
- Console.WriteLine("Invalid date format. Please use yyyy-mm-dd.")
- End If
- End Sub
- Function ValidateBirthCertificate(cityOfBirth As String, certificateCity As String) As Boolean
- If cityOfBirth.ToLower() <> certificateCity.ToLower() Then
- Console.WriteLine("Application refused because Birth certificate must be issued in the city of birth.")
- Return False
- End If
- Return True
- End Function
- Function ValidateCnamPaper(issueDate As DateTime) As Boolean
- Dim sixMonthsAgo As DateTime = DateTime.Now.AddMonths(-6)
- If issueDate < sixMonthsAgo Then
- Console.WriteLine("Application refused because CNAM paper must be issued within the last six months.")
- Return False
- End If
- Return True
- End Function
- Sub ValidateApplication(cityOfBirth As String, certificateCity As String, issueDate As DateTime)
- ' Using AndAlso to ensure short-circuiting
- If ValidateBirthCertificate(cityOfBirth, certificateCity) AndAlso ValidateCnamPaper(issueDate) Then
- Console.WriteLine("Application is valid.")
- Else
- Console.WriteLine("Application is not valid.")
- End If
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment